import { Store } from '../store'; import { combineReducers } from 'redux'; import { createReducer } from 'redux-starter-kit'; export const todosReducer = createReducer( {}, { addTodo(state, action) { state[action.id] = { label: action.label, completed: false }; }, remove(state, action) { delete state[action.id]; }, clear(state, action) { state[action.id].completed = !state[action.id].completed; }, complete(state, action) { Object.keys(state).forEach(key => { if (state[key].completed) { delete state[key]; } }); }, edit(state, action) { state[action.id].label = action.label; } } ); export const filterReducer = createReducer('all', { setFilter(state, action) { return action.filter; } }); export const reducer = combineReducers({ todos: todosReducer, filter: filterReducer });