1 | import { createStore, applyMiddleware, compose } from 'redux';
|
2 | import { routerMiddleware } from 'react-router-redux';
|
3 | import thunk from 'redux-thunk';
|
4 | import { createLogger } from 'redux-logger';
|
5 | import rootReducer from '../reducers';
|
6 | import { isClient, isDebug } from '../../config/app';
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | export default function configureStore(initialState, history) {
|
15 |
|
16 | const middleware = [thunk, routerMiddleware(history)];
|
17 | let store;
|
18 |
|
19 | if (isClient && isDebug) {
|
20 | middleware.push(createLogger());
|
21 | store = createStore(rootReducer, initialState, compose(
|
22 | applyMiddleware(...middleware),
|
23 | typeof window === 'object' && typeof window.devToolsExtension !== 'undefined' ? window.devToolsExtension() : f => f
|
24 | ));
|
25 | } else {
|
26 | store = createStore(rootReducer, initialState, compose(applyMiddleware(...middleware), f => f));
|
27 | }
|
28 |
|
29 | if (module.hot) {
|
30 |
|
31 | module.hot.accept('reducers', () => {
|
32 | const nextReducer = require('../reducers');
|
33 |
|
34 | store.replaceReducer(nextReducer);
|
35 | });
|
36 | }
|
37 |
|
38 | return store;
|
39 | }
|