Last active
March 5, 2018 19:16
-
-
Save avivshafir/dee43f43bde4d7adaa3bb1eef080b117 to your computer and use it in GitHub Desktop.
Injecting Async Redux Reducers
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 function injectAsyncReducer(store, name, asyncReducer) { | |
if (store.asyncReducers[name]) { | |
return; | |
} | |
store.asyncReducers[name] = asyncReducer; | |
store.replaceReducer(createReducer(store.asyncReducers)); | |
} | |
export const configureStore = (initialState: AppState) => { | |
const enhancer = compose(applyMiddleware(...getMiddleware())); | |
const store: any = createStore(createReducer(), initialState, enhancer); | |
store.asyncReducers = {}; | |
return store; | |
}; | |
const createReducer = (asyncReducers = {}) => { | |
return combineReducers({ | |
user, | |
sidenav, | |
navigation, | |
//... | |
...asyncReducers | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment