function visibleTodoFilter(state = 'watch', action) {
switch (action.type) {
case 'CHANGE_VISIBLE_FILTER':
return action.filter;
default:
return state;
}
}
function todos(state, action) {
switch (action.type) {
case 'ADD_TODO':
return [...state, {
text: action.text,
completed: false
}];
case 'COMPLETE_TODO':
return [
...state.slice(0, action.index),
Object.assign({}, state[action.index], {
completed: true
}),
...state.slice(action.index + 1)
]
default:
return state;
}
}
import { combineReducers, createStore } from 'redux';
let reducer = combineReducers({ visibleTodoFilter, todos });
let store = createStore(reducer);