From 48cf4edbb312d9aa5a4050501c98550a540ac8b1 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 3 Sep 2014 22:35:59 +0200 Subject: [PATCH] Remove event attaching from watcher handler. Events should be attached once, and having event attaching code within some watcher can cause big memory leaks attaching same handlers more that one time. --- app/coffee/modules/taskboard/charts.coffee | 24 ++++++++++++---------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/app/coffee/modules/taskboard/charts.coffee b/app/coffee/modules/taskboard/charts.coffee index 002fbfde..872fe43e 100644 --- a/app/coffee/modules/taskboard/charts.coffee +++ b/app/coffee/modules/taskboard/charts.coffee @@ -87,18 +87,20 @@ SprintGraphDirective = -> link = ($scope, $el, $attrs) -> element = angular.element($el) + + $scope.$on "resize", -> + redrawChart(element, $scope.stats.days) + + $scope.$on "taskboard:graph:toggle-visibility", -> + $el.parent().toggleClass('open') + + # fix chart overflow + timeout(100, -> redrawChart(element, $scope.stats.days)) + $scope.$watch 'stats', (value) -> - if $scope.stats? - redrawChart(element, $scope.stats.days) - - $scope.$on "resize", -> - redrawChart(element, $scope.stats.days) - - $scope.$on "taskboard:graph:toggle-visibility", -> - $el.parent().toggleClass('open') - - # fix chart overflow - timeout(100, -> redrawChart(element, $scope.stats.days)) + if not $scope.stats? + return + redrawChart(element, $scope.stats.days) $scope.$on "$destroy", -> $el.off()