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

perf(select): Execute render after $digest cycle #8825

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/ng/directive/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
optionsExp = attr.ngOptions,
nullOption = false, // if false, user will not be able to select it (used by ngOptions)
emptyOption,
renderScheduled = false,
// we can't just jqLite('<option>') since jqLite is not smart enough
// to create it in <select> and IE barfs otherwise.
optionTemplate = jqLite(document.createElement('option')),
Expand Down Expand Up @@ -413,9 +414,19 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {

ctrl.$render = render;

scope.$watchCollection(valuesFn, render);
scope.$watchCollection(valuesFn, function () {
if (!renderScheduled) {
scope.$$postDigest(render);
renderScheduled = true;
}
});
if ( multiple ) {
scope.$watchCollection(function() { return ctrl.$modelValue; }, render);
scope.$watchCollection(function() { return ctrl.$modelValue; }, function () {
if (!renderScheduled) {
scope.$$postDigest(render);
renderScheduled = true;
}
});
}

function getSelectedSet() {
Expand Down Expand Up @@ -604,6 +615,8 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
while(optionGroupsCache.length > groupIndex) {
optionGroupsCache.pop()[0].element.remove();
}

renderScheduled = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be the first thing in the render method in case an exception is thrown in the body

}
}
}
Expand Down