Skip to content

Commit c4f033b

Browse files
committed
Use Set instead of Field
1 parent 766027e commit c4f033b

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

src/lib/core/ripple/ripple-renderer.ts

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ export class RippleRenderer {
3737
/** Events to be registered on the trigger element. */
3838
private _triggerEvents = new Map<string, any>();
3939

40-
/** Currently active ripple references. */
41-
private _activeRipples: RippleRef[] = [];
40+
/** Set of currently active ripple references. */
41+
private _activeRipples = new Set<RippleRef>();
4242

4343
/** Ripple config for all ripples created by events. */
4444
rippleConfig: RippleConfig = {};
@@ -105,7 +105,7 @@ export class RippleRenderer {
105105
// Once it's faded in, the ripple can be hidden immediately if the mouse is released.
106106
this.runTimeoutOutsideZone(() => {
107107
if (config.persistent || this._isMousedown) {
108-
this._activeRipples.push(rippleRef);
108+
this._activeRipples.add(rippleRef);
109109
} else {
110110
rippleRef.fadeOut();
111111
}
@@ -117,12 +117,8 @@ export class RippleRenderer {
117117
/** Fades out a ripple reference. */
118118
fadeOutRipple(ripple: RippleRef) {
119119
let rippleEl = ripple.element;
120-
let rippleIndex = this._activeRipples.indexOf(ripple);
121120

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);
126122

127123
rippleEl.style.transitionDuration = `${RIPPLE_FADE_OUT_DURATION}ms`;
128124
rippleEl.style.opacity = '0';
@@ -135,12 +131,7 @@ export class RippleRenderer {
135131

136132
/** Fades out all currently active ripples. */
137133
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());
144135
}
145136

146137
/** Sets the trigger element and registers the mouse events. */
@@ -173,9 +164,11 @@ export class RippleRenderer {
173164
this._isMousedown = false;
174165

175166
// 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+
});
179172
}
180173

181174
/** Listener being called on mouseleave event. */

0 commit comments

Comments
 (0)