Created
February 4, 2018 11:52
-
-
Save Cotel/56b38ecad76e94e027197e558e157f83 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
import {combineReducers} from 'redux' | |
const todos = (state = [], {type, payload}) => { | |
switch(type) { | |
case LIST_TODOS: | |
return payload | |
case ADD_TODO: | |
return {...state, payload} | |
case TOGGLE_TODO: | |
return state.map(todo => todo.id === payload ? {...todo, completed: !todo.completed} : todo) | |
default: | |
return state | |
} | |
} | |
const isLoading = (state = false, {type}) => { | |
switch(type) { | |
case FETCH_TODOS: | |
return true | |
case LIST_TODOS: | |
return false | |
default: | |
return state | |
} | |
} | |
const filter = (state = 'all', {type}) => { | |
switch(type) { | |
case FILTER_ALL: | |
return 'all' | |
case FILTER_COMPLETED: | |
return 'completed' | |
case FILTER_UNCOMPLETED: | |
return 'uncompleted' | |
default: | |
return state | |
} | |
} | |
export default combineReducers({ | |
todos, | |
isLoading, | |
filter | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment