I am making a plugin where there are some universal actions that can be handled in a reducer. I am unsure how to make it so someone can extend for additional cases with the same action. I have some code like this:
export default function createStore() {
return configureStore({
preloadedState: initialStoreState,
reducer: {
workingStores: workingStoreReducer,
},
});
}
The reducer is what you would expect:
export default createReducer(initialWorkingStoreState, (builder) => {
builder
// chained for a number of actions rather than just one in reality
.addCase(anImportedAction, (state, { payload }) => {});
Essentially someone using my plugin may have additional actions to modify the state of workingStores.
I am thinking of solving the problem in a seemingly complicated way where createStore could take a callback, and then my workingStoreReducer becomes a method of getWorkingStoreReducer which would take that callback...
export default function getWorkingStoreReducer(extensions) {
return createReducer(initialWorkingStoreState, (builder) => {
exensions(builder); // method would add cases to builder
builder.addCase(anImportedAction, (state, { payload }) => {});
});
}
This seems convoluted so hoping there is a simpler thing I have missed in the docs