From d82230dea438b17da167d97d23afdbd6420fd9b7 Mon Sep 17 00:00:00 2001 From: Pete Richards Date: Tue, 4 Jul 2017 17:03:25 -0700 Subject: [PATCH 1/2] [Resize] don't trigger callback when destroyed Prevent MCTResize from triggering a callback after it is destroyed. Fixes https://github.com/nasa/openmct/issues/1509 --- platform/commonUI/general/src/directives/MCTResize.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/platform/commonUI/general/src/directives/MCTResize.js b/platform/commonUI/general/src/directives/MCTResize.js index d16384620d..130f0ce9e2 100644 --- a/platform/commonUI/general/src/directives/MCTResize.js +++ b/platform/commonUI/general/src/directives/MCTResize.js @@ -83,13 +83,14 @@ define( // Callback to fire after each timeout; // update bounds and schedule another timeout function onInterval() { + if (!active) { + return; + } fireEval({ width: element[0].offsetWidth, height: element[0].offsetHeight }); - if (active) { - $timeout(onInterval, currentInterval(), false); - } + $timeout(onInterval, currentInterval(), false); } // Stop running in the background From 89515bb89696bbc4381d712cfdef828399ae6e47 Mon Sep 17 00:00:00 2001 From: Pete Richards Date: Wed, 5 Jul 2017 16:48:09 -0700 Subject: [PATCH 2/2] verify that eval isn't called after destroy --- platform/commonUI/general/test/directives/MCTResizeSpec.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/platform/commonUI/general/test/directives/MCTResizeSpec.js b/platform/commonUI/general/test/directives/MCTResizeSpec.js index 7945a4d814..0e89119e1c 100644 --- a/platform/commonUI/general/test/directives/MCTResizeSpec.js +++ b/platform/commonUI/general/test/directives/MCTResizeSpec.js @@ -102,11 +102,16 @@ define( // Broadcast a destroy event mockScope.$on.mostRecentCall.args[1](); + testElement.offsetWidth = 300; + testElement.offsetHeight = 350; + mockScope.$eval.reset(); + // Fire the timeout mockTimeout.mostRecentCall.args[0](); // Should NOT have scheduled another timeout expect(mockTimeout.calls.length).toEqual(2); + expect(mockScope.$eval).not.toHaveBeenCalled(); }); it("triggers a digest cycle when size changes", function () {