Reducer Composition with Objects

In notebook:
Egghead Redux
Created at:
2016-07-09
Updated:
2016-07-09
Tags:
pattern libraries JavaScript
When he logs the store, he's just calling ​console.log(store.getSate())


So far, the todos is an array. To access individual todos, by id for example we need an object instead of the array. 

Filtering todos by completed state.

  const visibilityFilter = (state = 'SHOW_ALL',action) => {
  switch (action.type) {
    case 'SET_VISIBILITY_FILTER': 
      return action.filter
    default:
      return state;
  }
}
To use this we don't need to change the old reducer:
  const todoApp = (state={}, action) => {
  return {
    todos: todos(state.todos, action),
    visibilityFilter: visibilityFilter(state.visibilityFilter, action)
  };
}

const { createStore } = Redux;
const store = createStore(todoApp);
Now the combined state of the store contains the individual state of the reducers. Each reducer handles parts of the store independently.