Created
July 18, 2018 13:41
-
-
Save Piliponful/d71a6f280167e4cf71d8b527bc6d78e8 to your computer and use it in GitHub Desktop.
redux abstruction
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
export default initialState => { | |
const stateEntriesNames = Object.keys(initialState) | |
const reducer = (state, action) => stateEntriesNames.includes(action.type) ? ({ ...new Map(state).set(action.type, action.payload) }) : initialState | |
const setters = stateEntriesNames.reduce((acc, next) => ({ ...acc, [next]: payload => ({ type: next, payload }) }), {}) | |
return { reducer, setters } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment