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