From 637979f133d4f5f8f9760d0a5f06c92cd45bfdef Mon Sep 17 00:00:00 2001 From: Carlos Lopez Date: Wed, 2 Sep 2015 15:01:02 -0400 Subject: [PATCH] fix(md-tooltip): removed watcher for performance md-tooltip uses a watcher per tooltip. The watcher is just to watch if scope.visible changes. This variable only changes internally so there's no reason to need a watcher when the changes could be tracked manually. fixes https://github.com/angular/material/issues/4033 --- src/components/tooltip/tooltip.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/components/tooltip/tooltip.js b/src/components/tooltip/tooltip.js index 389331dd705..ffb90df460b 100644 --- a/src/components/tooltip/tooltip.js +++ b/src/components/tooltip/tooltip.js @@ -84,11 +84,15 @@ function MdTooltipDirective($timeout, $window, $$rAF, $document, $mdUtil, $mdThe scope.visible = false; element.remove(); angular.element($window).off('resize', debouncedOnResize); + checkVisibility(); }); - scope.$watch('visible', function (isVisible) { - if (isVisible) showTooltip(); - else hideTooltip(); - }); + } + + function checkVisibility () { + if (scope.visible) + showTooltip(); + else + hideTooltip(); } function addAriaLabel () { @@ -181,9 +185,13 @@ function MdTooltipDirective($timeout, $window, $$rAF, $document, $mdUtil, $mdThe $timeout(function() { scope.visible = setVisible.value; setVisible.queued = false; + checkVisibility(); }, scope.delay); } else { - $mdUtil.nextTick(function() { scope.visible = false; }); + $mdUtil.nextTick(function() { + scope.visible = false; + checkVisibility(); + }); } } } @@ -198,6 +206,7 @@ function MdTooltipDirective($timeout, $window, $$rAF, $document, $mdUtil, $mdThe if ( hasComputedStyleValue('display','none') ) { scope.visible = false; element.detach(); + checkVisibility(); return; }