Skip to content

Instantly share code, notes, and snippets.

@Cotel
Created February 4, 2018 11:52
Show Gist options
  • Save Cotel/56b38ecad76e94e027197e558e157f83 to your computer and use it in GitHub Desktop.
Save Cotel/56b38ecad76e94e027197e558e157f83 to your computer and use it in GitHub Desktop.
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