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