Skip to content
This repository has been 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

Conversation

wesleycho
Copy link
Contributor

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.

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.
@@ -413,9 +413,17 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {

ctrl.$render = render;

scope.$watchCollection(valuesFn, render);
scope.$watchCollection(valuesFn, function () {
if (scope.$$postDigestQueue.indexOf(render) === -1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of doing indexOf you could just have a internal boolean flag renderScheduled and set it to true when you schedule via postDigest and in postDigest reset it to false.

Add reset of toggle
@@ -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

@IgorMinar IgorMinar closed this in 6f7018d Aug 29, 2014
@IgorMinar
Copy link
Contributor

thanks

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants