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

Commit

Permalink
perf(ngAnimate): speed up areAnimationsAllowed check
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Narretz committed Jan 19, 2016
1 parent 7700e2d commit 683bd92
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/ngAnimate/animateQueue.js
Expand Up @@ -571,6 +571,13 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
return getDomNode(nodeOrElmA) === getDomNode(nodeOrElmB);
}

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

// disable animations if the user hasn't explicitly enabled animations on the
// current element
if (parentElementDisabled === true && elementDisabled !== false) {
// disable animations if the user hasn't explicitly enabled animations on the
// current element
elementDisabled = true;
// element is disabled via parent element, no need to check anything else
break;
} else if (parentElementDisabled === false) {
elementDisabled = false;
}
Expand All @@ -625,11 +634,17 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) {
if (parentAnimationDetected && animateChildren === false) break;

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

if (bodyElementDetected && rootElementDetected) {
// If both body and root have been found, any other checks are pointless,
// as no animation data should live outside the application
break;
}

if (!rootElementDetected) {
// If no rootElement is detected, check if the parentElement is pinned to another element
parentHost = parentElement.data(NG_ANIMATE_PIN_DATA);
Expand Down

0 comments on commit 683bd92

Please sign in to comment.