美文网首页
Redux中compose函数实现

Redux中compose函数实现

作者: Chris__Liu | 来源:发表于2020-04-14 11:39 被阅读0次

reduce 搭配函数 carry 化的妙用

function compose(...funcs) {
  if (funcs.length === 0) {
    return (arg) => arg
  }

  if (funcs.length === 1) {
    return funcs[0]
  }

  return funcs.reduce((a, b) => (...args) => a(b(...args)))
}

相关文章

网友评论

      本文标题:Redux中compose函数实现

      本文链接:https://www.haomeiwen.com/subject/gkzjuhtx.html