Single source of truth

The data lives in a single store in Redux and not a multiple store like in Flux. The data is represented by one object tree. This brings about a lot of benefits, such as:

  • It is easier to see what your application knows at any given point, so it is easy to serialize or deserialize it.
  • It is easier to work with in development, and easier to debug and inspect.
  • It easier to do things such as undo/redo if all applied actions produce a new state.

An example of a single store can look like the following:

// principles/store.jsclass Store {  getState() {    return {      jedis: [        { name: "Yoda", id: 1 },        { name: "Palpatine", id: 2 },        { name: "Darth Vader", id: 3 }      ],      selectedJedi: {        name: "Yoda",        id: 1      }    };  }}const store = new Store(); ...

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.