p5.js-web-editor/client/store.js

38 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

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