Skip to content

Commit 05be374

Browse files
rubennortefacebook-github-bot
authored andcommitted
Define Flow types for Performance APIs (#53433)
Summary: Pull Request resolved: #53433 Changelog: [internal] This adds the definitions for the Web Performance APIs in the global scope. Reviewed By: zeyap Differential Revision: D80811659 fbshipit-source-id: a81117a27a480ba03f8feb2e813a3a66a10307f9
1 parent 0a0b48b commit 05be374

File tree

1 file changed

+157
-0
lines changed

1 file changed

+157
-0
lines changed

packages/react-native/flow/bom.js.flow

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,169 @@ declare var navigator: Navigator;
8888
// https://developer.mozilla.org/en-US/docs/Web/API/DOMHighResTimeStamp
8989
declare type DOMHighResTimeStamp = number;
9090

91+
type PerformanceEntryFilterOptions = {
92+
entryType: string,
93+
name: string,
94+
...
95+
};
96+
97+
// https://www.w3.org/TR/performance-timeline-2/
98+
declare class PerformanceEntry {
99+
duration: DOMHighResTimeStamp;
100+
entryType: string;
101+
name: string;
102+
startTime: DOMHighResTimeStamp;
103+
toJSON(): string;
104+
}
105+
106+
// https://w3c.github.io/user-timing/#performancemark
107+
declare class PerformanceMark extends PerformanceEntry {
108+
constructor(name: string, markOptions?: PerformanceMarkOptions): void;
109+
+detail: mixed;
110+
}
111+
112+
// https://w3c.github.io/user-timing/#performancemeasure
113+
declare class PerformanceMeasure extends PerformanceEntry {
114+
+detail: mixed;
115+
}
116+
117+
// https://w3c.github.io/server-timing/#the-performanceservertiming-interface
118+
declare class PerformanceServerTiming {
119+
description: string;
120+
duration: DOMHighResTimeStamp;
121+
name: string;
122+
toJSON(): string;
123+
}
124+
125+
// https://www.w3.org/TR/resource-timing-2/#sec-performanceresourcetiming
126+
// https://w3c.github.io/server-timing/#extension-to-the-performanceresourcetiming-interface
127+
declare class PerformanceResourceTiming extends PerformanceEntry {
128+
connectEnd: number;
129+
connectStart: number;
130+
decodedBodySize: number;
131+
domainLookupEnd: number;
132+
domainLookupStart: number;
133+
encodedBodySize: number;
134+
fetchStart: number;
135+
initiatorType: string;
136+
nextHopProtocol: string;
137+
redirectEnd: number;
138+
redirectStart: number;
139+
requestStart: number;
140+
responseEnd: number;
141+
responseStart: number;
142+
secureConnectionStart: number;
143+
serverTiming: Array<PerformanceServerTiming>;
144+
transferSize: number;
145+
workerStart: number;
146+
}
147+
148+
// https://w3c.github.io/event-timing/#sec-performance-event-timing
149+
declare class PerformanceEventTiming extends PerformanceEntry {
150+
cancelable: boolean;
151+
interactionId: number;
152+
processingEnd: number;
153+
processingStart: number;
154+
target: ?Node;
155+
}
156+
157+
// https://w3c.github.io/longtasks/#taskattributiontiming
158+
declare class TaskAttributionTiming extends PerformanceEntry {
159+
containerId: string;
160+
containerName: string;
161+
containerSrc: string;
162+
containerType: string;
163+
}
164+
165+
// https://w3c.github.io/longtasks/#sec-PerformanceLongTaskTiming
166+
declare class PerformanceLongTaskTiming extends PerformanceEntry {
167+
attribution: $ReadOnlyArray<TaskAttributionTiming>;
168+
}
169+
170+
// https://www.w3.org/TR/user-timing/#extensions-performance-interface
171+
declare type PerformanceMarkOptions = {
172+
detail?: mixed,
173+
startTime?: number,
174+
};
175+
176+
declare type PerformanceMeasureOptions = {
177+
detail?: mixed,
178+
duration?: number,
179+
end?: number | string,
180+
start?: number | string,
181+
};
182+
183+
type EventCountsForEachCallbackType =
184+
| (() => void)
185+
| ((value: number) => void)
186+
| ((value: number, key: string) => void)
187+
| ((value: number, key: string, map: Map<string, number>) => void);
188+
189+
// https://www.w3.org/TR/event-timing/#eventcounts
190+
declare interface EventCounts {
191+
entries(): Iterator<[string, number]>;
192+
193+
forEach(callback: EventCountsForEachCallbackType): void;
194+
get(key: string): ?number;
195+
has(key: string): boolean;
196+
keys(): Iterator<string>;
197+
size: number;
198+
values(): Iterator<number>;
199+
}
200+
91201
declare class Performance {
202+
clearMarks(name?: string): void;
203+
204+
clearMeasures(name?: string): void;
205+
206+
eventCounts: EventCounts;
207+
getEntries: (
208+
options?: PerformanceEntryFilterOptions,
209+
) => Array<PerformanceEntry>;
210+
getEntriesByName: (name: string, type?: string) => Array<PerformanceEntry>;
211+
getEntriesByType: (type: string) => Array<PerformanceEntry>;
212+
mark(name: string, options?: PerformanceMarkOptions): PerformanceMark;
213+
measure(
214+
name: string,
215+
startMarkOrOptions?: string | PerformanceMeasureOptions,
216+
endMark?: string,
217+
): PerformanceMeasure;
92218
now: () => DOMHighResTimeStamp;
219+
toJSON(): string;
93220
}
94221

95222
declare var performance: Performance;
96223

224+
type PerformanceEntryList = Array<PerformanceEntry>;
225+
226+
declare interface PerformanceObserverEntryList {
227+
getEntries(): PerformanceEntryList;
228+
getEntriesByName(name: string, type: ?string): PerformanceEntryList;
229+
getEntriesByType(type: string): PerformanceEntryList;
230+
}
231+
232+
type PerformanceObserverInit = {
233+
buffered?: boolean,
234+
entryTypes?: Array<string>,
235+
type?: string,
236+
...
237+
};
238+
239+
declare class PerformanceObserver {
240+
constructor(
241+
callback: (
242+
entries: PerformanceObserverEntryList,
243+
observer: PerformanceObserver,
244+
) => mixed,
245+
): void;
246+
247+
disconnect(): void;
248+
observe(options: ?PerformanceObserverInit): void;
249+
static supportedEntryTypes: Array<string>;
250+
251+
takeRecords(): PerformanceEntryList;
252+
}
253+
97254
type FormDataEntryValue = string | File;
98255

99256
declare class FormData {

0 commit comments

Comments
 (0)