@@ -37,8 +37,8 @@ export class RippleRenderer {
37
37
/** Events to be registered on the trigger element. */
38
38
private _triggerEvents = new Map < string , any > ( ) ;
39
39
40
- /** Currently active ripple references. */
41
- private _activeRipples : RippleRef [ ] = [ ] ;
40
+ /** Set of currently active ripple references. */
41
+ private _activeRipples = new Set < RippleRef > ( ) ;
42
42
43
43
/** Ripple config for all ripples created by events. */
44
44
rippleConfig : RippleConfig = { } ;
@@ -105,7 +105,7 @@ export class RippleRenderer {
105
105
// Once it's faded in, the ripple can be hidden immediately if the mouse is released.
106
106
this . runTimeoutOutsideZone ( ( ) => {
107
107
if ( config . persistent || this . _isMousedown ) {
108
- this . _activeRipples . push ( rippleRef ) ;
108
+ this . _activeRipples . add ( rippleRef ) ;
109
109
} else {
110
110
rippleRef . fadeOut ( ) ;
111
111
}
@@ -117,12 +117,8 @@ export class RippleRenderer {
117
117
/** Fades out a ripple reference. */
118
118
fadeOutRipple ( ripple : RippleRef ) {
119
119
let rippleEl = ripple . element ;
120
- let rippleIndex = this . _activeRipples . indexOf ( ripple ) ;
121
120
122
- // Remove the ripple reference if added to the list of active ripples.
123
- if ( rippleIndex !== - 1 ) {
124
- this . _activeRipples . splice ( rippleIndex , 1 ) ;
125
- }
121
+ this . _activeRipples . delete ( ripple ) ;
126
122
127
123
rippleEl . style . transitionDuration = `${ RIPPLE_FADE_OUT_DURATION } ms` ;
128
124
rippleEl . style . opacity = '0' ;
@@ -135,12 +131,7 @@ export class RippleRenderer {
135
131
136
132
/** Fades out all currently active ripples. */
137
133
fadeOutAll ( ) {
138
- // Iterate in reverse, to avoid issues with the `fadeOut` method that will immediately remove
139
- // items from the array.
140
- let i = this . _activeRipples . length ;
141
- while ( i -- ) {
142
- this . _activeRipples [ i ] . fadeOut ( ) ;
143
- }
134
+ this . _activeRipples . forEach ( ripple => ripple . fadeOut ( ) ) ;
144
135
}
145
136
146
137
/** Sets the trigger element and registers the mouse events. */
@@ -173,9 +164,11 @@ export class RippleRenderer {
173
164
this . _isMousedown = false ;
174
165
175
166
// On mouseup, fade-out all ripples that are active and not persistent.
176
- this . _activeRipples
177
- . filter ( ripple => ! ripple . config . persistent )
178
- . forEach ( ripple => ripple . fadeOut ( ) ) ;
167
+ this . _activeRipples . forEach ( ripple => {
168
+ if ( ! ripple . config . persistent ) {
169
+ ripple . fadeOut ( ) ;
170
+ }
171
+ } ) ;
179
172
}
180
173
181
174
/** Listener being called on mouseleave event. */
0 commit comments