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.js

import { 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 following

state before: { items: [] }
state after: { items: [{ title: 'a new book'}] }
*/

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.189.138