Refactor IntersectionObserver, MutationObserver and PerformanceObserver options as interfaces (#49737)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/49737

Changelog: [internal]

Just a minor change to align with similar other option bags and TypeScript definitions.

Reviewed By: huntie

Differential Revision: D70355669

fbshipit-source-id: 37c44338c7b358eb2d25e8a14c75a78545b34bf1
This commit is contained in:
Rubén Norte
2025-02-28 05:58:45 -08:00
committed by Facebook GitHub Bot
parent eb877cba39
commit 52713eeff3
4 changed files with 38 additions and 38 deletions
@@ -9460,10 +9460,10 @@ exports[`public API should not change unintentionally src/private/webapis/inters
entries: Array<IntersectionObserverEntry>,
observer: IntersectionObserver
) => mixed;
type IntersectionObserverInit = {
threshold?: number | $ReadOnlyArray<number>,
rnRootThreshold?: number | $ReadOnlyArray<number>,
};
export interface IntersectionObserverInit {
threshold?: number | $ReadOnlyArray<number>;
rnRootThreshold?: number | $ReadOnlyArray<number>;
}
declare export default class IntersectionObserver {
constructor(
callback: IntersectionObserverCallback,
@@ -9507,15 +9507,15 @@ exports[`public API should not change unintentionally src/private/webapis/mutati
mutationRecords: $ReadOnlyArray<MutationRecord>,
observer: MutationObserver
) => mixed;
type MutationObserverInit = $ReadOnly<{
subtree?: boolean,
childList: true,
attributes?: boolean,
attributeFilter?: $ReadOnlyArray<string>,
attributeOldValue?: boolean,
characterData?: boolean,
characterDataOldValue?: boolean,
}>;
export interface MutationObserverInit {
+subtree?: boolean;
+childList: true;
+attributes?: boolean;
+attributeFilter?: $ReadOnlyArray<string>;
+attributeOldValue?: boolean;
+characterData?: boolean;
+characterDataOldValue?: boolean;
}
declare export default class MutationObserver {
constructor(callback: MutationObserverCallback): void;
observe(target: ReactNativeElement, options?: MutationObserverInit): void;
@@ -9687,12 +9687,12 @@ export type PerformanceObserverCallback = (
observer: PerformanceObserver,
options?: PerformanceObserverCallbackOptions
) => void;
export type PerformanceObserverInit = {
entryTypes?: Array<PerformanceEntryType>,
type?: PerformanceEntryType,
buffered?: boolean,
durationThreshold?: DOMHighResTimeStamp,
};
export interface PerformanceObserverInit {
+entryTypes?: Array<PerformanceEntryType>;
+type?: PerformanceEntryType;
+buffered?: boolean;
+durationThreshold?: DOMHighResTimeStamp;
}
declare export class PerformanceObserver {
constructor(callback: PerformanceObserverCallback): void;
observe(options: PerformanceObserverInit): void;
@@ -21,10 +21,10 @@ export type IntersectionObserverCallback = (
observer: IntersectionObserver,
) => mixed;
type IntersectionObserverInit = {
export interface IntersectionObserverInit {
// root?: ReactNativeElement, // This option exists on the Web but it's not currently supported in React Native.
// rootMargin?: string, // This option exists on the Web but it's not currently supported in React Native.
threshold?: number | $ReadOnlyArray<number>,
threshold?: number | $ReadOnlyArray<number>;
/**
* This is a React Native specific option (not spec compliant) that specifies
@@ -36,8 +36,8 @@ type IntersectionObserverInit = {
* Note: If `rnRootThreshold` is set, and `threshold` is not set,
* `threshold` will not default to [0] (as per spec)
*/
rnRootThreshold?: number | $ReadOnlyArray<number>,
};
rnRootThreshold?: number | $ReadOnlyArray<number>;
}
/**
* The [Intersection Observer API](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API)
@@ -21,18 +21,18 @@ export type MutationObserverCallback = (
observer: MutationObserver,
) => mixed;
type MutationObserverInit = $ReadOnly<{
subtree?: boolean,
export interface MutationObserverInit {
+subtree?: boolean;
// This is the only supported option so it's required to be `true`.
childList: true,
+childList: true;
// Unsupported:
attributes?: boolean,
attributeFilter?: $ReadOnlyArray<string>,
attributeOldValue?: boolean,
characterData?: boolean,
characterDataOldValue?: boolean,
}>;
+attributes?: boolean;
+attributeFilter?: $ReadOnlyArray<string>;
+attributeOldValue?: boolean;
+characterData?: boolean;
+characterDataOldValue?: boolean;
}
/**
* This is a React Native implementation for the `MutationObserver` API
@@ -66,12 +66,12 @@ export type PerformanceObserverCallback = (
options?: PerformanceObserverCallbackOptions,
) => void;
export type PerformanceObserverInit = {
entryTypes?: Array<PerformanceEntryType>,
type?: PerformanceEntryType,
buffered?: boolean,
durationThreshold?: DOMHighResTimeStamp,
};
export interface PerformanceObserverInit {
+entryTypes?: Array<PerformanceEntryType>;
+type?: PerformanceEntryType;
+buffered?: boolean;
+durationThreshold?: DOMHighResTimeStamp;
}
function getSupportedPerformanceEntryTypes(): $ReadOnlyArray<PerformanceEntryType> {
if (!NativePerformance) {