2017-01-17 13:40:59 +01:00
|
|
|
/**
|
|
|
|
* Create the store with asynchronously loaded reducers
|
|
|
|
*/
|
|
|
|
|
2017-05-11 14:17:21 +02:00
|
|
|
import createSagaMiddleware from 'redux-saga';
|
|
|
|
import { applyMiddleware, compose, createStore } from 'redux';
|
2017-01-17 13:40:59 +01:00
|
|
|
import { fromJS } from 'immutable';
|
|
|
|
import { routerMiddleware } from 'react-router-redux';
|
2017-05-11 14:17:21 +02:00
|
|
|
|
2017-01-17 13:40:59 +01:00
|
|
|
import createReducer from './reducers';
|
|
|
|
|
|
|
|
const sagaMiddleware = createSagaMiddleware();
|
2017-05-11 10:54:44 +02:00
|
|
|
const devtools = window.devToolsExtension || (() => noop => noop);
|
2017-01-17 13:40:59 +01:00
|
|
|
|
|
|
|
export default function configureStore(initialState = {}, history) {
|
|
|
|
// Create the store with two middlewares
|
|
|
|
// 1. sagaMiddleware: Makes redux-sagas work
|
|
|
|
// 2. routerMiddleware: Syncs the location/URL path to the state
|
2017-05-11 10:54:44 +02:00
|
|
|
const middlewares = [sagaMiddleware, routerMiddleware(history)];
|
2017-01-17 13:40:59 +01:00
|
|
|
|
2017-05-11 10:54:44 +02:00
|
|
|
const enhancers = [applyMiddleware(...middlewares), devtools()];
|
2017-01-17 13:40:59 +01:00
|
|
|
|
|
|
|
const store = createStore(
|
|
|
|
createReducer(),
|
|
|
|
fromJS(initialState),
|
|
|
|
compose(...enhancers)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Create hook for async sagas
|
|
|
|
store.runSaga = sagaMiddleware.run;
|
|
|
|
|
|
|
|
// Make reducers hot reloadable, see http://mxs.is/googmo
|
|
|
|
/* istanbul ignore next */
|
|
|
|
if (module.hot) {
|
2017-05-11 10:54:44 +02:00
|
|
|
System.import('./reducers').then(reducerModule => {
|
2017-01-17 13:40:59 +01:00
|
|
|
const createReducers = reducerModule.default;
|
|
|
|
const nextReducers = createReducers(store.asyncReducers);
|
|
|
|
|
|
|
|
store.replaceReducer(nextReducers);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize it with no other reducers
|
|
|
|
store.asyncReducers = {};
|
|
|
|
return store;
|
|
|
|
}
|