From a9f7cc9658c7b8777a0b142f04db266d0c82e413 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Mon, 26 Jan 2015 17:48:33 -0800 Subject: [PATCH] [Performance] Deactive mct-resize on destroy Deactive mct-resize when its containing scope is destroyed; that is, don't go on polling for size changes indefinitely. Issue discovered/addressed in the context of investigating sluggishness of plotting in WTD-717. --- .../commonUI/general/src/directives/MCTResize.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/platform/commonUI/general/src/directives/MCTResize.js b/platform/commonUI/general/src/directives/MCTResize.js index 10e4256c50..9e6d5a29f1 100644 --- a/platform/commonUI/general/src/directives/MCTResize.js +++ b/platform/commonUI/general/src/directives/MCTResize.js @@ -35,7 +35,8 @@ define( // Link; start listening for changes to an element's size function link(scope, element, attrs) { - var lastBounds; + var lastBounds, + active = true; // Determine how long to wait before the next update function currentInterval() { @@ -62,9 +63,19 @@ define( width: element[0].offsetWidth, height: element[0].offsetHeight }); - $timeout(onInterval, currentInterval()); + if (active) { + $timeout(onInterval, currentInterval()); + } } + // Stop running in the background + function deactivate() { + active = false; + } + + // Unregister once out-of-scope + scope.$on("$destroy", deactivate); + // Handle the initial callback onInterval(); }