configureStore.js
1.3 KB
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
import thunk from 'redux-thunk';
// import logger from 'redux-logger'
import rootReducer from './reducers';
import {
applyMiddleware,
compose,
createStore
} from 'redux';
export default function configureStore(initialState) {
let createStoreWithMiddleware;
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const middleware = applyMiddleware(thunk
// , logger
);
if (__DEBUG__) {
if (window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) {
createStoreWithMiddleware = composeEnhancers(
middleware
);
}
} else {
createStoreWithMiddleware = compose(middleware);
}
const store = createStoreWithMiddleware(createStore)(
rootReducer, initialState,
// dev-tools的另外一种调用方法,前提是在自己的浏览器中安装了扩展 redux-devtools
// 1、 添加下边语句
/* 2、将该文件的17行内容 'require('./../containers/devtools/DevTools').instrument()' 注释掉
原因是不允许调用生成调试工具两次
*/
// window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
);
if (module.hot) {
module.hot.accept('./reducers', () => {
const nextRootReducer = require('./reducers');
store.replaceReducer(nextRootReducer);
});
}
return store;
}