Created
February 4, 2018 11:24
-
-
Save Cotel/b137e981e4bbae588a69de6c25563830 to your computer and use it in GitHub Desktop.
This file contains 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
const initialState = { | |
todos: [], | |
filter: 'all', | |
isLoading: false | |
} | |
export default function(state = initialState, action) { | |
switch (action.type) { | |
case FETCH_TODOS: | |
return {...state, isLoading: true} | |
case LIST_TODOS: | |
return {...state, todos: action.payload, isLoading: false} | |
case ADD_TODO: | |
return {...state, todos: {...state.todos, action.payload}} | |
case TOGGLE_TODO: | |
return {...state, todos: state.todos.map(todo => todo.id === action.payload ? {...todo, completed: !todo.completed} : todo)} | |
case FILTER_ALL: | |
return {...state, filter: 'all'} | |
case FILTER_COMPLETED: | |
return {...state, filter: 'completed'} | |
case FILTER_UNCOMPLETED: | |
return {...state, filter: 'uncompleted'} | |
default: | |
return state | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment