Skip to content

Commit

Permalink
Flow: ReactFiberHotReloading recursive type (#25225)
Browse files Browse the repository at this point in the history
  • Loading branch information
kassens authored Sep 12, 2022
1 parent c156ecd commit c739cef
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 55 deletions.
34 changes: 25 additions & 9 deletions packages/react-reconciler/src/ReactFiberHotReloading.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,11 @@
* @flow
*/

import {enableNewReconciler} from 'shared/ReactFeatureFlags';
import type {Instance} from './ReactFiberHostConfig';
import type {FiberRoot} from './ReactInternalTypes';
import type {ReactNodeList} from 'shared/ReactTypes';

export type {
Family,
RefreshUpdate,
SetRefreshHandler,
ScheduleRefresh,
ScheduleRoot,
FindHostInstancesForRefresh,
} from './ReactFiberHotReloading';
import {enableNewReconciler} from 'shared/ReactFeatureFlags';

import {
setRefreshHandler as setRefreshHandler_old,
Expand All @@ -42,6 +37,27 @@ import {
findHostInstancesForRefresh as findHostInstancesForRefresh_new,
} from './ReactFiberHotReloading.new';

export type Family = {
current: any,
};

export type RefreshUpdate = {
staleFamilies: Set<Family>,
updatedFamilies: Set<Family>,
};

// Resolves type to a family.
export type RefreshHandler = any => Family | void;

// Used by React Refresh runtime through DevTools Global Hook.
export type SetRefreshHandler = (handler: RefreshHandler | null) => void;
export type ScheduleRefresh = (root: FiberRoot, update: RefreshUpdate) => void;
export type ScheduleRoot = (root: FiberRoot, element: ReactNodeList) => void;
export type FindHostInstancesForRefresh = (
root: FiberRoot,
families: Array<Family>,
) => Set<Instance>;

export const setRefreshHandler = enableNewReconciler
? setRefreshHandler_new
: setRefreshHandler_old;
Expand Down
33 changes: 10 additions & 23 deletions packages/react-reconciler/src/ReactFiberHotReloading.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@
/* eslint-disable react-internal/prod-error-codes */

import type {ReactElement} from 'shared/ReactElementType';
import type {Fiber} from './ReactInternalTypes';
import type {FiberRoot} from './ReactInternalTypes';
import type {Fiber, FiberRoot} from './ReactInternalTypes';
import type {Instance} from './ReactFiberHostConfig';
import type {ReactNodeList} from 'shared/ReactTypes';

import type {
Family,
FindHostInstancesForRefresh,
RefreshHandler,
RefreshUpdate,
ScheduleRefresh,
ScheduleRoot,
} from './ReactFiberHotReloading';

import {
flushSync,
scheduleUpdateOnFiber,
Expand All @@ -40,27 +48,6 @@ import {
REACT_LAZY_TYPE,
} from 'shared/ReactSymbols';

export type Family = {
current: any,
};

export type RefreshUpdate = {
staleFamilies: Set<Family>,
updatedFamilies: Set<Family>,
};

// Resolves type to a family.
type RefreshHandler = any => Family | void;

// Used by React Refresh runtime through DevTools Global Hook.
export type SetRefreshHandler = (handler: RefreshHandler | null) => void;
export type ScheduleRefresh = (root: FiberRoot, update: RefreshUpdate) => void;
export type ScheduleRoot = (root: FiberRoot, element: ReactNodeList) => void;
export type FindHostInstancesForRefresh = (
root: FiberRoot,
families: Array<Family>,
) => Set<Instance>;

let resolveFamily: RefreshHandler | null = null;
// $FlowFixMe Flow gets confused by a WeakSet feature check below.
let failedBoundaries: WeakSet<Fiber> | null = null;
Expand Down
33 changes: 10 additions & 23 deletions packages/react-reconciler/src/ReactFiberHotReloading.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@
/* eslint-disable react-internal/prod-error-codes */

import type {ReactElement} from 'shared/ReactElementType';
import type {Fiber} from './ReactInternalTypes';
import type {FiberRoot} from './ReactInternalTypes';
import type {Fiber, FiberRoot} from './ReactInternalTypes';
import type {Instance} from './ReactFiberHostConfig';
import type {ReactNodeList} from 'shared/ReactTypes';

import type {
Family,
FindHostInstancesForRefresh,
RefreshHandler,
RefreshUpdate,
ScheduleRefresh,
ScheduleRoot,
} from './ReactFiberHotReloading';

import {
flushSync,
scheduleUpdateOnFiber,
Expand All @@ -40,27 +48,6 @@ import {
REACT_LAZY_TYPE,
} from 'shared/ReactSymbols';

export type Family = {
current: any,
};

export type RefreshUpdate = {
staleFamilies: Set<Family>,
updatedFamilies: Set<Family>,
};

// Resolves type to a family.
type RefreshHandler = any => Family | void;

// Used by React Refresh runtime through DevTools Global Hook.
export type SetRefreshHandler = (handler: RefreshHandler | null) => void;
export type ScheduleRefresh = (root: FiberRoot, update: RefreshUpdate) => void;
export type ScheduleRoot = (root: FiberRoot, element: ReactNodeList) => void;
export type FindHostInstancesForRefresh = (
root: FiberRoot,
families: Array<Family>,
) => Set<Instance>;

let resolveFamily: RefreshHandler | null = null;
// $FlowFixMe Flow gets confused by a WeakSet feature check below.
let failedBoundaries: WeakSet<Fiber> | null = null;
Expand Down

0 comments on commit c739cef

Please sign in to comment.