javascript - __ 应该只适用于咖喱函数吗?为什么它在这里工作?
问题描述
我试图理解为什么__
在这段代码中可以正常工作:
function editAddress (id, addressId, model) {
return BusinessService
.getById(id)
.then(unless(
() => checkUrlValue(addressId, model.id),
rejectWithError(InvalidData.error('Invalid address data: Address id is different from request'))
))
.then(pipe(
updateModel(__, 'addresses', model, 'id', addressId),
juxt([ always(id), identity ]),
apply(BusinessService.editById)
))
.then(pipe(
prop('addresses'),
find(propEq('id', addressId))
))
}
function updateModel (entity, property, model, attr, id) {
return evolve({
[property]: pipe(
juxt([
findIndex(propEq(attr, id)),
pipe(
find(propEq(attr, id)),
mergeLeft(model)
),
identity
]),
apply(update)
)
})(entity)
}
既然调用的函数( updateModel )没有被柯里化,为什么__
在这种情况下仍然有效?
解决方案
updateModel
不是柯里化的,而是返回一个evolve
被柯里化的函数的结果。第一个调用传入:
{
[property]: pipe(
juxt([
findIndex(propEq(attr, id)),
pipe(
find(propEq(attr, id)),
mergeLeft(model)
),
identity
]),
apply(update)
)
}
然后用 调用此调用的结果entity
,在您的情况下为 __。如果不看其内部,evolve
就不可能进一步理解代码。
推荐阅读
- flutter - 如何访问嵌套集合结构中最里面的文档?
- mysql - Maria DB - 防止删除 where 子句中的尾随空格
- snmp - 无法访问“http://mibs.snmplabs.com/asn1/”,任何编译专有 mib 的替代方法
- java - 如何使用 POI 读取 xlsx 文件?
- html - srcset hiDPI 图像的 Pagespeed 洞察惩罚
- javascript - 在反应中向父组件添加单选按钮值
- r - Smooth change of day length
- angularjs - 在 Angular 8 应用程序中使用 Angular JS 组件时无法解决“角度”错误
- tensorflow - 这个警告信息是什么意思,tensorflow:Efficient allreduce is not supported for 4 IndexedSlices?
- node.js - 在客户端和服务器在不同端口 reactJS 和 nodeJS 上运行的系统中使用 Google 身份验证处理登录