R.cond 无法读取未定义的 属性 'length'
R.cond Cannot read property 'length' of undefined
const getStats = response => R.reduce(
R.cond([
(accum, val) => isCompleted(val), someIrrelevantFn,
(accum, val) => isOngoing(val), someOtherIrrelevantFn
]),
{ planned: R.path(['data', 'length'], response), ongoing: 0, completed: 0 },
response.data
)
当我调用 getStats(response)
时,其中 response.data
是一个数组(我已经验证了这一点),R.cond 抛出以下错误:
(node:40290) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'length' of undefined
at /Users/ash/dev/project/node_modules/ramda/src/cond.js:42:20
at _map (/Users/ash/dev/project/node_modules/ramda/src/internal/_map.js:6:19)
at map (/Users/ash/dev/project/node_modules/ramda/src/map.js:64:14)
at /Users/ash/dev/project/node_modules/ramda/src/internal/_dispatchable.js:41:15
at f2 (/Users/ash/dev/project/node_modules/ramda/src/internal/_curry2.js:29:14)
at Object.cond (/Users/ash/dev/project/node_modules/ramda/src/cond.js:41:30)
at Object.f1 [as cond] (/Users/ash/dev/project/node_modules/ramda/src/internal/_curry1.js:18:17)
at XWrap.console.log.R.reduce [as f] (/Users/ash/dev/project/functions/commands/statsinfo.js:37:25)
at XWrap.@@transducer/step (/Users/ash/dev/project/node_modules/ramda/src/internal/_xwrap.js:12:17)
at _arrayReduce (/Users/ash/dev/project/node_modules/ramda/src/internal/_reduce.js:11:34)
(node:40290) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
这发生在任何谓词被调用之前,但无论如何 isComplete 和 isOngoing 看起来像这样:
const isCompleted = R.compose(
R.pathEq(['value', 'name'], 'Done'),
R.find(R.pathEq(['customFields', 'field', 'name'], 'State')),
R.prop('fields')
)
const isOngoing = R.complement(isCompleted)
我正在使用节点 10.16.0 如果有任何相关性,任何建议将不胜感激
你好像打错了cond
。输入是一个数组数组,内部数组看起来像 [testFn, consequentFn]
.
我认为这会解决问题:
const getStats = response => R.reduce(
R.cond([
[(accum, val) => isCompleted(val), someIrrelevantFn],
// ^ ^
[(accum, val) => isOngoing(val), someOtherIrrelevantFn]
// ^ ^
]),
{ planned: R.path(['data', 'length'], response), ongoing: 0, completed: 0 },
response.data
)
const getStats = response => R.reduce(
R.cond([
(accum, val) => isCompleted(val), someIrrelevantFn,
(accum, val) => isOngoing(val), someOtherIrrelevantFn
]),
{ planned: R.path(['data', 'length'], response), ongoing: 0, completed: 0 },
response.data
)
当我调用 getStats(response)
时,其中 response.data
是一个数组(我已经验证了这一点),R.cond 抛出以下错误:
(node:40290) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'length' of undefined
at /Users/ash/dev/project/node_modules/ramda/src/cond.js:42:20
at _map (/Users/ash/dev/project/node_modules/ramda/src/internal/_map.js:6:19)
at map (/Users/ash/dev/project/node_modules/ramda/src/map.js:64:14)
at /Users/ash/dev/project/node_modules/ramda/src/internal/_dispatchable.js:41:15
at f2 (/Users/ash/dev/project/node_modules/ramda/src/internal/_curry2.js:29:14)
at Object.cond (/Users/ash/dev/project/node_modules/ramda/src/cond.js:41:30)
at Object.f1 [as cond] (/Users/ash/dev/project/node_modules/ramda/src/internal/_curry1.js:18:17)
at XWrap.console.log.R.reduce [as f] (/Users/ash/dev/project/functions/commands/statsinfo.js:37:25)
at XWrap.@@transducer/step (/Users/ash/dev/project/node_modules/ramda/src/internal/_xwrap.js:12:17)
at _arrayReduce (/Users/ash/dev/project/node_modules/ramda/src/internal/_reduce.js:11:34)
(node:40290) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
这发生在任何谓词被调用之前,但无论如何 isComplete 和 isOngoing 看起来像这样:
const isCompleted = R.compose(
R.pathEq(['value', 'name'], 'Done'),
R.find(R.pathEq(['customFields', 'field', 'name'], 'State')),
R.prop('fields')
)
const isOngoing = R.complement(isCompleted)
我正在使用节点 10.16.0 如果有任何相关性,任何建议将不胜感激
你好像打错了cond
。输入是一个数组数组,内部数组看起来像 [testFn, consequentFn]
.
我认为这会解决问题:
const getStats = response => R.reduce(
R.cond([
[(accum, val) => isCompleted(val), someIrrelevantFn],
// ^ ^
[(accum, val) => isOngoing(val), someOtherIrrelevantFn]
// ^ ^
]),
{ planned: R.path(['data', 'length'], response), ongoing: 0, completed: 0 },
response.data
)