Skip to content

Commit 669a501

Browse files
committed
Add native debounce of onNewImage event
1 parent 9b7b64b commit 669a501

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/CornerstoneViewport/CornerstoneViewport.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import windowResizeHandler from './windowResizeHandler.js';
99
import cornerstone from 'cornerstone-core';
1010
import cornerstoneTools from 'cornerstone-tools';
1111
import ReactResizeDetector from 'react-resize-detector/lib/index.js';
12+
import debounce from 'lodash.debounce';
1213

1314
// Util
1415
import areStringArraysEqual from './../helpers/areStringArraysEqual.js';
@@ -49,6 +50,7 @@ class CornerstoneViewport extends Component {
4950
//
5051
setViewportActive: PropTypes.func, // Called when viewport should be set to active?
5152
onNewImage: PropTypes.func,
53+
onNewImageDebounceTime: PropTypes.number,
5254
viewportOverlayComponent: PropTypes.oneOfType([
5355
PropTypes.string,
5456
PropTypes.func,
@@ -91,6 +93,7 @@ class CornerstoneViewport extends Component {
9193
loadingIndicatorComponent: LoadingIndicator,
9294
resizeThrottleMs: 200,
9395
tools: [],
96+
onNewImageDebounceTime: 0,
9497
};
9598

9699
constructor(props) {
@@ -668,7 +671,7 @@ class CornerstoneViewport extends Component {
668671
});
669672
};
670673

671-
onNewImage = event => {
674+
onNewImage = debounce(event => {
672675
const { imageId } = event.detail.image;
673676
const { sopInstanceUid } =
674677
cornerstone.metaData.get('generalImageModule', imageId) || {};
@@ -686,7 +689,7 @@ class CornerstoneViewport extends Component {
686689
sopInstanceUid,
687690
});
688691
}
689-
};
692+
}, this.props.onNewImageDebounceTime);
690693

691694
onImageLoaded = () => {
692695
// TODO: This is not necessarily true :thinking:

0 commit comments

Comments
 (0)