Skip to content

Commit

Permalink
Rename internal ReactRoot types
Browse files Browse the repository at this point in the history
  • Loading branch information
acdlite committed May 13, 2019
1 parent 7723a44 commit 918d7fd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
23 changes: 13 additions & 10 deletions packages/react-dom/src/client/ReactDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ setRestoreImplementation(restoreControlledState);

export type DOMContainer =
| (Element & {
_reactRootContainer: ?Root,
_reactRootContainer: ?(_ReactRoot | _ReactSyncRoot),
_reactHasBeenPassedToCreateRootDEV: ?boolean,
})
| (Document & {
_reactRootContainer: ?Root,
_reactRootContainer: ?(_ReactRoot | _ReactSyncRoot),
_reactHasBeenPassedToCreateRootDEV: ?boolean,
});

Expand All @@ -175,26 +175,26 @@ type Batch = FiberRootBatch & {
// The ReactRoot constructor is hoisted but the prototype methods are not. If
// we move ReactRoot to be above ReactBatch, the inverse error occurs.
// $FlowFixMe Hoisting issue.
_root: Root,
_root: _ReactRoot | _ReactSyncRoot,
_hasChildren: boolean,
_children: ReactNodeList,

_callbacks: Array<() => mixed> | null,
_didComplete: boolean,
};

type Root = {
type _ReactSyncRoot = {
render(children: ReactNodeList, callback: ?() => mixed): Work,
unmount(callback: ?() => mixed): Work,

_internalRoot: FiberRoot,
};

type RootWithBatchingAPI = Root & {
type _ReactRoot = _ReactSyncRoot & {
createBatch(): Batch,
};

function ReactBatch(root: Root) {
function ReactBatch(root: _ReactRoot | _ReactSyncRoot) {
const expirationTime = computeUniqueAsyncExpiration();
this._expirationTime = expirationTime;
this._root = root;
Expand Down Expand Up @@ -489,7 +489,7 @@ let warnedAboutHydrateAPI = false;
function legacyCreateRootFromDOMContainer(
container: DOMContainer,
forceHydrate: boolean,
): Root {
): _ReactSyncRoot {
const shouldHydrate =
forceHydrate || shouldHydrateDueToLegacyHeuristic(container);
// First clear any existing content.
Expand Down Expand Up @@ -545,7 +545,7 @@ function legacyRenderSubtreeIntoContainer(

// TODO: Without `any` type, Flow says "Property cannot be accessed on any
// member of intersection type." Whyyyyyy.
let root: Root = (container._reactRootContainer: any);
let root: _ReactSyncRoot = (container._reactRootContainer: any);
let fiberRoot;
if (!root) {
// Initial mount
Expand Down Expand Up @@ -817,7 +817,7 @@ type RootOptions = {
function createRoot(
container: DOMContainer,
options?: RootOptions,
): RootWithBatchingAPI {
): _ReactRoot {
const functionName = enableStableConcurrentModeAPIs
? 'createRoot'
: 'unstable_createRoot';
Expand All @@ -831,7 +831,10 @@ function createRoot(
return new ReactRoot(container, hydrate);
}

function createSyncRoot(container: DOMContainer, options?: RootOptions): Root {
function createSyncRoot(
container: DOMContainer,
options?: RootOptions,
): _ReactSyncRoot {
const functionName = enableStableConcurrentModeAPIs
? 'createRoot'
: 'unstable_createRoot';
Expand Down
23 changes: 13 additions & 10 deletions packages/react-dom/src/fire/ReactFire.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,11 @@ setRestoreImplementation(restoreControlledState);

export type DOMContainer =
| (Element & {
_reactRootContainer: ?Root,
_reactRootContainer: ?(_ReactRoot | _ReactSyncRoot),
_reactHasBeenPassedToCreateRootDEV: ?boolean,
})
| (Document & {
_reactRootContainer: ?Root,
_reactRootContainer: ?(_ReactRoot | _ReactSyncRoot),
_reactHasBeenPassedToCreateRootDEV: ?boolean,
});

Expand All @@ -181,26 +181,26 @@ type Batch = FiberRootBatch & {
// The ReactRoot constructor is hoisted but the prototype methods are not. If
// we move ReactRoot to be above ReactBatch, the inverse error occurs.
// $FlowFixMe Hoisting issue.
_root: Root,
_root: _ReactRoot | _ReactSyncRoot,
_hasChildren: boolean,
_children: ReactNodeList,

_callbacks: Array<() => mixed> | null,
_didComplete: boolean,
};

type Root = {
type _ReactSyncRoot = {
render(children: ReactNodeList, callback: ?() => mixed): Work,
unmount(callback: ?() => mixed): Work,

_internalRoot: FiberRoot,
};

type RootWithBatchingAPI = Root & {
type _ReactRoot = _ReactSyncRoot & {
createBatch(): Batch,
};

function ReactBatch(root: Root) {
function ReactBatch(root: _ReactRoot | _ReactSyncRoot) {
const expirationTime = computeUniqueAsyncExpiration();
this._expirationTime = expirationTime;
this._root = root;
Expand Down Expand Up @@ -495,7 +495,7 @@ let warnedAboutHydrateAPI = false;
function legacyCreateRootFromDOMContainer(
container: DOMContainer,
forceHydrate: boolean,
): Root {
): _ReactSyncRoot {
const shouldHydrate =
forceHydrate || shouldHydrateDueToLegacyHeuristic(container);
// First clear any existing content.
Expand Down Expand Up @@ -551,7 +551,7 @@ function legacyRenderSubtreeIntoContainer(

// TODO: Without `any` type, Flow says "Property cannot be accessed on any
// member of intersection type." Whyyyyyy.
let root: Root = (container._reactRootContainer: any);
let root: _ReactSyncRoot = (container._reactRootContainer: any);
let fiberRoot;
if (!root) {
// Initial mount
Expand Down Expand Up @@ -823,7 +823,7 @@ type RootOptions = {
function createRoot(
container: DOMContainer,
options?: RootOptions,
): RootWithBatchingAPI {
): _ReactRoot {
const functionName = enableStableConcurrentModeAPIs
? 'createRoot'
: 'unstable_createRoot';
Expand All @@ -837,7 +837,10 @@ function createRoot(
return new ReactRoot(container, hydrate);
}

function createSyncRoot(container: DOMContainer, options?: RootOptions): Root {
function createSyncRoot(
container: DOMContainer,
options?: RootOptions,
): _ReactSyncRoot {
const functionName = enableStableConcurrentModeAPIs
? 'createRoot'
: 'unstable_createRoot';
Expand Down

0 comments on commit 918d7fd

Please sign in to comment.