(initialState = {}, history)
| 8 | import createReducer from './reducers'; |
| 9 | |
| 10 | export default function configureStore(initialState = {}, history) { |
| 11 | let composeEnhancers = compose; |
| 12 | const reduxSagaMonitorOptions = {}; |
| 13 | |
| 14 | // If Redux Dev Tools and Saga Dev Tools Extensions are installed, enable them |
| 15 | /* istanbul ignore next */ |
| 16 | if (process.env.NODE_ENV !== 'production' && typeof window === 'object') { |
| 17 | /* eslint-disable no-underscore-dangle */ |
| 18 | if (window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) |
| 19 | composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({}); |
| 20 | |
| 21 | // NOTE: Uncomment the code below to restore support for Redux Saga |
| 22 | // Dev Tools once it supports redux-saga version 1.x.x |
| 23 | // if (window.__SAGA_MONITOR_EXTENSION__) |
| 24 | // reduxSagaMonitorOptions = { |
| 25 | // sagaMonitor: window.__SAGA_MONITOR_EXTENSION__, |
| 26 | // }; |
| 27 | /* eslint-enable */ |
| 28 | } |
| 29 | |
| 30 | const sagaMiddleware = createSagaMiddleware(reduxSagaMonitorOptions); |
| 31 | |
| 32 | // Create the store with two middlewares |
| 33 | // 1. sagaMiddleware: Makes redux-sagas work |
| 34 | // 2. routerMiddleware: Syncs the location/URL path to the state |
| 35 | const middlewares = [sagaMiddleware, routerMiddleware(history)]; |
| 36 | |
| 37 | const enhancers = [applyMiddleware(...middlewares)]; |
| 38 | |
| 39 | const store = createStore( |
| 40 | createReducer(), |
| 41 | initialState, |
| 42 | composeEnhancers(...enhancers), |
| 43 | ); |
| 44 | |
| 45 | // Extensions |
| 46 | store.runSaga = sagaMiddleware.run; |
| 47 | store.injectedReducers = {}; // Reducer registry |
| 48 | store.injectedSagas = {}; // Saga registry |
| 49 | |
| 50 | // Make reducers hot reloadable, see http://mxs.is/googmo |
| 51 | /* istanbul ignore next */ |
| 52 | if (module.hot) { |
| 53 | module.hot.accept('./reducers', () => { |
| 54 | store.replaceReducer(createReducer(store.injectedReducers)); |
| 55 | }); |
| 56 | } |
| 57 | |
| 58 | return store; |
| 59 | } |
no test coverage detected