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

Commit 679eaf0

Browse files
committed
perf(animate): avoid unnecessary computations if animations are globally disabled
1 parent 71c4d8c commit 679eaf0

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/ngAnimate/animateQueue.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,16 @@ var $$AnimateQueueProvider = ['$animateProvider', /** @this */ function($animate
306306
return $animate;
307307

308308
function queueAnimation(originalElement, event, initialOptions) {
309+
// we create a fake runner with a working promise.
310+
// These methods will become available after the digest has passed
311+
var runner = new $$AnimateRunner();
312+
313+
// If animations are hard-disabled for the whole application there is no need to continue
314+
if (!animationsEnabled) {
315+
close();
316+
return runner;
317+
}
318+
309319
// we always make a copy of the options since
310320
// there should never be any side effects on
311321
// the input data when running `$animateCss`.
@@ -317,10 +327,6 @@ var $$AnimateQueueProvider = ['$animateProvider', /** @this */ function($animate
317327

318328
options = prepareAnimationOptions(options);
319329

320-
// we create a fake runner with a working promise.
321-
// These methods will become available after the digest has passed
322-
var runner = new $$AnimateRunner();
323-
324330
// this is used to trigger callbacks in postDigest mode
325331
var runInNextPostDigestOrNow = postDigestTaskFactory();
326332

@@ -348,7 +354,7 @@ var $$AnimateQueueProvider = ['$animateProvider', /** @this */ function($animate
348354
options.to = null;
349355
}
350356

351-
// there are situations where a directive issues an animation for
357+
// There are situations where a directive issues an animation for
352358
// a jqLite wrapper that contains only comment nodes... If this
353359
// happens then there is no way we can perform an animation
354360
if (!node ||
@@ -362,12 +368,11 @@ var $$AnimateQueueProvider = ['$animateProvider', /** @this */ function($animate
362368

363369
var documentHidden = $$isDocumentHidden();
364370

365-
// this is a hard disable of all animations for the application or on
366-
// the element itself, therefore there is no need to continue further
367-
// past this point if not enabled
371+
// This is a hard disable of all animations the element itself, therefore there is no need to
372+
// continue further past this point if not enabled
368373
// Animations are also disabled if the document is currently hidden (page is not visible
369374
// to the user), because browsers slow down or do not flush calls to requestAnimationFrame
370-
var skipAnimations = !animationsEnabled || documentHidden || disabledElementsLookup.get(node);
375+
var skipAnimations = documentHidden || disabledElementsLookup.get(node);
371376
var existingAnimation = (!skipAnimations && activeAnimationsLookup.get(node)) || {};
372377
var hasExistingAnimation = !!existingAnimation.state;
373378

0 commit comments

Comments
 (0)