2017-08-08 14:25:33 +08:00
|
|
|
import { createStore as _createStore, applyMiddleware, compose } from 'redux';
|
|
|
|
import thunkMiddleware from 'redux-thunk';
|
|
|
|
import promiseMiddleware from 'redux-promise';
|
|
|
|
import messageMiddleware from './middleware/messageMiddleware';
|
|
|
|
import reducer from './modules/reducer';
|
|
|
|
|
|
|
|
export default function createStore(initialState = {}) {
|
|
|
|
const middleware = [thunkMiddleware, promiseMiddleware, messageMiddleware];
|
|
|
|
|
|
|
|
let finalCreateStore;
|
2017-08-23 20:41:47 +08:00
|
|
|
if (process.env.NODE_ENV === 'production') {
|
|
|
|
finalCreateStore = applyMiddleware(...middleware)(_createStore);
|
|
|
|
} else {
|
2017-08-08 14:25:33 +08:00
|
|
|
finalCreateStore = compose(
|
|
|
|
applyMiddleware(...middleware),
|
2017-08-23 18:24:29 +08:00
|
|
|
window.devToolsExtension ? window.devToolsExtension() : require('../containers/DevTools/DevTools').instrument()
|
2017-08-08 14:25:33 +08:00
|
|
|
)(_createStore);
|
|
|
|
}
|
|
|
|
|
|
|
|
const store = finalCreateStore(reducer, initialState);
|
|
|
|
|
|
|
|
return store;
|
|
|
|
}
|