Redux is a predictable state container

后端 未结 4 2191
被撕碎了的回忆
被撕碎了的回忆 2021-02-09 18:08

The description of Redux project is:

Redux is a predictable state container

Can explain to me what \"predictable\" word meaning in t

4条回答
  •  不要未来只要你来
    2021-02-09 18:38

    You first have to understand how Redux works. There are few key principles:

    1. State is a immutable object
    2. You never mutate application state, you always return a new, modified one
    3. All state changes are initiated through actions (they contain desired changes details)
    4. Reducers take current state, action and produce a new state ((state, action) => state)

    So you can see that this is all unidirectional (changes flow one way only):

    state -> action -> reducer -> state -> action -> reducer -> state ...

    Redux is heavily inspired by Elm architecture and encourages functional programming principles, one of them being pure functions (they produce no side effects (like http calls, disk reads) and their output is always the same for the same input).

    Every single state change in reducers has to be taken care by developers explicitly. Also all reducers are supposed to be pure. That's where the predictability comes from.

    So to summarize, predictable in this context means, that using Redux you'll know what every single action in application will do and how state will change.

提交回复
热议问题