Created
July 19, 2016 08:07
-
-
Save justin3737/b26c2008db09b0d40ed78651244cfcd0 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
function reducer(state = [], action) { | |
switch (action.type) { | |
case 'ADD_ATTENDEE': | |
// Return a new array with old state and added attendee. | |
return [{ | |
name: action.name, | |
color: action.color | |
}, | |
...state | |
]; | |
case 'REMOVE_ATTENDEE': | |
return [ | |
// Grab state from begging to index of one to delete | |
...state.slice(0, action.index), | |
// Grab state from the one after one we want to delete | |
...state.slice(action.index + 1) | |
]; | |
default: | |
return state; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment