Read-only states

We want to ensure we only have one way to alter state, and that is through mediators called actions. An action should describe the intent of the action as well as the data that should be applied to the current state. An action is dispatched by us using a store.dispatch(action). The action itself should look like the following:

// principles/action.js// the actionlet action = {  // expresses intent, loading jedis  type: "LOAD_JEDIS",   payload:[    { name: "Yoda", id: 1 },    { name: "Palpatine", id: 2 },     { name: "Darth Vader", id: 3 }  ]};

At this point, let's try to implement what a store might actually look like and what it initially contains:

// principles/storeII.jsclass Store {  constructor() {    this.state = {      jedis: [], selectedJedi: ...

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.