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

perf(*): don't trigger digests after enter/leave of structural directives #15345

Merged
merged 2 commits into from
Nov 23, 2016
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/ng/directive/ngIf.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ var ngIfDirective = ['$animate', '$compile', function($animate, $compile) {
}
if (block) {
previousElements = getBlockNodes(block.clone);
$animate.leave(previousElements).then(function() {
previousElements = null;
$animate.leave(previousElements).done(function(response) {
if (response !== false) previousElements = null;
});
block = null;
}
Expand Down
13 changes: 7 additions & 6 deletions src/ng/directive/ngInclude.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,18 +214,19 @@ var ngIncludeDirective = ['$templateRequest', '$anchorScroll', '$animate',
currentScope = null;
}
if (currentElement) {
$animate.leave(currentElement).then(function() {
previousElement = null;
$animate.leave(currentElement).done(function(response) {
if (response !== false) previousElement = null;
});
previousElement = currentElement;
currentElement = null;
}
};

scope.$watch(srcExp, function ngIncludeWatchAction(src) {
var afterAnimation = function() {
if (isDefined(autoScrollExp) && (!autoScrollExp || scope.$eval(autoScrollExp))) {
$anchorScroll();
var afterAnimation = function(response) {
if (response !== false && isDefined(autoScrollExp) &&
(!autoScrollExp || scope.$eval(autoScrollExp))) {
$anchorScroll();
}
};
var thisChangeId = ++changeCounter;
Expand All @@ -248,7 +249,7 @@ var ngIncludeDirective = ['$templateRequest', '$anchorScroll', '$animate',
// directives to non existing elements.
var clone = $transclude(newScope, function(clone) {
cleanupLastIncludeContent();
$animate.enter(clone, null, $element).then(afterAnimation);
$animate.enter(clone, null, $element).done(afterAnimation);
});

currentScope = newScope;
Expand Down
15 changes: 9 additions & 6 deletions src/ng/directive/ngSwitch.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,21 +153,24 @@ var ngSwitchDirective = ['$animate', '$compile', function($animate, $compile) {
selectedScopes = [];

var spliceFactory = function(array, index) {
return function() { array.splice(index, 1); };
return function(response) {
if (response !== false) array.splice(index, 1);
};
};

scope.$watch(watchExpr, function ngSwitchWatchAction(value) {
var i, ii;
for (i = 0, ii = previousLeaveAnimations.length; i < ii; ++i) {
$animate.cancel(previousLeaveAnimations[i]);

// Start with the last, in case the array is modified during the loop
while (previousLeaveAnimations.length) {
$animate.cancel(previousLeaveAnimations.pop());
}
previousLeaveAnimations.length = 0;

for (i = 0, ii = selectedScopes.length; i < ii; ++i) {
var selected = getBlockNodes(selectedElements[i].clone);
selectedScopes[i].$destroy();
var promise = previousLeaveAnimations[i] = $animate.leave(selected);
promise.then(spliceFactory(previousLeaveAnimations, i));
var runner = previousLeaveAnimations[i] = $animate.leave(selected);
runner.done(spliceFactory(previousLeaveAnimations, i));
}

selectedElements.length = 0;
Expand Down
8 changes: 4 additions & 4 deletions src/ngRoute/directive/ngView.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ function ngViewFactory($route, $anchorScroll, $animate) {
}
if (currentElement) {
previousLeaveAnimation = $animate.leave(currentElement);
previousLeaveAnimation.then(function() {
previousLeaveAnimation = null;
previousLeaveAnimation.done(function(response) {
if (response !== false) previousLeaveAnimation = null;
});
currentElement = null;
}
Expand All @@ -229,8 +229,8 @@ function ngViewFactory($route, $anchorScroll, $animate) {
// function is called before linking the content, which would apply child
// directives to non existing elements.
var clone = $transclude(newScope, function(clone) {
$animate.enter(clone, null, currentElement || $element).then(function onNgViewEnter() {
if (angular.isDefined(autoScrollExp)
$animate.enter(clone, null, currentElement || $element).done(function onNgViewEnter(response) {
if (response !== false && angular.isDefined(autoScrollExp)
&& (!autoScrollExp || scope.$eval(autoScrollExp))) {
$anchorScroll();
}
Expand Down
Loading