Skip to content

Commit 13c29db

Browse files
committed
fix: declare reset on prototype
1 parent 96e53c6 commit 13c29db

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

packages/core/data/dom-events/dom-event.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,20 @@ export class DOMEvent implements Event {
271271
this.listenersLive.onMutation = null;
272272
}
273273

274+
/**
275+
* Resets any internal state to allow the event to be redispatched. Call
276+
* this before returning from dispatchTo().
277+
*/
278+
// Declaring this on the prototype rather than as an arrow function saves
279+
// 190 nanoseconds per dispatchTo().
280+
private resetForRedispatch() {
281+
this.currentTarget = null;
282+
this.target = null;
283+
this.eventPhase = this.NONE;
284+
this.propagationState = EventPropagationState.resume;
285+
this.listenersLive = emptyArray;
286+
this.listenersLazyCopy = emptyArray;
287+
}
274288
/**
275289
* Dispatches a synthetic event event to target and returns true if either
276290
* event's cancelable attribute value is false or its preventDefault()
@@ -288,19 +302,6 @@ export class DOMEvent implements Event {
288302
// completed the breaking changes to migrate fully to DOMEvents.
289303
DOMEvent.unstable_currentEvent = this;
290304

291-
/**
292-
* Resets any internal state to allow the event to be redispatched. Call
293-
* this before returning.
294-
*/
295-
const reset = () => {
296-
this.currentTarget = null;
297-
this.target = null;
298-
this.eventPhase = this.NONE;
299-
this.propagationState = EventPropagationState.resume;
300-
this.listenersLive = emptyArray;
301-
this.listenersLazyCopy = emptyArray;
302-
};
303-
304305
// `Observable.removeEventListener` would likely suffice, but grabbing
305306
// the static method named `removeEventListener` on the target's class
306307
// allows us to be robust to the possiblity of the case of the target
@@ -348,7 +349,7 @@ export class DOMEvent implements Event {
348349
});
349350

350351
if (this.propagationState !== EventPropagationState.resume) {
351-
reset();
352+
this.resetForRedispatch();
352353
return !this.defaultPrevented;
353354
}
354355
}
@@ -368,15 +369,15 @@ export class DOMEvent implements Event {
368369
});
369370

370371
if (this.propagationState !== EventPropagationState.resume) {
371-
reset();
372+
this.resetForRedispatch();
372373
return !this.defaultPrevented;
373374
}
374375

375376
// If the event doesn't bubble, then, having dispatched it at the
376377
// target (the first iteration of this loop) we don't let it
377378
// propagate any further.
378379
if (!this.bubbles) {
379-
reset();
380+
this.resetForRedispatch();
380381
break;
381382
}
382383

@@ -393,7 +394,7 @@ export class DOMEvent implements Event {
393394
phase: this.BUBBLING_PHASE,
394395
});
395396

396-
reset();
397+
this.resetForRedispatch();
397398
return !this.defaultPrevented;
398399
}
399400

0 commit comments

Comments
 (0)