@@ -22,6 +22,7 @@ import * as capm from './css-animation-parser';
22
22
import { sanitizeModuleName } from '../../utils/common' ;
23
23
import { resolveModuleName } from '../../module-name-resolver' ;
24
24
import { cleanupImportantFlags } from './css-utils' ;
25
+ import { Observable , PropertyChangeData } from '../../data/observable' ;
25
26
26
27
let cssAnimationParserModule : typeof capm ;
27
28
function ensureCssAnimationParserModule ( ) {
@@ -418,6 +419,8 @@ export class CssState {
418
419
_matchInvalid : boolean ;
419
420
_playsKeyframeAnimations : boolean ;
420
421
422
+ private _dynamicUpdateListenerMap : Map < ViewBase , ( t : any ) => void > = new Map ( ) ;
423
+
421
424
constructor ( private viewRef : WeakRef < ViewBase > ) {
422
425
this . _onDynamicStateChangeHandler = ( ) => this . updateDynamicState ( ) ;
423
426
}
@@ -650,9 +653,14 @@ export class CssState {
650
653
const changeMap = this . _match . changeMap ;
651
654
changeMap . forEach ( ( changes , view ) => {
652
655
if ( changes . attributes ) {
653
- changes . attributes . forEach ( ( attribute ) => {
654
- view . addEventListener ( attribute + 'Change' , this . _onDynamicStateChangeHandler ) ;
655
- } ) ;
656
+ const attributes = changes . attributes ;
657
+ const listener = ( args : PropertyChangeData ) => {
658
+ if ( attributes . has ( args . propertyName ) ) {
659
+ this . _onDynamicStateChangeHandler ( ) ;
660
+ }
661
+ } ;
662
+ this . _dynamicUpdateListenerMap . set ( view , listener ) ;
663
+ view . addEventListener ( Observable . propertyChangeEvent , listener ) ;
656
664
}
657
665
if ( changes . pseudoClasses ) {
658
666
changes . pseudoClasses . forEach ( ( pseudoClass ) => {
@@ -669,10 +677,8 @@ export class CssState {
669
677
670
678
private unsubscribeFromDynamicUpdates ( ) : void {
671
679
this . _appliedChangeMap . forEach ( ( changes , view ) => {
672
- if ( changes . attributes ) {
673
- changes . attributes . forEach ( ( attribute ) => {
674
- view . removeEventListener ( attribute + 'Change' , this . _onDynamicStateChangeHandler ) ;
675
- } ) ;
680
+ if ( this . _dynamicUpdateListenerMap . has ( view ) ) {
681
+ view . removeEventListener ( Observable . propertyChangeEvent , this . _dynamicUpdateListenerMap . get ( view ) ) ;
676
682
}
677
683
if ( changes . pseudoClasses ) {
678
684
changes . pseudoClasses . forEach ( ( pseudoClass ) => {
@@ -684,6 +690,7 @@ export class CssState {
684
690
} ) ;
685
691
}
686
692
} ) ;
693
+ this . _dynamicUpdateListenerMap . clear ( ) ;
687
694
this . _appliedChangeMap = CssState . emptyChangeMap ;
688
695
}
689
696
0 commit comments