Further optimizations for event dispatching (#48426)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/48426

Changelog: [internal]

This improves the performance of DOM `Event` interface implementation by migrating away from private fields.

Reviewed By: yungsters

Differential Revision: D67751821

fbshipit-source-id: e58e5a9cbb04e7d91cbc676ec7d1b00fff357e2e
This commit is contained in:
Rubén Norte
2025-01-27 07:48:50 -08:00
committed by Facebook GitHub Bot
parent 47e490f084
commit e04e502f77
+18 -18
View File
@@ -48,13 +48,13 @@ export default class Event {
static AT_TARGET: 2 = 2;
static BUBBLING_PHASE: 3 = 3;
#bubbles: boolean;
#cancelable: boolean;
#composed: boolean;
#type: string;
_bubbles: boolean;
_cancelable: boolean;
_composed: boolean;
_type: string;
#defaultPrevented: boolean = false;
#timeStamp: number = performance.now();
_defaultPrevented: boolean = false;
_timeStamp: number = performance.now();
// $FlowExpectedError[unsupported-syntax]
[COMPOSED_PATH_KEY]: boolean = [];
@@ -99,22 +99,22 @@ export default class Event {
);
}
this.#type = String(type);
this.#bubbles = Boolean(options?.bubbles);
this.#cancelable = Boolean(options?.cancelable);
this.#composed = Boolean(options?.composed);
this._type = String(type);
this._bubbles = Boolean(options?.bubbles);
this._cancelable = Boolean(options?.cancelable);
this._composed = Boolean(options?.composed);
}
get bubbles(): boolean {
return this.#bubbles;
return this._bubbles;
}
get cancelable(): boolean {
return this.#cancelable;
return this._cancelable;
}
get composed(): boolean {
return this.#composed;
return this._composed;
}
get currentTarget(): EventTarget | null {
@@ -122,7 +122,7 @@ export default class Event {
}
get defaultPrevented(): boolean {
return this.#defaultPrevented;
return this._defaultPrevented;
}
get eventPhase(): EventPhase {
@@ -138,11 +138,11 @@ export default class Event {
}
get timeStamp(): number {
return this.#timeStamp;
return this._timeStamp;
}
get type(): string {
return this.#type;
return this._type;
}
composedPath(): $ReadOnlyArray<EventTarget> {
@@ -150,7 +150,7 @@ export default class Event {
}
preventDefault(): void {
if (!this.#cancelable) {
if (!this._cancelable) {
return;
}
@@ -163,7 +163,7 @@ export default class Event {
return;
}
this.#defaultPrevented = true;
this._defaultPrevented = true;
}
stopImmediatePropagation(): void {