3 Principles of Redux

Redux is a predictable state container for JavaScript apps.
Redux homepage

The 3 principles of Redux

1. Representation of the state of your application through a single object
2. The state tree of Redux is readonly.

Modification is only possible by dispatching an action. Reducers are the only functions that can change the state tree.

3. State mutation: previous state -> action -> function = new state

To describe a state mutation requires a function (reducer) is taking the previous state, the action being dispatched and returns the next state.
The function has to be a pure function. A pure function returns a value that is solely referring to the value that it gets as their arguments.

/* pure */
function square(x) {
    return x * x;
}

/* impure */
function square(x) {
    updateXinSquare(x);
    return x * x;
}
Last update: Tue, 13 Sep 2022 14:32:15