From a5bd64ece868ce3ce0bab0237d487cb1e4684cba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Mon, 22 Jul 2024 04:45:02 -0700 Subject: [PATCH] Move classes for Event Timing API to the same module to align with existing convention (#45535) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/45535 Changelog: [internal] Small refactor to group things based on the spec where they're defined. Reviewed By: rshest Differential Revision: D59911334 fbshipit-source-id: 1c40d6bf82b6cc7be78bd81b652d6855c39a53eb --- .../{EventCounts.js => EventTiming.js} | 68 +++++++++++++++++- .../webapis/performance/Performance.js | 2 +- .../performance/PerformanceEventTiming.js | 72 ------------------- .../performance/PerformanceObserver.js | 2 +- .../performance/RawPerformanceEntry.js | 2 +- 5 files changed, 68 insertions(+), 78 deletions(-) rename packages/react-native/src/private/webapis/performance/{EventCounts.js => EventTiming.js} (56%) delete mode 100644 packages/react-native/src/private/webapis/performance/PerformanceEventTiming.js diff --git a/packages/react-native/src/private/webapis/performance/EventCounts.js b/packages/react-native/src/private/webapis/performance/EventTiming.js similarity index 56% rename from packages/react-native/src/private/webapis/performance/EventCounts.js rename to packages/react-native/src/private/webapis/performance/EventTiming.js index 682ef555707..110689a0601 100644 --- a/packages/react-native/src/private/webapis/performance/EventCounts.js +++ b/packages/react-native/src/private/webapis/performance/EventTiming.js @@ -4,13 +4,75 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow strict * @format + * @flow strict */ +// flowlint unsafe-getters-setters:off + +import type { + DOMHighResTimeStamp, + PerformanceEntryJSON, +} from './PerformanceEntry'; + +import {PerformanceEntry} from './PerformanceEntry'; import {warnNoNativePerformanceObserver} from './PerformanceObserver'; import NativePerformanceObserver from './specs/NativePerformanceObserver'; +export type PerformanceEventTimingJSON = { + ...PerformanceEntryJSON, + processingStart: DOMHighResTimeStamp, + processingEnd: DOMHighResTimeStamp, + interactionId: number, + ... +}; + +export class PerformanceEventTiming extends PerformanceEntry { + #processingStart: DOMHighResTimeStamp; + #processingEnd: DOMHighResTimeStamp; + #interactionId: number; + + constructor(init: { + name: string, + startTime?: DOMHighResTimeStamp, + duration?: DOMHighResTimeStamp, + processingStart?: DOMHighResTimeStamp, + processingEnd?: DOMHighResTimeStamp, + interactionId?: number, + }) { + super({ + name: init.name, + entryType: 'event', + startTime: init.startTime ?? 0, + duration: init.duration ?? 0, + }); + this.#processingStart = init.processingStart ?? 0; + this.#processingEnd = init.processingEnd ?? 0; + this.#interactionId = init.interactionId ?? 0; + } + + get processingStart(): DOMHighResTimeStamp { + return this.#processingStart; + } + + get processingEnd(): DOMHighResTimeStamp { + return this.#processingEnd; + } + + get interactionId(): number { + return this.#interactionId; + } + + toJSON(): PerformanceEventTimingJSON { + return { + ...super.toJSON(), + processingStart: this.#processingStart, + processingEnd: this.#processingEnd, + interactionId: this.#interactionId, + }; + } +} + type EventCountsForEachCallbackType = | (() => void) | ((value: number) => void) @@ -41,13 +103,13 @@ function getCachedEventCounts(): Map { }); return cachedEventCounts ?? new Map(); } + /** * Implementation of the EventCounts Web Performance API * corresponding to the standard in * https://www.w3.org/TR/event-timing/#eventcounts */ -export default class EventCounts { - // flowlint unsafe-getters-setters:off +export class EventCounts { get size(): number { return getCachedEventCounts().size; } diff --git a/packages/react-native/src/private/webapis/performance/Performance.js b/packages/react-native/src/private/webapis/performance/Performance.js index 80defff2554..5861d358280 100644 --- a/packages/react-native/src/private/webapis/performance/Performance.js +++ b/packages/react-native/src/private/webapis/performance/Performance.js @@ -18,7 +18,7 @@ import type {PerformanceEntryList} from './PerformanceObserver'; import type {DetailType, PerformanceMarkOptions} from './UserTiming'; import warnOnce from '../../../../Libraries/Utilities/warnOnce'; -import EventCounts from './EventCounts'; +import {EventCounts} from './EventTiming'; import MemoryInfo from './MemoryInfo'; import {ALWAYS_LOGGED_ENTRY_TYPES} from './PerformanceEntry'; import {warnNoNativePerformanceObserver} from './PerformanceObserver'; diff --git a/packages/react-native/src/private/webapis/performance/PerformanceEventTiming.js b/packages/react-native/src/private/webapis/performance/PerformanceEventTiming.js deleted file mode 100644 index 3c806c4700a..00000000000 --- a/packages/react-native/src/private/webapis/performance/PerformanceEventTiming.js +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @format - * @flow strict - */ - -// flowlint unsafe-getters-setters:off - -import type { - DOMHighResTimeStamp, - PerformanceEntryJSON, -} from './PerformanceEntry'; - -import {PerformanceEntry} from './PerformanceEntry'; - -export type PerformanceEventTimingJSON = { - ...PerformanceEntryJSON, - processingStart: DOMHighResTimeStamp, - processingEnd: DOMHighResTimeStamp, - interactionId: number, - ... -}; - -export default class PerformanceEventTiming extends PerformanceEntry { - #processingStart: DOMHighResTimeStamp; - #processingEnd: DOMHighResTimeStamp; - #interactionId: number; - - constructor(init: { - name: string, - startTime?: DOMHighResTimeStamp, - duration?: DOMHighResTimeStamp, - processingStart?: DOMHighResTimeStamp, - processingEnd?: DOMHighResTimeStamp, - interactionId?: number, - }) { - super({ - name: init.name, - entryType: 'event', - startTime: init.startTime ?? 0, - duration: init.duration ?? 0, - }); - this.#processingStart = init.processingStart ?? 0; - this.#processingEnd = init.processingEnd ?? 0; - this.#interactionId = init.interactionId ?? 0; - } - - get processingStart(): DOMHighResTimeStamp { - return this.#processingStart; - } - - get processingEnd(): DOMHighResTimeStamp { - return this.#processingEnd; - } - - get interactionId(): number { - return this.#interactionId; - } - - toJSON(): PerformanceEventTimingJSON { - return { - ...super.toJSON(), - processingStart: this.#processingStart, - processingEnd: this.#processingEnd, - interactionId: this.#interactionId, - }; - } -} diff --git a/packages/react-native/src/private/webapis/performance/PerformanceObserver.js b/packages/react-native/src/private/webapis/performance/PerformanceObserver.js index 4a3984874ea..278c38e0530 100644 --- a/packages/react-native/src/private/webapis/performance/PerformanceObserver.js +++ b/packages/react-native/src/private/webapis/performance/PerformanceObserver.js @@ -14,8 +14,8 @@ import type { } from './PerformanceEntry'; import warnOnce from '../../../../Libraries/Utilities/warnOnce'; +import {PerformanceEventTiming} from './EventTiming'; import {PerformanceEntry} from './PerformanceEntry'; -import PerformanceEventTiming from './PerformanceEventTiming'; import { performanceEntryTypeToRaw, rawToPerformanceEntry, diff --git a/packages/react-native/src/private/webapis/performance/RawPerformanceEntry.js b/packages/react-native/src/private/webapis/performance/RawPerformanceEntry.js index 5ccedba8e0c..3a4e540e275 100644 --- a/packages/react-native/src/private/webapis/performance/RawPerformanceEntry.js +++ b/packages/react-native/src/private/webapis/performance/RawPerformanceEntry.js @@ -14,9 +14,9 @@ import type { RawPerformanceEntryType, } from './specs/NativePerformanceObserver'; +import {PerformanceEventTiming} from './EventTiming'; import {PerformanceLongTaskTiming} from './LongTasks'; import {PerformanceEntry} from './PerformanceEntry'; -import PerformanceEventTiming from './PerformanceEventTiming'; import {PerformanceMark, PerformanceMeasure} from './UserTiming'; export const RawPerformanceEntryTypeValues = {