Skip to content

Commit

Permalink
Use the right interfaces for PerformanceLongTaskTiming (facebook#45526)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#45526

Changelog: [internal]

Just using the right interfaces so we can expose them in the global scope and do refinements as necessary using `instanceof`.

Reviewed By: rshest

Differential Revision: D59911144
  • Loading branch information
rubennorte authored and facebook-github-bot committed Jul 22, 2024
1 parent cd4b0b8 commit 7c63876
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
39 changes: 39 additions & 0 deletions packages/react-native/src/private/webapis/performance/LongTasks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* 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 {PerformanceEntryJSON} from './PerformanceEntry';

import {PerformanceEntry} from './PerformanceEntry';

export type PerformanceLongTaskTimingJSON = {
...PerformanceEntryJSON,
attribution: $ReadOnlyArray<TaskAttributionTiming>,
...
};

export class TaskAttributionTiming extends PerformanceEntry {}

const EMPTY_ATTRIBUTION: $ReadOnlyArray<TaskAttributionTiming> =
Object.preventExtensions([]);

export class PerformanceLongTaskTiming extends PerformanceEntry {
get attribution(): $ReadOnlyArray<TaskAttributionTiming> {
return EMPTY_ATTRIBUTION;
}

toJSON(): PerformanceLongTaskTimingJSON {
return {
...super.toJSON(),
attribution: this.attribution,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type {
RawPerformanceEntryType,
} from './specs/NativePerformanceObserver';

import {PerformanceLongTaskTiming} from './LongTasks';
import {PerformanceEntry} from './PerformanceEntry';
import PerformanceEventTiming from './PerformanceEventTiming';
import {PerformanceMark, PerformanceMeasure} from './UserTiming';
Expand All @@ -37,6 +38,13 @@ export function rawToPerformanceEntry(
processingEnd: entry.processingEnd,
interactionId: entry.interactionId,
});
} else if (entry.entryType === RawPerformanceEntryTypeValues.LONGTASK) {
return new PerformanceLongTaskTiming({
name: entry.name,
entryType: rawToPerformanceEntryType(entry.entryType),
startTime: entry.startTime,
duration: entry.duration,
});
} else if (entry.entryType === RawPerformanceEntryTypeValues.MARK) {
return new PerformanceMark(entry.name, {
startTime: entry.startTime,
Expand Down

0 comments on commit 7c63876

Please sign in to comment.