-
Notifications
You must be signed in to change notification settings - Fork 50
/
configureStore.js
executable file
·44 lines (38 loc) · 1.38 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
import { createStore, applyMiddleware, compose } from 'redux';
import thunk from 'redux-thunk';
import notify from 'redux-notify';
import rootReducer from '../reducers';
import notifyEvents from '../events/notifyEvents';
export default function configureStore(callback, isBg) {
let getState;
if (isBg === undefined) getState = require('./getStoredState'); /* If you don't want to persist states, use './getDefaultState' */// eslint-disable-line max-len
else getState = (isBg ? require('./getStateToBg') : require('./getStateFromBg'));
getState(initialState => {
let enhancer;
const middleware = [
thunk,
notify(notifyEvents, { noReverse: true })
];
if (process.env.NODE_ENV !== 'production') {
middleware.push(
require('redux-immutable-state-invariant')(),
require('redux-logger')({ level: 'info', collapsed: true })
);
enhancer = compose(
applyMiddleware(...middleware),
window.devToolsExtension ? window.devToolsExtension() : f => f
);
} else {
enhancer = applyMiddleware(...middleware);
}
const store = createStore(rootReducer, initialState, enhancer);
if (process.env.NODE_ENV !== 'production') {
if (module.hot) {
module.hot.accept('../reducers', () =>
store.replaceReducer(require('../reducers'))
);
}
}
return store;
}, callback);
}