reactnative - redux 中的 reducer 的命名和含义
访问量: 2319
reducer来自于官方网站的说明:
而js 中的 Array的方法 reduce, 是这样的;
[10,2,3].reduce(function(a, b){ return a + b})
结果是 15. ( 10 + 2 + 3)
[10,2,3].reduce(function(a, b){ return a - b})
结果是5 ( 10 -2 - 3)
所以 , reduce 是把一个数组压缩成一个值的函数。(reduce an array to a single value)
在上面的代码中, reduce所接受的函数, ( function(a,b) {return a+b}) ,
在redux中,就叫做reducer 。 英文原文: It's called a reducer because it's the type of function you would pass to Array.prototype.reduce(reducer, ?initialValue)
所以,这个东西完全不要翻译, 它是从语法概念的层面得到的名称,而不是 "store, action"这样 含义非常明显的名称。
大家在使用redux的时候知道这一点就好。 。