Redux 是一个可预测的状态容器 [英] Redux is a predictable state container

查看:33
本文介绍了Redux 是一个可预测的状态容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Redux 项目描述为:

Redux 是一个可预测的状态容器

Redux is a predictable state container

可以向我解释在这种情况下可预测"一词的含义吗?

Can explain to me what "predictable" word meaning in this context?

推荐答案

您首先必须了解 Redux 的工作原理.有几个关键原则:

You first have to understand how Redux works. There are few key principles:

  1. 状态是一个不可变的对象
  2. 你永远不会改变应用程序的状态,你总是返回一个新的、修改过的
  3. 所有状态更改都是通过操作发起的(它们包含所需的更改详细信息)
  4. Reducers 获取当前状态、动作并产生一个新状态 ((state, action) => state)

所以你可以看到这都是单向的(只改变一个方向):

So you can see that this is all unidirectional (changes flow one way only):

state -> action -> reducer -> state -> action -> reducer -> state ...

state -> action -> reducer -> state -> action -> reducer -> state ...

Redux 深受 Elm 架构的启发,并鼓励函数式编程原则,其中之一是纯函数(它们不会产生副作用(如 http 调用、磁盘读取),并且对于相同的输入,它们的输出始终相同).

Redux is heavily inspired by Elm architecture and encourages functional programming principles, one of them being pure functions (they produce no side effects (like http calls, disk reads) and their output is always the same for the same input).

reducer 中的每一个状态变化都必须由开发人员明确注意.此外,所有减速器都应该是纯的.这就是可预测性的来源.

Every single state change in reducers has to be taken care by developers explicitly. Also all reducers are supposed to be pure. That's where the predictability comes from.

总而言之,可预测在此上下文中意味着,使用 Redux,您将了解应用程序中的每个操作将执行的操作以及状态将如何更改.

So to summarize, predictable in this context means, that using Redux you'll know what every single action in application will do and how state will change.

这篇关于Redux 是一个可预测的状态容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆