March 2018
Intermediate to advanced
364 pages
8h 21m
English
OK, so our Redux implementation seems to be working. It's time to clean it up a bit. We need to move the reducer out into its own file, like so:
// dataflow/reducer.jsfunction itemsReducer(state = [], action) { switch(action.type) { case "CREATE_ITEM": return [...state, Object.assign(action.payload) ]; default: return state; } }
It's also a good idea to add a select() function to the store as we sometimes don't want to move a full state back, only part of it. Our list view will benefit from the use of the select() function. Let's add that next:
// dataflow/redux-stepII.js// this now refers to the reducers.js file we broke outimport { itemsReducer } from "./reducers";let state = { items: []};function store(state ...Read now
Unlock full access