redux 函数式组件
Discover Functional JavaScript was named one of the best new Functional Programming books by BookAuthority!
“发现功能JavaScript”被BookAuthority评为最佳新功能编程书籍之一 !
Redux is a state container that promotes the use of functional programming for managing state.
Redux是一个状态容器,可促进使用功能编程来管理状态。
I would say that the Redux ecosystem has evolved in an architectural pattern that gives best practices on how to organize an application.
我要说的是,Redux生态系统已经以一种体系结构模式发展,该体系结构为如何组织应用程序提供了最佳实践。
纯函数 (Pure Functions)
Pure functions produce the same output value, given the same input. Pure functions have no side-effects.
给定相同的输入,纯函数会产生相同的输出值。 纯函数没有副作用。
Pure functions don’t mutate data, so the question is how can we change state and at the same time use pure functions. Redux proposes a solution: we write pure functions and let the library apply them and do the state change.
纯函数不会改变数据,因此问题是我们如何更改状态并同时使用纯函数。 Redux提出了一个解决方案:我们编写纯函数,然后让库应用它们并进行状态更改。
The application does state change, but the mutation is encapsulated behind the Redux store.
该应用程序确实会进行状态更改,但是该突变被封装在Redux存储后面。
不变性 (Immutability)
An immutable value is a value that, once created, cannot be changed.
不变值是一旦创建就无法更改的值。
The state value is immutable, so each time we want to change the state we need to create a new immutable value.
状态值是不可变的,因此每次我们要更改状态时,都需要创建一个新的不可变值。
The value of state is immutable but state can change. There is no point to use a library to manage state that doesn’t change. We can use a plain object to store that kind of data.
状态的值是不变的,但状态可以更改。 没有必要使用库来管理不变的状态。 我们可以使用一个普通的对象来存储这种数据。
建筑 (Architecture)
Redux suggests that we split a practical application into the following parts:
Redux建议我们将实际应用分为以下几部分:
- Presentation Components 演示组件
- Action Creators (aka Synchronous Action Creators) 动作创建者(又名同步动作创建者)
- Reducers 减速器
- Asynchronous Action Creators 异步动作创建者
- API Utils/Gateways API实用程序/网关
- Selectors 选择器
- Container Components 容器组件
Discover Functional JavaScript was named one of the best new Functional Programming books by BookAuthority!
发现功能JavaScript被称为 BookAuthority最好的新功能编程书籍 !
For more on applying functional programming techniques in React take a look at Functional React.
有关在React中应用函数式编程技术的更多信息,请查看 Functional React 。
Learn functional React, in a project-based way, with Functional Architecture with React and Redux.
通过带有React和Redux的功能架构 ,以基于项目的方式学习功能性React 。
redux 函数式组件