Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

基于typescript的redux(ng-book2) #4

Open
chenbj2333 opened this issue Jun 23, 2017 · 0 comments
Open

基于typescript的redux(ng-book2) #4

chenbj2333 opened this issue Jun 23, 2017 · 0 comments

Comments

@chenbj2333
Copy link
Owner

为什么要使用redux

1 属性的间接传递:为了让任何组件都可以获取到应用的状态,我们会使用inputs传递值,这可能导致我们会借助很多中间组件来传递状态,但是这些中间组件不使用这些值也不关心这些值的状态。
2 重构不灵活:传递inputs会贯穿整个组件树,从而导致父子组件之间的耦合。
3 状态树和dom树不匹配。
4 应用中到处都是状态:如果通过组件来管理状态,就很难获取应用整体状态的快照。很难知道哪个组件拥有一条特定的数据以及哪些组件关心该数据的变化。
redux就是把所有应用状态都存在同一个地方。

redux的核心概念

1 应用的所有数据都放在一个叫做state的数据结构之中,state放在store中。
2 应用从store中读取state。
3 store永远不会被直接修改。
4 action描述发生了什么,由用户交互触发。
5 通过调用一个reducer的函数来结合旧的state和action会创建出新的state。

reducer是什么

接收旧的state和action返回新的state。reducer是一个纯函数,它不能直接修改当前的state,也不会使用除参数之外的任何数据。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant