| 1 | const todos = (state = [], action) => { |
| 2 | switch (action.type) { |
| 3 | case 'ADD_TODO': |
| 4 | return [ |
| 5 | ...state, |
| 6 | { |
| 7 | id: action.id, |
| 8 | text: action.text, |
| 9 | completed: false |
| 10 | } |
| 11 | ] |
| 12 | case 'TOGGLE_TODO': |
| 13 | return state.map(todo => |
| 14 | (todo.id === action.id) |
| 15 | ? {...todo, completed: !todo.completed} |
| 16 | : todo |
| 17 | ) |
| 18 | default: |
| 19 | return state |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | export default todos |