Adding to and cleaning up the register method

One of the store's jobs has been to handle eventing, especially when the store wants to convey to a view that a change has happened to its state. In the store.js file, other things were happening as well, things like registering ourselves with the dispatcher and being able to receive dispatched actions. We used these actions to alter the state of the store. Let's remind ourselves what that looked like:

// store.jslet store = {};function selectIndex(index) {  store["selectedIndex"] = index;}dispatcher.register(message => {  switch (message.type) {    case "SELECT_INDEX":      selectIndex(message.data);      break;  }});

Here, we are only supporting one action, namely SELECT_INDEX. There are two things we need ...

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.