redux-middleware的实现
博客地址 从 compose 函数开始 在函数式编程当中有一个很重要的概念就是函数组合,实际上就是把处理数据的函数像管道一样连接起来,然后让数据穿过管道得到最终的结果。 const add = x => x + 2 // 加 const minus = x => x - 2 // 减 const mul = x => x * 2 // 乘 const div = x => x / 2 // 除 minus(mul(add(3))) // => 8 如果我想对一个参数执行上面的 add, mul, minus 函数, 然后得到返回值, 上面的写法可读性就会很差, 这时候我们就需要一个 compose 函数, 它可以接受上面的函数作为参数, 然后返回一个函数, 返回的这个函数也可以达成上面的效果, 如下 ... const myOperate1 = compose(minus, mul, add) // 加 => 乘 => 减 const myOperate2 = compose(div, add, mul) // 乘 => 加 => ...




