Skip to content

Instantly share code, notes, and snippets.

@BiosBoy
Created January 13, 2019 12:25
Show Gist options
  • Select an option

  • Save BiosBoy/2d04326c3b45bec5135665fa61fd8cee to your computer and use it in GitHub Desktop.

Select an option

Save BiosBoy/2d04326c3b45bec5135665fa61fd8cee to your computer and use it in GitHub Desktop.
import { applyMiddleware, compose, createStore } from 'redux';
import { routerMiddleware } from 'connected-react-router';
import initialState from './initialState';
import history from './history';
import { logger, makeRootReducer, sagaMiddleware as saga, rootSaga, runSaga } from './middleware';
// creating the root store config
const rootStore = () => {
const middleware = [];
// Adding app routing
middleware.push(routerMiddleware(history));
// Adding async Saga actions environment
middleware.push(saga);
// Adding console logger for Redux
middleware.push(logger);
const enhancers = [];
// allow to use the redux browser plugin
if (__DEV__ && window.__REDUX_DEVTOOLS_EXTENSION__) {
enhancers.push(window.__REDUX_DEVTOOLS_EXTENSION__());
}
// ======================================================
// Store Instantiation
// ======================================================
const store = createStore(
makeRootReducer(),
initialState,
compose(
applyMiddleware(...middleware),
...enhancers
)
);
// saga injecting during code-splitting
store.runSaga = runSaga;
runSaga(rootSaga);
store.asyncReducers = {};
return store;
};
export default rootStore();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment