2016-06-24 00:29:55 +02:00
|
|
|
import { createStore, applyMiddleware, compose } from 'redux';
|
|
|
|
import thunk from 'redux-thunk';
|
|
|
|
import DevTools from './modules/App/components/DevTools';
|
|
|
|
import rootReducer from './reducers';
|
2017-04-20 20:05:15 +02:00
|
|
|
import { clearState, loadState } from './persistState';
|
2020-06-08 11:46:38 +02:00
|
|
|
import getConfig from './utils/getConfig';
|
2018-08-24 23:41:23 +02:00
|
|
|
|
2016-05-05 23:48:26 +02:00
|
|
|
export default function configureStore(initialState) {
|
2016-06-23 00:36:04 +02:00
|
|
|
const enhancers = [
|
|
|
|
applyMiddleware(thunk),
|
|
|
|
];
|
|
|
|
|
2020-06-08 11:46:38 +02:00
|
|
|
if (getConfig('CLIENT') && getConfig('NODE_ENV') === 'development') {
|
2016-06-23 00:36:04 +02:00
|
|
|
// Enable DevTools only when rendering on client and during development.
|
|
|
|
enhancers.push(window.devToolsExtension ? window.devToolsExtension() : DevTools.instrument());
|
|
|
|
}
|
|
|
|
|
2017-04-20 20:05:15 +02:00
|
|
|
const savedState = loadState();
|
|
|
|
clearState();
|
|
|
|
|
2016-05-05 23:48:26 +02:00
|
|
|
const store = createStore(
|
|
|
|
rootReducer,
|
2017-04-20 20:05:15 +02:00
|
|
|
savedState != null ? savedState : initialState,
|
2016-06-23 00:36:04 +02:00
|
|
|
compose(...enhancers)
|
2016-06-24 00:29:55 +02:00
|
|
|
);
|
2016-05-05 23:48:26 +02:00
|
|
|
|
|
|
|
if (module.hot) {
|
|
|
|
// Enable Webpack hot module replacement for reducers
|
2016-06-22 21:58:23 +02:00
|
|
|
module.hot.accept('./reducers', () => {
|
2016-06-24 00:29:55 +02:00
|
|
|
const nextRootReducer = require('./reducers').default; // eslint-disable-line global-require
|
|
|
|
store.replaceReducer(nextRootReducer);
|
|
|
|
});
|
2016-05-05 23:48:26 +02:00
|
|
|
}
|
|
|
|
|
2016-06-24 00:29:55 +02:00
|
|
|
return store;
|
|
|
|
}
|
|
|
|
|