Skip to content

Instantly share code, notes, and snippets.

@avivshafir
Last active March 5, 2018 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avivshafir/dee43f43bde4d7adaa3bb1eef080b117 to your computer and use it in GitHub Desktop.
Save avivshafir/dee43f43bde4d7adaa3bb1eef080b117 to your computer and use it in GitHub Desktop.
Injecting Async Redux Reducers
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