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》
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯系作者
- 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事?!?“怎么了?”我有些...
- 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
- 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...