__ 应该只适用于咖喱函数吗?它为什么在这里工作?
Is __ supposed to work only with curried functions? Why is it working here?
我试图理解为什么 __
在这段代码中运行良好:
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
的内部结构,就无法进一步理解代码。
我试图理解为什么 __
在这段代码中运行良好:
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
的内部结构,就无法进一步理解代码。