Redux architecture revolves around a strict unidirectional data flow.
1. You call store.dispatch(action)
from anywhere in your app, including components and XHR callbacks, or even at scheduled intervals.
2. The Redux store calls the reducer function you gave it.
The store will pass two arguments to the reducer: the current state tree and the action.
1 | // The current application state (list of todos and chosen filter) |
Note that a reducer is a pure function. It only computes the next state. It should be completely predictable: calling it with the same inputs many times should produce the same outputs. It shouldn’t perform any side effects like API calls or router transitions. These should happen before an action is dispatched.
3. The root reducer may combine the output of multiple reducers into a single state tree.
4. The Redux store saves the complete state tree returned by the root reducer.
This new tree is now the next state of your app! Every listener registered with store.subscribe(listener) will now be invoked; listeners may call store.getState() to get the current state.
Now, the UI can be updated to reflect the new state. If you use bindings like React Redux, this is the point at which component.setState(newState) is called.