From c21f2100dd59b944c77073a5b39e3c6d87ba941e Mon Sep 17 00:00:00 2001 From: james hadfield Date: Tue, 29 Oct 2024 09:31:50 +1300 Subject: [PATCH] Implement performance flags structure Performance flags (reduxState.controls.performanceFlags) represent flags for which we enable/disable certain functionality in Auspice. These flags shouldn't be depended on, i.e. Auspice should work just fine without them (but may be a little slow). --- src/components/tree/index.ts | 3 ++- src/middleware/performanceFlags.js | 26 ++++++++++++++++++++++++++ src/reducers/controls.ts | 3 ++- src/store.ts | 2 ++ 4 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 src/middleware/performanceFlags.js diff --git a/src/components/tree/index.ts b/src/components/tree/index.ts index 07218e725..9f0cc1d2c 100644 --- a/src/components/tree/index.ts +++ b/src/components/tree/index.ts @@ -30,7 +30,8 @@ const Tree = connect((state: RootState) => ({ tipLabelKey: state.controls.tipLabelKey, narrativeMode: state.narrative.display, animationPlayPauseButton: state.controls.animationPlayPauseButton, - showOnlyPanels: state.controls.showOnlyPanels + showOnlyPanels: state.controls.showOnlyPanels, + performanceFlags: state.controls.performanceFlags, }))(UnconnectedTree); export default Tree; diff --git a/src/middleware/performanceFlags.js b/src/middleware/performanceFlags.js new file mode 100644 index 000000000..958fc65c7 --- /dev/null +++ b/src/middleware/performanceFlags.js @@ -0,0 +1,26 @@ +import * as types from "../actions/types"; + +/** + * Performance toggles (reduxState.controls.performanceFlags) represent flags + * for which we enable/disable certain functionality in Auspice. These flags + * shouldn't be depended on, i.e. Auspice should work just fine without them + * (but may be a little slow). + */ + + +export const performanceFlags = (_store) => (next) => (action) => { + let modifiedAction; + switch (action.type) { + case types.URL_QUERY_CHANGE_WITH_COMPUTED_STATE: /* fallthrough */ + case types.CLEAN_START: { + modifiedAction = {...action}; + modifiedAction.controls.performanceFlags = calculate() + } + } + return next(modifiedAction || action); // send action to other middleware / reducers +}; + +function calculate() { + const toggles = new Map(); + return toggles; +} \ No newline at end of file diff --git a/src/reducers/controls.ts b/src/reducers/controls.ts index 5dc967b11..5290c2440 100644 --- a/src/reducers/controls.ts +++ b/src/reducers/controls.ts @@ -137,7 +137,8 @@ export const getDefaultControlsState = () => { measurementsDisplay: undefined, measurementsShowOverallMean: undefined, measurementsShowThreshold: undefined, - measurementsFilters: {} + measurementsFilters: {}, + performanceFlags: new Map(), }; }; diff --git a/src/store.ts b/src/store.ts index 4943b23ae..d68e74d09 100644 --- a/src/store.ts +++ b/src/store.ts @@ -3,10 +3,12 @@ import { changeURLMiddleware } from "./middleware/changeURL"; import rootReducer from "./reducers"; // import { loggingMiddleware } from "./middleware/logActions"; import { keepScatterplotStateInSync } from "./middleware/scatterplot"; +import { performanceFlags } from "./middleware/performanceFlags"; const middleware = [ keepScatterplotStateInSync, changeURLMiddleware, + performanceFlags, // loggingMiddleware ];