node.js - lodash中的流函数问题
问题描述
我开始在一个新项目中工作,在那里我找到了 lodash 的函数,我在文档flow
中看到了它的用途,但是在我的项目中,在下面的代码中,我在这里找到了函数末尾的内容是什么?flow([...])(state)
(state)
module.exports = (async function published(state) {
return flow([
setColumnIndex('my_pay_table', 1, 'rate_mode', getColumn('pay_structure', 'pay_per_id', state)),
setColumnIndex('my_pay_table', 1, 'rate_amount', getColumn('pay_structure', 'pay_rate', state)),
setColumnIndex('my_wo_title_table', 1, 'user_id', buildArtifact(ownerAlias, 'user', 'id', 1)),
setColumnIndex('my_wo_title_table', 1, 'date_added', Date.now() / 1000),
])(state);
});
谁能帮我?
解决方案
根据 lodash 文档,flow
返回一个函数。在 JavaScript 中,可以在不执行函数的情况下返回函数。
我们可以将您提供的代码重构为以下内容
module.exports = (async function published(state) {
// `func` here is a function
const func = flow([
setColumnIndex('my_pay_table', 1, 'rate_mode', getColumn('pay_structure', 'pay_per_id', state)),
setColumnIndex('my_pay_table', 1, 'rate_amount', getColumn('pay_structure', 'pay_rate', state)),
setColumnIndex('my_wo_title_table', 1, 'user_id', buildArtifact(ownerAlias, 'user', 'id', 1)),
setColumnIndex('my_wo_title_table', 1, 'date_added', Date.now() / 1000),
]);
// Here we execute that function with an argument `state`
return func(state);
});
推荐阅读
- java - why i can make few file object in for loop at java
- clang-format - clang-format 似乎忽略了 CommentPragmas
- vba - Application.ontime follow the wrong speed
- visual-studio - 在正在运行的 Visual Studio 实例中打开文件
- google-photos - Google Photos API - 为什么有些查询是 POST 而有些是 GET?
- css - Wordpress - Image containers too large
- go - 如何使用带有用户令牌 E2E 的 CF 客户端
- c# - 如何制作面向对象的登录程序?
- java - Read each key press only once with JNativeHook
- php - 如果 Schedulertask 由 cronjob 执行,则 getParentKeyFieldName() on null