2016-06-10 00:41:40 +02:00
|
|
|
import { createStore, applyMiddleware, compose } from 'redux'
|
|
|
|
import thunk from 'redux-thunk'
|
2016-06-23 00:36:04 +02:00
|
|
|
import DevTools from './modules/App/components/DevTools'
|
2016-06-22 21:58:23 +02:00
|
|
|
import rootReducer from './reducers'
|
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),
|
|
|
|
];
|
|
|
|
|
|
|
|
if (process.env.CLIENT && process.env.NODE_ENV === 'development') {
|
|
|
|
// Enable DevTools only when rendering on client and during development.
|
|
|
|
enhancers.push(window.devToolsExtension ? window.devToolsExtension() : DevTools.instrument());
|
|
|
|
}
|
|
|
|
|
2016-05-05 23:48:26 +02:00
|
|
|
const store = createStore(
|
|
|
|
rootReducer,
|
2016-06-10 00:41:40 +02:00
|
|
|
initialState,
|
2016-06-23 00:36:04 +02:00
|
|
|
compose(...enhancers)
|
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', () => {
|
|
|
|
const nextRootReducer = require('./reducers').default
|
2016-05-05 23:48:26 +02:00
|
|
|
store.replaceReducer(nextRootReducer)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return store
|
|
|
|
}
|