@@ -304,33 +304,6 @@ function getCssTransitionDurationStyle(duration, applyOnlyDuration) {
304
304
return [ style , value ] ;
305
305
}
306
306
307
- function createLocalCacheLookup ( ) {
308
- var cache = Object . create ( null ) ;
309
- return {
310
- flush : function ( ) {
311
- cache = Object . create ( null ) ;
312
- } ,
313
-
314
- count : function ( key ) {
315
- var entry = cache [ key ] ;
316
- return entry ? entry . total : 0 ;
317
- } ,
318
-
319
- get : function ( key ) {
320
- var entry = cache [ key ] ;
321
- return entry && entry . value ;
322
- } ,
323
-
324
- put : function ( key , value ) {
325
- if ( ! cache [ key ] ) {
326
- cache [ key ] = { total : 1 , value : value } ;
327
- } else {
328
- cache [ key ] . total ++ ;
329
- }
330
- }
331
- } ;
332
- }
333
-
334
307
// we do not reassign an already present style value since
335
308
// if we detect the style property value again we may be
336
309
// detecting styles that were added via the `from` styles.
@@ -349,26 +322,16 @@ function registerRestorableStyles(backup, node, properties) {
349
322
}
350
323
351
324
var $AnimateCssProvider = [ '$animateProvider' , /** @this */ function ( $animateProvider ) {
352
- var gcsLookup = createLocalCacheLookup ( ) ;
353
- var gcsStaggerLookup = createLocalCacheLookup ( ) ;
354
325
355
- this . $get = [ '$window' , '$$jqLite' , '$$AnimateRunner' , '$timeout' ,
326
+ this . $get = [ '$window' , '$$jqLite' , '$$AnimateRunner' , '$timeout' , '$$animateCache' ,
356
327
'$$forceReflow' , '$sniffer' , '$$rAFScheduler' , '$$animateQueue' ,
357
- function ( $window , $$jqLite , $$AnimateRunner , $timeout ,
328
+ function ( $window , $$jqLite , $$AnimateRunner , $timeout , $$animateCache ,
358
329
$$forceReflow , $sniffer , $$rAFScheduler , $$animateQueue ) {
359
330
360
331
var applyAnimationClasses = applyAnimationClassesFactory ( $$jqLite ) ;
361
332
362
- var parentCounter = 0 ;
363
- function gcsHashFn ( node , extraClasses ) {
364
- var KEY = '$$ngAnimateParentKey' ;
365
- var parentNode = node . parentNode ;
366
- var parentID = parentNode [ KEY ] || ( parentNode [ KEY ] = ++ parentCounter ) ;
367
- return parentID + '-' + node . getAttribute ( 'class' ) + '-' + extraClasses ;
368
- }
369
-
370
- function computeCachedCssStyles ( node , className , cacheKey , properties ) {
371
- var timings = gcsLookup . get ( cacheKey ) ;
333
+ function computeCachedCssStyles ( node , className , cacheKey , allowNoDuration , properties ) {
334
+ var timings = $$animateCache . get ( cacheKey ) ;
372
335
373
336
if ( ! timings ) {
374
337
timings = computeCssStyles ( $window , node , properties ) ;
@@ -377,20 +340,26 @@ var $AnimateCssProvider = ['$animateProvider', /** @this */ function($animatePro
377
340
}
378
341
}
379
342
343
+ // if a css animation has no duration we
344
+ // should mark that so that repeated addClass/removeClass calls are skipped
345
+ var hasDuration = allowNoDuration || ( timings . transitionDuration > 0 || timings . animationDuration > 0 ) ;
346
+
380
347
// we keep putting this in multiple times even though the value and the cacheKey are the same
381
348
// because we're keeping an internal tally of how many duplicate animations are detected.
382
- gcsLookup . put ( cacheKey , timings ) ;
349
+ $$animateCache . put ( cacheKey , timings , hasDuration ) ;
350
+
383
351
return timings ;
384
352
}
385
353
386
354
function computeCachedCssStaggerStyles ( node , className , cacheKey , properties ) {
387
355
var stagger ;
356
+ var staggerCacheKey = 'stagger-' + cacheKey ;
388
357
389
358
// if we have one or more existing matches of matching elements
390
359
// containing the same parent + CSS styles (which is how cacheKey works)
391
360
// then staggering is possible
392
- if ( gcsLookup . count ( cacheKey ) > 0 ) {
393
- stagger = gcsStaggerLookup . get ( cacheKey ) ;
361
+ if ( $$animateCache . count ( cacheKey ) > 0 ) {
362
+ stagger = $$animateCache . get ( staggerCacheKey ) ;
394
363
395
364
if ( ! stagger ) {
396
365
var staggerClassName = pendClasses ( className , '-stagger' ) ;
@@ -405,7 +374,7 @@ var $AnimateCssProvider = ['$animateProvider', /** @this */ function($animatePro
405
374
406
375
$$jqLite . removeClass ( node , staggerClassName ) ;
407
376
408
- gcsStaggerLookup . put ( cacheKey , stagger ) ;
377
+ $$animateCache . put ( staggerCacheKey , stagger , true ) ;
409
378
}
410
379
}
411
380
@@ -416,8 +385,7 @@ var $AnimateCssProvider = ['$animateProvider', /** @this */ function($animatePro
416
385
function waitUntilQuiet ( callback ) {
417
386
rafWaitQueue . push ( callback ) ;
418
387
$$rAFScheduler . waitUntilQuiet ( function ( ) {
419
- gcsLookup . flush ( ) ;
420
- gcsStaggerLookup . flush ( ) ;
388
+ $$animateCache . flush ( ) ;
421
389
422
390
// DO NOT REMOVE THIS LINE OR REFACTOR OUT THE `pageWidth` variable.
423
391
// PLEASE EXAMINE THE `$$forceReflow` service to understand why.
@@ -432,8 +400,8 @@ var $AnimateCssProvider = ['$animateProvider', /** @this */ function($animatePro
432
400
} ) ;
433
401
}
434
402
435
- function computeTimings ( node , className , cacheKey ) {
436
- var timings = computeCachedCssStyles ( node , className , cacheKey , DETECT_CSS_PROPERTIES ) ;
403
+ function computeTimings ( node , className , cacheKey , allowNoDuration ) {
404
+ var timings = computeCachedCssStyles ( node , className , cacheKey , allowNoDuration , DETECT_CSS_PROPERTIES ) ;
437
405
var aD = timings . animationDelay ;
438
406
var tD = timings . transitionDelay ;
439
407
timings . maxDelay = aD && tD
@@ -520,7 +488,6 @@ var $AnimateCssProvider = ['$animateProvider', /** @this */ function($animatePro
520
488
521
489
var preparationClasses = [ structuralClassName , addRemoveClassName ] . join ( ' ' ) . trim ( ) ;
522
490
var fullClassName = classes + ' ' + preparationClasses ;
523
- var activeClasses = pendClasses ( preparationClasses , ACTIVE_CLASS_SUFFIX ) ;
524
491
var hasToStyles = styles . to && Object . keys ( styles . to ) . length > 0 ;
525
492
var containsKeyframeAnimation = ( options . keyframeStyle || '' ) . length > 0 ;
526
493
@@ -533,7 +500,12 @@ var $AnimateCssProvider = ['$animateProvider', /** @this */ function($animatePro
533
500
return closeAndReturnNoopAnimator ( ) ;
534
501
}
535
502
536
- var cacheKey , stagger ;
503
+ var stagger , cacheKey = $$animateCache . cacheKey ( node , method , options . addClass , options . removeClass ) ;
504
+ if ( $$animateCache . containsCachedAnimationWithoutDuration ( cacheKey ) ) {
505
+ preparationClasses = null ;
506
+ return closeAndReturnNoopAnimator ( ) ;
507
+ }
508
+
537
509
if ( options . stagger > 0 ) {
538
510
var staggerVal = parseFloat ( options . stagger ) ;
539
511
stagger = {
@@ -543,7 +515,6 @@ var $AnimateCssProvider = ['$animateProvider', /** @this */ function($animatePro
543
515
animationDuration : 0
544
516
} ;
545
517
} else {
546
- cacheKey = gcsHashFn ( node , fullClassName ) ;
547
518
stagger = computeCachedCssStaggerStyles ( node , preparationClasses , cacheKey , DETECT_STAGGER_CSS_PROPERTIES ) ;
548
519
}
549
520
@@ -577,7 +548,7 @@ var $AnimateCssProvider = ['$animateProvider', /** @this */ function($animatePro
577
548
var itemIndex = stagger
578
549
? options . staggerIndex >= 0
579
550
? options . staggerIndex
580
- : gcsLookup . count ( cacheKey )
551
+ : $$animateCache . count ( cacheKey )
581
552
: 0 ;
582
553
583
554
var isFirst = itemIndex === 0 ;
@@ -592,7 +563,7 @@ var $AnimateCssProvider = ['$animateProvider', /** @this */ function($animatePro
592
563
blockTransitions ( node , SAFE_FAST_FORWARD_DURATION_VALUE ) ;
593
564
}
594
565
595
- var timings = computeTimings ( node , fullClassName , cacheKey ) ;
566
+ var timings = computeTimings ( node , fullClassName , cacheKey , ! isStructural ) ;
596
567
var relativeDelay = timings . maxDelay ;
597
568
maxDelay = Math . max ( relativeDelay , 0 ) ;
598
569
maxDuration = timings . maxDuration ;
@@ -630,6 +601,8 @@ var $AnimateCssProvider = ['$animateProvider', /** @this */ function($animatePro
630
601
return closeAndReturnNoopAnimator ( ) ;
631
602
}
632
603
604
+ var activeClasses = pendClasses ( preparationClasses , ACTIVE_CLASS_SUFFIX ) ;
605
+
633
606
if ( options . delay != null ) {
634
607
var delayStyle ;
635
608
if ( typeof options . delay !== 'boolean' ) {
@@ -717,10 +690,13 @@ var $AnimateCssProvider = ['$animateProvider', /** @this */ function($animatePro
717
690
animationClosed = true ;
718
691
animationPaused = false ;
719
692
720
- if ( ! options . $$skipPreparationClasses ) {
693
+ if ( preparationClasses && ! options . $$skipPreparationClasses ) {
721
694
$$jqLite . removeClass ( element , preparationClasses ) ;
722
695
}
723
- $$jqLite . removeClass ( element , activeClasses ) ;
696
+
697
+ if ( activeClasses ) {
698
+ $$jqLite . removeClass ( element , activeClasses ) ;
699
+ }
724
700
725
701
blockKeyframeAnimations ( node , false ) ;
726
702
blockTransitions ( node , false ) ;
@@ -904,9 +880,9 @@ var $AnimateCssProvider = ['$animateProvider', /** @this */ function($animatePro
904
880
905
881
if ( flags . recalculateTimingStyles ) {
906
882
fullClassName = node . getAttribute ( 'class' ) + ' ' + preparationClasses ;
907
- cacheKey = gcsHashFn ( node , fullClassName ) ;
883
+ cacheKey = $$animateCache . cacheKey ( node , method , options . addClass , options . removeClass ) ;
908
884
909
- timings = computeTimings ( node , fullClassName , cacheKey ) ;
885
+ timings = computeTimings ( node , fullClassName , cacheKey , false ) ;
910
886
relativeDelay = timings . maxDelay ;
911
887
maxDelay = Math . max ( relativeDelay , 0 ) ;
912
888
maxDuration = timings . maxDuration ;
0 commit comments