Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
fix(md-tooltip): removed watcher for performance
Browse files Browse the repository at this point in the history
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 #4033
  • Loading branch information
clshortfuse committed Sep 2, 2015
1 parent 32ab2eb commit 637979f
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/components/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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();
});
}
}
}
Expand All @@ -198,6 +206,7 @@ function MdTooltipDirective($timeout, $window, $$rAF, $document, $mdUtil, $mdThe
if ( hasComputedStyleValue('display','none') ) {
scope.visible = false;
element.detach();
checkVisibility();
return;
}

Expand Down

1 comment on commit 637979f

@clshortfuse
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I've checked the logic and you don't need to call $mdUtil.nextTick(checkVisibility) at any point. The new function is always called by angular, not by dom events.

Please sign in to comment.