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
This commit is contained in:
Rubén Norte
2024-07-22 04:45:02 -07:00
committed by Facebook GitHub Bot
parent 2680198b09
commit a5bd64ece8
5 changed files with 68 additions and 78 deletions
@@ -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<string, number> {
});
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;
}
@@ -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';
@@ -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,
};
}
}
@@ -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,
@@ -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 = {