2017-06-29 12:54:02 -06:00
|
|
|
import thunk from "redux-thunk";
|
2018-03-19 14:01:05 -06:00
|
|
|
import { applyMiddleware, compose } from "redux";
|
|
|
|
import { EnvName, ReduxAction } from "./interfaces";
|
2017-12-27 10:19:15 -07:00
|
|
|
import { Actions } from "../constants";
|
2018-01-15 10:50:44 -07:00
|
|
|
import { stateFetchMiddlewareConfig } from "./state_fetch_middleware";
|
2018-01-23 13:57:37 -07:00
|
|
|
import { revertToEnglishMiddleware } from "./revert_to_english_middleware";
|
2018-03-19 13:06:31 -06:00
|
|
|
import { versionChangeMiddleware } from "./version_tracker_middleware";
|
2018-03-19 14:01:05 -06:00
|
|
|
import { Everything } from "../interfaces";
|
|
|
|
import { Middleware } from "redux";
|
|
|
|
import { Store } from "redux";
|
2018-04-06 13:26:55 -06:00
|
|
|
import { refilterLogsMiddleware } from "./refilter_logs_middleware";
|
2018-03-19 14:01:05 -06:00
|
|
|
|
|
|
|
export interface MW extends Middleware {
|
|
|
|
(store: Store<Everything>):
|
|
|
|
(dispatch: Function) =>
|
|
|
|
(action: ReduxAction<object>) => void;
|
|
|
|
}
|
2017-06-29 12:54:02 -06:00
|
|
|
|
2018-03-23 09:44:06 -06:00
|
|
|
export interface MiddlewareConfig { fn: MW; env: EnvName; }
|
2017-06-29 12:54:02 -06:00
|
|
|
|
|
|
|
/** To make it easier to manage all things watching the state tree,
|
|
|
|
* we keep subscriber functions in this array. */
|
2019-12-10 12:53:20 -07:00
|
|
|
export const mwConfig: MiddlewareConfig[] = [
|
2018-01-15 10:34:21 -07:00
|
|
|
{ env: "*", fn: thunk },
|
|
|
|
{ env: "development", fn: require("redux-immutable-state-invariant").default() },
|
2018-01-23 13:22:12 -07:00
|
|
|
stateFetchMiddlewareConfig,
|
2018-03-19 13:06:31 -06:00
|
|
|
revertToEnglishMiddleware,
|
2018-04-06 13:26:55 -06:00
|
|
|
versionChangeMiddleware,
|
|
|
|
refilterLogsMiddleware
|
2017-06-29 12:54:02 -06:00
|
|
|
];
|
|
|
|
|
|
|
|
export function getMiddleware(env: EnvName) {
|
2017-08-28 05:49:13 -06:00
|
|
|
const middlewareFns = mwConfig
|
2017-06-29 12:54:02 -06:00
|
|
|
.filter(function (mwc) { return (mwc.env === env) || (mwc.env === "*"); })
|
|
|
|
.map((mwc) => mwc.fn);
|
2018-08-08 08:44:12 -06:00
|
|
|
// tslint:disable-next-line:no-any
|
2017-12-27 10:19:15 -07:00
|
|
|
const wow = (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__;
|
|
|
|
const dtCompose = wow && wow({
|
|
|
|
actionsBlacklist: [
|
|
|
|
Actions.NETWORK_EDGE_CHANGE,
|
2019-10-07 14:26:09 -06:00
|
|
|
Actions.PING_NO,
|
|
|
|
Actions.PING_OK,
|
|
|
|
Actions.PING_START,
|
2017-12-27 10:19:15 -07:00
|
|
|
Actions.RESOURCE_READY
|
|
|
|
]
|
|
|
|
});
|
2017-06-29 12:54:02 -06:00
|
|
|
const composeEnhancers = dtCompose || compose;
|
2018-01-15 10:34:21 -07:00
|
|
|
const middleware = applyMiddleware(...middlewareFns);
|
2017-06-29 12:54:02 -06:00
|
|
|
|
2018-01-15 10:34:21 -07:00
|
|
|
return composeEnhancers(middleware);
|
2017-06-29 12:54:02 -06:00
|
|
|
}
|