Skip to content
This repository has been archived by the owner on Oct 2, 2019. It is now read-only.

Commit

Permalink
feat(perf): optimize width resizing
Browse files Browse the repository at this point in the history
- Optimize running dynamic width calculations when resizing
  • Loading branch information
wesleycho authored and user378230 committed Apr 4, 2016
1 parent 6dfe407 commit d78ba5f
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/uiSelectController.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ uis.controller('uiSelectCtrl',
};

var sizeWatch = null;
var updaterScheduled = false;
ctrl.sizeSearchInput = function() {

var input = ctrl.searchInput[0],
Expand All @@ -465,10 +466,16 @@ uis.controller('uiSelectCtrl',
ctrl.searchInput.css('width', '10px');
$timeout(function() { //Give tags time to render correctly
if (sizeWatch === null && !updateIfVisible(calculateContainerWidth())) {
sizeWatch = $scope.$watch(calculateContainerWidth, function(containerWidth) {
if (updateIfVisible(containerWidth)) {
sizeWatch();
sizeWatch = null;
sizeWatch = $scope.$watch(angular.noop, function() {
if (!updaterScheduled) {
updaterScheduled = true;
$scope.$$postDigest(function() {
updaterScheduled = false;
if (updateIfVisible(calculateContainerWidth())) {
sizeWatch();
sizeWatch = null;
}
});
}
});
}
Expand Down

1 comment on commit d78ba5f

@kavika-1
Copy link

Choose a reason for hiding this comment

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

@wesleycho looks like this fix would help fix #845 (as well as several other related bugs with ng-show) if you could change one line:

sizeWatch = $scope.$watch(angular.noop, function()
to
sizeWatch = $scope.$watch(function()

This way it will try on every $digest until visible (updateIfVisible). Right now, as coded, the $watch never gets triggered again, since the watchExpression never changes (noop). This does fix it for a case we are investigating. Thanks for your consideration.

Please sign in to comment.