mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
fix: declare reset on prototype
This commit is contained in:
@@ -271,6 +271,20 @@ export class DOMEvent implements Event {
|
||||
this.listenersLive.onMutation = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets any internal state to allow the event to be redispatched. Call
|
||||
* this before returning from dispatchTo().
|
||||
*/
|
||||
// Declaring this on the prototype rather than as an arrow function saves
|
||||
// 190 nanoseconds per dispatchTo().
|
||||
private resetForRedispatch() {
|
||||
this.currentTarget = null;
|
||||
this.target = null;
|
||||
this.eventPhase = this.NONE;
|
||||
this.propagationState = EventPropagationState.resume;
|
||||
this.listenersLive = emptyArray;
|
||||
this.listenersLazyCopy = emptyArray;
|
||||
}
|
||||
/**
|
||||
* Dispatches a synthetic event event to target and returns true if either
|
||||
* event's cancelable attribute value is false or its preventDefault()
|
||||
@@ -288,19 +302,6 @@ export class DOMEvent implements Event {
|
||||
// completed the breaking changes to migrate fully to DOMEvents.
|
||||
DOMEvent.unstable_currentEvent = this;
|
||||
|
||||
/**
|
||||
* Resets any internal state to allow the event to be redispatched. Call
|
||||
* this before returning.
|
||||
*/
|
||||
const reset = () => {
|
||||
this.currentTarget = null;
|
||||
this.target = null;
|
||||
this.eventPhase = this.NONE;
|
||||
this.propagationState = EventPropagationState.resume;
|
||||
this.listenersLive = emptyArray;
|
||||
this.listenersLazyCopy = emptyArray;
|
||||
};
|
||||
|
||||
// `Observable.removeEventListener` would likely suffice, but grabbing
|
||||
// the static method named `removeEventListener` on the target's class
|
||||
// allows us to be robust to the possiblity of the case of the target
|
||||
@@ -348,7 +349,7 @@ export class DOMEvent implements Event {
|
||||
});
|
||||
|
||||
if (this.propagationState !== EventPropagationState.resume) {
|
||||
reset();
|
||||
this.resetForRedispatch();
|
||||
return !this.defaultPrevented;
|
||||
}
|
||||
}
|
||||
@@ -368,7 +369,7 @@ export class DOMEvent implements Event {
|
||||
});
|
||||
|
||||
if (this.propagationState !== EventPropagationState.resume) {
|
||||
reset();
|
||||
this.resetForRedispatch();
|
||||
return !this.defaultPrevented;
|
||||
}
|
||||
|
||||
@@ -376,7 +377,7 @@ export class DOMEvent implements Event {
|
||||
// target (the first iteration of this loop) we don't let it
|
||||
// propagate any further.
|
||||
if (!this.bubbles) {
|
||||
reset();
|
||||
this.resetForRedispatch();
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -393,7 +394,7 @@ export class DOMEvent implements Event {
|
||||
phase: this.BUBBLING_PHASE,
|
||||
});
|
||||
|
||||
reset();
|
||||
this.resetForRedispatch();
|
||||
return !this.defaultPrevented;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user