Skip to content

Commit

Permalink
Further optimizations for event dispatching (facebook#48426)
Browse files Browse the repository at this point in the history
Summary:

Changelog: [internal]

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

Differential Revision: D67751821
  • Loading branch information
rubennorte authored and facebook-github-bot committed Jan 4, 2025
1 parent 554d670 commit a683051
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions packages/react-native/src/private/webapis/dom/events/Event.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -93,30 +93,30 @@ 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 {
return getCurrentTarget(this);
}

get defaultPrevented(): boolean {
return this.#defaultPrevented;
return this._defaultPrevented;
}

get eventPhase(): EventPhase {
Expand All @@ -132,19 +132,19 @@ 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> {
return getComposedPath(this).slice();
}

preventDefault(): void {
if (!this.#cancelable) {
if (!this._cancelable) {
return;
}

Expand All @@ -157,7 +157,7 @@ export default class Event {
return;
}

this.#defaultPrevented = true;
this._defaultPrevented = true;
}

stopImmediatePropagation(): void {
Expand Down

0 comments on commit a683051

Please sign in to comment.