Added support for createStore to accept a reducer function#12
Added support for createStore to accept a reducer function#12mattcgenui wants to merge 5 commits intogeneralui:masterfrom
Conversation
|
I could be wrong, but I think there is an easier way to do this. Reducers can be chained. If the reducer passed in is a function, we can just use logic something like this: // (initialReducer = {}, ...args) =>
const combinedReducer = combineReducers(reducers)
const overallReducer = (state, action) => initialReducer(combinedReducer(state, action), action)
store.replaceReducer(overallReducer) |
|
This should work with a regular reducer function. However, if the |
|
Interesting. I didn't know about UnexpectedStateShapeWarning. It's unfortunate to have to end-run a false warning message with some fairly runtime heavy code. Looking at your overall implementation, I'm concerned about the performance of the rootReducers. They do a lot of work every time an action is dispatched that could be cached. The actual work in the rootReducer should be as light as possible. Example: // these never change, but currently they will be executed for every dispatched action
const initialSlices = initialReducer ? initialReducer({}, '') : {}
const initialKeys = Object.keys(initialSlices)
const knownKeys = Object.keys(reducers)Are there any other opportunities to move any |
No description provided.