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

Commit d78ba5f

Browse files
wesleychouser378230
authored andcommittedApr 4, 2016
feat(perf): optimize width resizing
- Optimize running dynamic width calculations when resizing
1 parent 6dfe407 commit d78ba5f

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed
 

‎src/uiSelectController.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ uis.controller('uiSelectCtrl',
444444
};
445445

446446
var sizeWatch = null;
447+
var updaterScheduled = false;
447448
ctrl.sizeSearchInput = function() {
448449

449450
var input = ctrl.searchInput[0],
@@ -465,10 +466,16 @@ uis.controller('uiSelectCtrl',
465466
ctrl.searchInput.css('width', '10px');
466467
$timeout(function() { //Give tags time to render correctly
467468
if (sizeWatch === null && !updateIfVisible(calculateContainerWidth())) {
468-
sizeWatch = $scope.$watch(calculateContainerWidth, function(containerWidth) {
469-
if (updateIfVisible(containerWidth)) {
470-
sizeWatch();
471-
sizeWatch = null;
469+
sizeWatch = $scope.$watch(angular.noop, function() {
470+
if (!updaterScheduled) {
471+
updaterScheduled = true;
472+
$scope.$$postDigest(function() {
473+
updaterScheduled = false;
474+
if (updateIfVisible(calculateContainerWidth())) {
475+
sizeWatch();
476+
sizeWatch = null;
477+
}
478+
});
472479
}
473480
});
474481
}

1 commit comments

Comments
 (1)

kavika-1 commented on May 20, 2016

@kavika-1

@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.

This repository has been archived.