Files
react-native/packages/react-native/Libraries/WebPerformance/PerformanceEventTiming.js
T
Rubén Norte d71da6190a Define toJSON method in PerformanceEventTiming to show all fields properly when using console.log (#37808)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/37808

When passing entries of type "event" to `console.log` we only see the fields defined in the base `PerformanceEntry` class because it defines a `toJSON` method but the `PerformanceEventTiming` subclass doesn't.

This implements the method in that class too to improve debuggability (while also making it more spec compliant).

Changelog: [internal]

Reviewed By: rshest

Differential Revision: D46597764

fbshipit-source-id: ca6fba3fdbb74a4f767eebc647681e5b65ba65d8
2023-06-12 09:11:58 -07:00

56 lines
1.4 KiB
JavaScript

/**
* 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
*/
import type {HighResTimeStamp, PerformanceEntryJSON} from './PerformanceEntry';
import {PerformanceEntry} from './PerformanceEntry';
export type PerformanceEventTimingJSON = {
...PerformanceEntryJSON,
processingStart: HighResTimeStamp,
processingEnd: HighResTimeStamp,
interactionId: number,
...
};
export class PerformanceEventTiming extends PerformanceEntry {
processingStart: HighResTimeStamp;
processingEnd: HighResTimeStamp;
interactionId: number;
constructor(init: {
name: string,
startTime?: HighResTimeStamp,
duration?: HighResTimeStamp,
processingStart?: HighResTimeStamp,
processingEnd?: HighResTimeStamp,
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;
}
toJSON(): PerformanceEventTimingJSON {
return {
...super.toJSON(),
processingStart: this.processingStart,
processingEnd: this.processingEnd,
interactionId: this.interactionId,
};
}
}