From 211179bdae64bbef784229f2055e06dbcf8e3e2d Mon Sep 17 00:00:00 2001 From: Forrest Li Date: Mon, 28 Oct 2019 16:14:11 -0400 Subject: [PATCH] fix(ImageCroppingWidget): Missing unsubscribe call --- .../Widgets/Widgets3D/ImageCroppingWidget/index.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Sources/Widgets/Widgets3D/ImageCroppingWidget/index.js b/Sources/Widgets/Widgets3D/ImageCroppingWidget/index.js index f275ec08a5b..0c0a6ea7246 100644 --- a/Sources/Widgets/Widgets3D/ImageCroppingWidget/index.js +++ b/Sources/Widgets/Widgets3D/ImageCroppingWidget/index.js @@ -24,6 +24,8 @@ import { ViewTypes } from 'vtk.js/Sources/Widgets/Core/WidgetManager/Constants'; function vtkImageCroppingWidget(publicAPI, model) { model.classHierarchy.push('vtkImageCroppingWidget'); + let stateSub = null; + // -------------------------------------------------------------------------- function setHandlesEnabled(label, flag) { @@ -87,6 +89,14 @@ function vtkImageCroppingWidget(publicAPI, model) { } }; + // -------------------------------------------------------------------------- + + publicAPI.delete = macro.chain(publicAPI.delete, () => { + if (stateSub) { + stateSub.unsubscribe(); + } + }); + // --- Widget Requirement --------------------------------------------------- model.behavior = behavior; @@ -117,7 +127,9 @@ function vtkImageCroppingWidget(publicAPI, model) { }; // Update handle positions when cropping planes update - model.widgetState.getCroppingPlanes().onModified(publicAPI.updateHandles); + stateSub = model.widgetState + .getCroppingPlanes() + .onModified(publicAPI.updateHandles); // Add manipulators to our widgets. const planeManipulator = vtkPlaneManipulator.newInstance();