Farmbot-Web-App/frontend/redux/refilter_logs_middleware.ts

24 lines
888 B
TypeScript
Raw Normal View History

import { Actions } from "../constants";
2018-04-06 14:12:06 -06:00
import { Middleware } from "redux";
import { MiddlewareConfig } from "./middlewares";
2018-08-01 07:12:15 -06:00
import { ResourceName } from "farmbot";
2018-04-06 14:12:06 -06:00
import { throttledLogRefresh } from "./refresh_logs";
const WEB_APP_CONFIG: ResourceName = "WebAppConfig";
2018-04-06 14:19:22 -06:00
/**
* Middleware function that listens for changes on the `WebAppConfig` resource.
* If the resource does change, it will trigger a throttled refresh of all log
* resources, downloading the filtered log list as required from the API. */
// tslint:disable-next-line:no-any
2018-04-06 14:12:06 -06:00
export const fn: Middleware = () => (dispatch) => (action: any) => {
2020-01-03 13:04:45 -07:00
const needsRefresh = action?.payload?.kind === WEB_APP_CONFIG
&& action.type === Actions.SAVE_RESOURCE_OK;
2018-04-06 14:12:06 -06:00
needsRefresh && throttledLogRefresh(dispatch);
return dispatch(action);
};
export const refilterLogsMiddleware: MiddlewareConfig = { fn, env: "*" };