From c455253c0ec33054bf0e06dabb3df893f50b4a9f Mon Sep 17 00:00:00 2001 From: David Wire Date: Wed, 31 Jul 2019 00:46:41 -0600 Subject: [PATCH] fix(ConnectedCornerstoneViewport): Fix definition of function map so it happens less frequently (#740) `onMeasurementsChanged` currently defines a function map every time it is called. This function map includes a throttle on the `modified` function which is not being used because the function is called at most once per time it is instantiated. These changes elevate the map definition to the file level, since what it is defining does not change based on the other executed code. --- .../src/ConnectedCornerstoneViewport.js | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/extensions/ohif-cornerstone-extension/src/ConnectedCornerstoneViewport.js b/extensions/ohif-cornerstone-extension/src/ConnectedCornerstoneViewport.js index 7f1979998..f0d775047 100644 --- a/extensions/ohif-cornerstone-extension/src/ConnectedCornerstoneViewport.js +++ b/extensions/ohif-cornerstone-extension/src/ConnectedCornerstoneViewport.js @@ -4,6 +4,21 @@ import { connect } from 'react-redux'; import throttle from 'lodash.throttle'; const { setViewportActive, setViewportSpecificData } = OHIF.redux.actions; +const { + onAdded, + onRemoved, + onModified, +} = OHIF.measurements.MeasurementHandlers; + +// TODO: Transition to enums for the action names so that we can ensure they stay up to date +// everywhere they're used. +const MEASUREMENT_ACTION_MAP = { + 'added': onAdded, + 'removed': onRemoved, + 'modified': throttle(event => { + return onModified(event); + }, 300), +} const mapStateToProps = (state, ownProps) => { let dataFromStore; @@ -71,20 +86,7 @@ const mapDispatchToProps = (dispatch, ownProps) => { }, onMeasurementsChanged: (event, action) => { - const { - onAdded, - onRemoved, - onModified, - } = OHIF.measurements.MeasurementHandlers; - const actions = { - added: onAdded, - removed: onRemoved, - modified: throttle(event => { - return onModified(event); - }, 300), - }; - - return actions[action](event); + return MEASUREMENT_ACTION_MAP[action](event); }, }; };