Skip to content

Instantly share code, notes, and snippets.

@matthieu-D
Created November 2, 2017 20:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthieu-D/5cb7cd0eb4ab87a5e0ebe695f72d01b3 to your computer and use it in GitHub Desktop.
Save matthieu-D/5cb7cd0eb4ab87a5e0ebe695f72d01b3 to your computer and use it in GitHub Desktop.
todoReducer(state, action) {
switch (action.type) {
case 'CREATE':
state = [...state, action.payload];
return state;
case 'DELETE':
state = state.filter((todo) => {
return todo.id !== action.payload.id;
});
return state;
case 'UPDATE':
const todos = state.concat([]);
let todoToUpdate = todos.filter((todo) => {
return todo.id === action.payload.id;
})[0];
todoToUpdate.value = action.payload.value;
state = todos;
return state;
default:
return state;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment