Aurélien Georget bd91a2ef93 Add 'packages/strapi-plugin-settings-manager/' from commit 'cd241c14c6a6239bca279e7accd709ba58e87cc8'
git-subtree-dir: packages/strapi-plugin-settings-manager
git-subtree-mainline: 80aa83d8460c95366547e143c74bf79ea6ae69f8
git-subtree-split: cd241c14c6a6239bca279e7accd709ba58e87cc8
2017-01-15 20:14:40 +01:00

52 lines
1.4 KiB
JavaScript

/**
* Create the store with asynchronously loaded reducers
*/
import { createStore, applyMiddleware, compose } from 'redux';
import { fromJS } from 'immutable';
import { routerMiddleware } from 'react-router-redux';
import createSagaMiddleware from 'redux-saga';
import createReducer from './reducers';
const sagaMiddleware = createSagaMiddleware();
const devtools = window.devToolsExtension || (() => (noop) => noop);
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
const middlewares = [
sagaMiddleware,
routerMiddleware(history),
];
const enhancers = [
applyMiddleware(...middlewares),
devtools(),
];
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) {
System.import('./reducers').then((reducerModule) => {
const createReducers = reducerModule.default;
const nextReducers = createReducers(store.asyncReducers);
store.replaceReducer(nextReducers);
});
}
// Initialize it with no other reducers
store.asyncReducers = {};
return store;
}