Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 8391fbf

Browse files
committed
perf(select): Execute render after $digest cycle
This is an optimization to defer execution of the render function in the select directive after the $digest cycle completes inside the $watchCollection expressions. This does a check to see if the render function is already registered in the $$postDigestQueue before it passes it into $$postDigest, guaranteeing that the DOM manipulation happens only in one execution after the model settles.
1 parent cb73a37 commit 8391fbf

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/ng/directive/select.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,17 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
413413

414414
ctrl.$render = render;
415415

416-
scope.$watchCollection(valuesFn, render);
416+
scope.$watchCollection(valuesFn, function () {
417+
if (scope.$$postDigestQueue.indexOf(render) === -1) {
418+
scope.$$postDigest(render);
419+
}
420+
});
417421
if ( multiple ) {
418-
scope.$watchCollection(function() { return ctrl.$modelValue; }, render);
422+
scope.$watchCollection(function() { return ctrl.$modelValue; }, function () {
423+
if (scope.$$postDigestQueue.indexOf(render) === -1) {
424+
scope.$$postDigest(render);
425+
}
426+
});
419427
}
420428

421429
function getSelectedSet() {

0 commit comments

Comments
 (0)