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 0let sum = 0;// sum is now 3sum +=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.

Get Architecting Angular Applications with Redux, RxJS, and NgRx now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.