Thinking in Redux
Describe state with normal object. Dispatch an action to update the data of state.
Use some functions to connect action with state, that is reducer.
Add another reducer to call the reduces above, to manage the whole state of application:
- One way data flow
- Appliction’s state is maintained in a object tree, which exists unique in stores。
- State is only readable
- The only way to change state is dispatch an action，which is an object to descrbie what happened.
- Action just describe the fact that something happened, do not describe how to update the state.
Action is an object, and can be logged、serialized、stored.
- use pure function to modify
Action is the only datasource of store. Use
store.dispatch() to deliver action into store.
Use action generate function in Redux, to return an action:
Reducers specify how changes to the application state are sent to the store in response to actions.
Reducer is pure function，with prev state and prev action as params, to return new state:
equals to ：
- maintain states of application；
getState() to get state；
dispatch(action) to update state；
subscribe(listener) to add listener;
- Redux store call the incoming reducer function
- root reducer combine chidren reducers to a single state tree。
- Redux store mantain the root reducer to return the whole state。