Created
November 2, 2017 20:53
-
-
Save matthieu-D/5cb7cd0eb4ab87a5e0ebe695f72d01b3 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
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