Skip to content

Instantly share code, notes, and snippets.

@innovid-rnd
Created March 6, 2018 12:21
Show Gist options
  • Save innovid-rnd/5c0f89d4cab8a40628b9bbd1230cf115 to your computer and use it in GitHub Desktop.
Save innovid-rnd/5c0f89d4cab8a40628b9bbd1230cf115 to your computer and use it in GitHub Desktop.
Configuring the redux store and 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