Skip to content

Commit

Permalink
Merge pull request #83 from igoroctaviano/fix/1733
Browse files Browse the repository at this point in the history
Add native debounce of onNewImage event
  • Loading branch information
JamesAPetts authored May 15, 2020
2 parents 9b7b64b + 669a501 commit 7474152
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/CornerstoneViewport/CornerstoneViewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import windowResizeHandler from './windowResizeHandler.js';
import cornerstone from 'cornerstone-core';
import cornerstoneTools from 'cornerstone-tools';
import ReactResizeDetector from 'react-resize-detector/lib/index.js';
import debounce from 'lodash.debounce';

// Util
import areStringArraysEqual from './../helpers/areStringArraysEqual.js';
Expand Down Expand Up @@ -49,6 +50,7 @@ class CornerstoneViewport extends Component {
//
setViewportActive: PropTypes.func, // Called when viewport should be set to active?
onNewImage: PropTypes.func,
onNewImageDebounceTime: PropTypes.number,
viewportOverlayComponent: PropTypes.oneOfType([
PropTypes.string,
PropTypes.func,
Expand Down Expand Up @@ -91,6 +93,7 @@ class CornerstoneViewport extends Component {
loadingIndicatorComponent: LoadingIndicator,
resizeThrottleMs: 200,
tools: [],
onNewImageDebounceTime: 0,
};

constructor(props) {
Expand Down Expand Up @@ -668,7 +671,7 @@ class CornerstoneViewport extends Component {
});
};

onNewImage = event => {
onNewImage = debounce(event => {
const { imageId } = event.detail.image;
const { sopInstanceUid } =
cornerstone.metaData.get('generalImageModule', imageId) || {};
Expand All @@ -686,7 +689,7 @@ class CornerstoneViewport extends Component {
sopInstanceUid,
});
}
};
}, this.props.onNewImageDebounceTime);

onImageLoaded = () => {
// TODO: This is not necessarily true :thinking:
Expand Down

0 comments on commit 7474152

Please sign in to comment.