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

Commit 5068ca1

Browse files
committed
perf(ngAnimate): speed up areAnimationsAllowed check
This commit speeds up the code that checks if an element can be animated, for the following two cases: The checks will be sped up in cases where the animation is disabled via $animate.enabled(element, false) on any parent element. A minor speed-up is also included for cases where the $rootElement of the app (the bootstrap element) is on the body or lower in the DOM tree.
1 parent 4ee5db2 commit 5068ca1

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/ngAnimate/animateQueue.js

+18-3
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,13 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
571571
return getDomNode(nodeOrElmA) === getDomNode(nodeOrElmB);
572572
}
573573

574+
/**
575+
* This fn returns false if any of the following is true:
576+
* a) animations on any parent element are disabled, and animations on the element aren't explicitly allowed
577+
* b) a parent element has an ongoing structural animation, and animateChildren is false
578+
* c) the element is not a child of the body
579+
* d) the element is not a child of the $rootElement
580+
*/
574581
function areAnimationsAllowed(element, parentElement, event) {
575582
var bodyElement = jqLite($document[0].body);
576583
var bodyElementDetected = isMatchingElement(element, bodyElement) || element[0].nodeName === 'HTML';
@@ -604,10 +611,12 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
604611
if (!parentAnimationDetected) {
605612
var parentElementDisabled = disabledElementsLookup.get(parentNode);
606613

607-
// disable animations if the user hasn't explicitly enabled animations on the
608-
// current element
609614
if (parentElementDisabled === true && elementDisabled !== false) {
615+
// disable animations if the user hasn't explicitly enabled animations on the
616+
// current element
610617
elementDisabled = true;
618+
// element is disabled via parent element, no need to check anything else
619+
break;
611620
} else if (parentElementDisabled === false) {
612621
elementDisabled = false;
613622
}
@@ -625,11 +634,17 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
625634
if (parentAnimationDetected && animateChildren === false) break;
626635

627636
if (!bodyElementDetected) {
628-
// we also need to ensure that the element is or will be apart of the body element
637+
// we also need to ensure that the element is or will be a part of the body element
629638
// otherwise it is pointless to even issue an animation to be rendered
630639
bodyElementDetected = isMatchingElement(parentElement, bodyElement);
631640
}
632641

642+
if (bodyElementDetected && rootElementDetected) {
643+
// If both body and root have been found, any other checks are pointless,
644+
// as no animation data should live outside the application
645+
break;
646+
}
647+
633648
if (!rootElementDetected) {
634649
// If no rootElement is detected, check if the parentElement is pinned to another element
635650
parentHost = parentElement.data(NG_ANIMATE_PIN_DATA);

0 commit comments

Comments
 (0)