Created
June 23, 2019 22:31
-
-
Save jsmanifest/65e24ccda0e9f5908f1b61b15c1c9cba 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
const reducer = (state, action) => { | |
switch (action.type) { | |
case 'set-theme': | |
return { ...state, theme: action.theme, history: insertToHistory(state) } | |
case 'add-friend': | |
return { | |
...state, | |
friends: [...state.friends, action.friend], | |
history: insertToHistory(state), | |
} | |
case 'undo': { | |
const isEmpty = !state.history.length | |
if (isEmpty) return state | |
return { ...state.history[state.history.length - 1] } | |
} | |
case 'reset': | |
return { ...initialState, history: insertToHistory(state) } | |
default: | |
return state | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment