react - redux 中的 reducer 的命名和含义

栏目: 服务器 · 发布时间: 7年前

内容简介:reducer来自于官方网站的说明:而js 中的 Array的方法 reduce, 是这样的;[10,2,3].reduce(function(a, b){ return a + b})

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的时候知道这一点就好。 。


以上所述就是小编给大家介绍的《react - redux 中的 reducer 的命名和含义》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Understanding Machine Learning

Understanding Machine Learning

Shai Shalev-Shwartz、Shai Ben-David / Cambridge University Press / 2014 / USD 48.51

Machine learning is one of the fastest growing areas of computer science, with far-reaching applications. The aim of this textbook is to introduce machine learning, and the algorithmic paradigms it of......一起来看看 《Understanding Machine Learning》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具