fleet/frontend/redux/store.js

43 lines
1.2 KiB
JavaScript
Raw Normal View History

import Es6ObjectAssign from 'es6-object-assign';
import Es6Promise from 'es6-promise';
import { applyMiddleware, compose, createStore } from 'redux';
2016-09-07 00:04:02 +00:00
import { browserHistory } from 'react-router';
import { loadingBarMiddleware } from 'react-redux-loading-bar';
2016-09-07 00:04:02 +00:00
import { routerMiddleware } from 'react-router-redux';
import thunkMiddleware from 'redux-thunk';
import authMiddleware from './middlewares/auth';
import nagMessageMiddleware from './middlewares/nag_message';
2017-02-06 15:04:20 +00:00
import redirectMiddleware from './middlewares/redirect';
2016-09-07 00:04:02 +00:00
import reducers from './reducers';
// ie polyfills
Es6ObjectAssign.polyfill();
Es6Promise.polyfill();
2016-09-07 00:04:02 +00:00
const initialState = {};
const appliedMiddleware = applyMiddleware(
2016-09-07 00:04:02 +00:00
thunkMiddleware,
routerMiddleware(browserHistory),
authMiddleware,
nagMessageMiddleware,
2017-02-06 15:04:20 +00:00
redirectMiddleware,
loadingBarMiddleware({
promiseTypeSuffixes: ['REQUEST', 'SUCCESS', 'FAILURE'],
}),
);
2016-09-07 00:04:02 +00:00
2016-11-18 14:04:17 +00:00
const composeEnhancers = process.env.NODE_ENV !== 'production' &&
typeof global.window === 'object' &&
global.window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ?
global.window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ : compose;
2016-09-07 00:04:02 +00:00
const store = createStore(
reducers,
initialState,
2016-11-18 14:04:17 +00:00
composeEnhancers(appliedMiddleware),
2016-09-07 00:04:02 +00:00
);
2016-09-07 00:04:02 +00:00
export default store;