Skip to content

Instantly share code, notes, and snippets.

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