-
Notifications
You must be signed in to change notification settings - Fork 194
/
configureStore.js
58 lines (49 loc) · 1.92 KB
/
configureStore.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* global __DEVELOPMENT__ __USE_GA__ __DEVTOOLS__ */
/* eslint global-require: 0 */
import { compose, createStore, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import DevTools from '../pages/DevTools';
import reducers from '../state';
import sagas from '../sagas';
import { routerMiddleware } from 'react-router-redux';
import { socketIoMiddleware } from '../middlewares/socketio';
import createSagaMiddleware from 'redux-saga';
export default function configureStore(initialState = {}, browserHistory) {
const middlewares = [];
const sagaMiddleware = createSagaMiddleware();
middlewares.push(thunk);
middlewares.push(routerMiddleware(browserHistory));
middlewares.push(socketIoMiddleware);
middlewares.push(sagaMiddleware);
if (__DEVELOPMENT__) {
const createLogger = require('redux-logger');
const logger = createLogger({ predicate:
(getState, action) => action.type !== 'EFFECT_TRIGGERED' &&
action.type !== 'EFFECT_RESOLVED' });
middlewares.push(logger);
}
if (__USE_GA__) {
const { googleAnalyticsMiddleware } = require('../middlewares/ga');
middlewares.push(googleAnalyticsMiddleware);
}
let createStoreWithMiddleware = applyMiddleware(...middlewares);
if (__DEVTOOLS__) {
createStoreWithMiddleware = compose(
createStoreWithMiddleware,
DevTools.instrument()
);
}
const finalCreateStore = createStoreWithMiddleware(createStore);
const store = finalCreateStore(reducers, initialState);
sagaMiddleware.run(sagas);
if (__DEVELOPMENT__) {
if (module.hot) {
// Enable Webpack hot module replacement for reducers
module.hot.accept('../state', () => {
const nextReducer = require('../state');
store.replaceReducer(nextReducer);
});
}
}
return store;
}