Redux is a predictable state container for JavaScript apps.
Keep your state flat.
-
Redux Flow
mutation and asynchronicity
Redux attempts to make state mutations predictable by imposing certain restrictions on how and when updates can happen.
To change something in the state, you need to dispatch an action. An action is a plain JavaScript object (notice how we don’t introduce any magic?) that describes what happened.
Finally, to tie state and actions together, we write a function called a reducer. Again, nothing magical about it—it’s just a function that takes state and action as arguments, and returns the next state of the app.
-
Three Principles
- Single source of truth (The state of your whole application is stored in an object tree within a single store.)
- State is read-only (The only way to change the state is to emit an action, an object describing what happened.)
- Changes are made with pure functions (To specify how the state tree is transformed by actions, you write pure reducers.)
Reducers are just pure functions that take the previous state and an action, and return the next state. Remember to return new state objects, instead of mutating the previous state.
《Redux》
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...