Last active
August 28, 2019 19:49
-
-
Save brookslybrand/46bb919063be9c755b5fbc64aeb2ffe6 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 = produce((state, action) => { | |
| // eslint-disable-next-line default-case | |
| switch (action.type) { | |
| case REVERSE: { | |
| state.reverse(); | |
| break; | |
| } | |
| case SET_OPTION: { | |
| const { id, option } = action; | |
| const itemOptions = state.find(item => item.id === id).options; | |
| itemOptions[option].value = !itemOptions[option].value; | |
| break; | |
| } | |
| case RESET_OPTIONS: { | |
| state.forEach(({ options }) => | |
| Object.values(options).map(option => (option.value = false)) | |
| ); | |
| break; | |
| } | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment