Module 2 of 3 · Text
Redux - The principles of Redux
The principles of Redux
- Single source of truth – all of the different states of different services and components are saved into the store, an object that holds the complete state.
- Universal apps - This makes it possible to serialize state on server side and pass it to the client with no extra effort, thus making it easy to create universal apps.
- Easier to debug - or inspect the application
- Enables persistence of app state in development – makes for faster development cycles
- Some functionality becomes trivial to implement - for example Undo/Redo
- State is read-only
- The only way to change state is by emitting actions, an object describing what happened.
- Since state mutation is centralized, and changes happen one by one in a strict order, there is no subtle race conditions (which change happened first? and which changes are dependent on that change?).
- Since actions are plain objects they can be logged, stored, serialized for debugging and research.
- Changes are made with pure functions
- reducers are just pure functions that take the previous state and an action, and return the next state.