
上QQ阅读APP看书,第一时间看更新
The read-only state
In a Redux application, you cannot modify application state directly. The only way to change the state is by dispatching actions:
This restriction ensures that state changes are predictable. If no action happens, nothing in the application changes.
Because actions are processed one at a time, we do not have to deal with race conditions.
Because actions are plain JavaScript objects, they can be easily serialized, logged, stored, and replayed. This makes debugging and testing easy.
A Redux action object (to create a new post) could look like this:
{ type: 'CREATE_POST', user: 'dan', text: 'New post' }