2017-12-13 11:01:37 +00:00
|
|
|
/* @flow */
|
2018-07-30 10:52:13 +00:00
|
|
|
|
2018-04-16 21:19:50 +00:00
|
|
|
import { createStore, applyMiddleware, compose } from 'redux';
|
2018-12-18 13:33:01 +00:00
|
|
|
import { routerMiddleware } from 'connected-react-router';
|
2018-04-16 21:19:50 +00:00
|
|
|
import thunk from 'redux-thunk';
|
|
|
|
import createHistory from 'history/createHashHistory';
|
2018-09-12 14:59:31 +00:00
|
|
|
import { createLogger } from 'redux-logger';
|
2018-12-18 13:33:01 +00:00
|
|
|
import createRootReducer from 'reducers';
|
2018-08-14 13:18:16 +00:00
|
|
|
import services from 'services';
|
2018-05-11 19:01:43 +00:00
|
|
|
|
|
|
|
import Raven from 'raven-js';
|
2018-04-16 21:19:50 +00:00
|
|
|
import RavenMiddleware from 'redux-raven-middleware';
|
2018-10-11 16:04:25 +00:00
|
|
|
import * as buildUtils from 'utils/build';
|
2018-04-16 21:19:50 +00:00
|
|
|
|
2018-10-09 13:20:57 +00:00
|
|
|
import type { Action, GetState } from 'flowtype';
|
2018-04-16 21:19:50 +00:00
|
|
|
|
2018-07-30 10:52:13 +00:00
|
|
|
export const history: History = createHistory({ queryKey: false });
|
2018-04-16 21:19:50 +00:00
|
|
|
|
|
|
|
const initialState: any = {};
|
|
|
|
const enhancers = [];
|
2018-09-19 14:55:09 +00:00
|
|
|
|
|
|
|
const middlewares = [
|
2018-04-16 21:19:50 +00:00
|
|
|
thunk,
|
2018-07-30 10:52:13 +00:00
|
|
|
routerMiddleware(history),
|
2018-04-16 21:19:50 +00:00
|
|
|
];
|
|
|
|
|
2018-10-11 16:04:25 +00:00
|
|
|
// sentry io middleware only in dev and beta build
|
|
|
|
if (buildUtils.isDev() || buildUtils.isBeta()) {
|
2018-09-19 14:55:09 +00:00
|
|
|
const RAVEN_KEY = 'https://34b8c09deb6c4cd2a4dc3f0029cd02d8@sentry.io/1279550';
|
|
|
|
const ravenMiddleware = RavenMiddleware(RAVEN_KEY);
|
|
|
|
Raven.config(RAVEN_KEY).install();
|
|
|
|
middlewares.push(ravenMiddleware);
|
|
|
|
}
|
2018-04-16 21:19:50 +00:00
|
|
|
|
2018-05-05 11:52:03 +00:00
|
|
|
let composedEnhancers: any;
|
2018-10-11 16:04:25 +00:00
|
|
|
if (buildUtils.isDev()) {
|
2018-09-12 14:59:31 +00:00
|
|
|
const excludeLogger = (getState: GetState, action: Action): boolean => {
|
|
|
|
//'@@router/LOCATION_CHANGE'
|
2018-09-14 10:20:39 +00:00
|
|
|
const excluded: Array<?string> = ['LOG_TO_EXCLUDE', 'log__add', undefined];
|
|
|
|
const pass: Array<?string> = excluded.filter(act => action.type === act);
|
2018-09-12 14:59:31 +00:00
|
|
|
return pass.length === 0;
|
|
|
|
};
|
2018-07-30 10:52:13 +00:00
|
|
|
|
2018-09-03 15:47:15 +00:00
|
|
|
const logger = createLogger({
|
|
|
|
level: 'info',
|
|
|
|
predicate: excludeLogger,
|
|
|
|
collapsed: true,
|
|
|
|
});
|
|
|
|
|
2018-12-18 09:53:11 +00:00
|
|
|
/* eslint-disable no-underscore-dangle */
|
|
|
|
if (window && typeof window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ === 'function') {
|
|
|
|
enhancers.push(window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__());
|
2018-09-03 15:47:15 +00:00
|
|
|
}
|
2018-12-18 09:53:11 +00:00
|
|
|
/* eslint-enable */
|
2018-09-03 15:47:15 +00:00
|
|
|
|
2018-05-05 11:52:03 +00:00
|
|
|
composedEnhancers = compose(
|
2018-09-19 14:55:09 +00:00
|
|
|
applyMiddleware(logger, ...middlewares, ...services),
|
2018-07-30 10:52:13 +00:00
|
|
|
...enhancers,
|
2018-05-05 11:52:03 +00:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
composedEnhancers = compose(
|
2018-09-19 14:55:09 +00:00
|
|
|
applyMiddleware(...middlewares, ...services),
|
2018-07-30 10:52:13 +00:00
|
|
|
...enhancers,
|
2018-05-05 11:52:03 +00:00
|
|
|
);
|
|
|
|
}
|
2018-04-16 21:19:50 +00:00
|
|
|
|
|
|
|
export default createStore(
|
2018-12-18 13:33:01 +00:00
|
|
|
createRootReducer(history),
|
2018-04-16 21:19:50 +00:00
|
|
|
initialState,
|
2018-07-30 10:52:13 +00:00
|
|
|
composedEnhancers,
|
2018-04-16 21:19:50 +00:00
|
|
|
);
|