Created
March 16, 2017 10:00
-
-
Save esbb48/245bb13cae82a80fb600e93da5a3ea9c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const addTodo = text => ({ type: types.ADD_TODO, text }) | |
| export const deleteTodo = id => ({ type: types.DELETE_TODO, id }) | |
| export const editTodo = (id, text) => ({ type: types.EDIT_TODO, id, text }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const ADD_TODO = 'ADD_TODO' | |
| export const DELETE_TODO = 'DELETE_TODO' | |
| export const EDIT_TODO = 'EDIT_TODO' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export default function todos(state = initialState, action) { | |
| switch (action.type) { | |
| case ADD_TODO: | |
| return [ | |
| { | |
| id: state.reduce((maxId, todo) => Math.max(todo.id, maxId), -1) + 1, | |
| completed: false, | |
| text: action.text | |
| }, | |
| ...state | |
| ] | |
| case DELETE_TODO: | |
| return state.filter(todo => | |
| todo.id !== action.id | |
| ) | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment