Immutability patterns

The whole point of the state is to take an existing state, apply an action to it, and produce a new state. It can be written like this:

old state + action = new state

Imagine, if you were performing basic calculations, then you would start writing it like this:

// sum is 0
let sum = 0;

// sum is now 3
sum +=3;

The Redux way of doing things, though, is to change the preceding to:

let sum = 0;
let sumWith3 = sum + 3;
let sumWith6 = sumWith3 + 3;

We don't mutate anything but rather produce a new state for everything we do. Let's look at different constructs and what it means in practice to not mutate.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.87.83