Testing out our store

Now it is time to put our code to use; first, we will create a redux-demo.js file to test out our Redux implementation, then we will polish it a bit, and lastly we will use it in the view we created earlier:

// dataflow/redux-demo.jsimport { dispatch, getState, select, subscribe } from "./redux";const { addItem } = require("./actions");subscribe(() => {console.log("store changed");});console.log("initial state", getState());dispatch(addItem("A book"));dispatch(addItem("A second book"));console.log("after dispatch", getState());console.log("items", select("items"));/* this will print the followingstate before: { items: [] }state after: { items: [{ title: 'a new book'}] }*/

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.