-
-
Save jekku/ffb92fbccfb8d354c0afce6d57c4ffc4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
//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