Last active
April 16, 2021 01:04
-
-
Save pflevy/bc555d0e6fa159894ece9316997e3433 to your computer and use it in GitHub Desktop.
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
export const multipleIdsReducerHandler = (reducerFunction) => ( | |
state = {}, | |
action | |
) => { | |
const { internalReducerId } = action; | |
if (internalReducerId === undefined) return state; | |
const newState = reducerFunction( | |
state?.byId?.[internalReducerId] || {}, | |
action | |
); | |
if (Object.keys(newState).length === 0) return state; | |
return { | |
...state, | |
byId: { | |
...state.byId, | |
[internalReducerId]: { ...newState } | |
} | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment