Created
November 18, 2019 23:48
-
-
Save whitelizard/4d0252175d1c25b9685eb11f9604ad75 to your computer and use it in GitHub Desktop.
Reducer for Immutable Store in JavaScript
This file contains 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) => { | |
const actions = { | |
move: ({ id, payload }) => ({ ...state, [id]: setPos(state[id], payload) }), | |
hit: ({ id1, id2 }) => ({ | |
...state, | |
[id1]: incHits(state[id1]), | |
[id2]: incHits(state[id2]), | |
}), | |
}; | |
return actions[action.type](action); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment