Skip to content

Instantly share code, notes, and snippets.

@jekku
Last active December 15, 2016 06:22
Show Gist options
  • Save jekku/ffb92fbccfb8d354c0afce6d57c4ffc4 to your computer and use it in GitHub Desktop.
Save jekku/ffb92fbccfb8d354c0afce6d57c4ffc4 to your computer and use it in GitHub Desktop.
//array reducer
function todos(state = initialState, action) {
switch (action.type) {
case ADD_TODO:
return [
...state,
todo(null, action)
]
case TOGGLE_TODO:
return state.map(t => todo (t, action));
default:
return state
}
}
function todo (state, action) {
switch (action.type) {
case ADD_TODO:
return {
text: action.text,
completed, false
}
case TOGGLE_TODO:
if (action.id === state.id) {
return {
...state,
completed: !state.completed
}
}
return state;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment