mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Add getOwner on the AsyncDispatcher
This commit is contained in:
committed by
Rick Hanlon
parent
d5d6023a01
commit
d87e6e4e07
+12
-3
@@ -7,13 +7,15 @@
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import type {AsyncDispatcher} from './ReactInternalTypes';
|
||||
import type {AsyncDispatcher, Fiber} from './ReactInternalTypes';
|
||||
import type {Cache} from './ReactFiberCacheComponent';
|
||||
|
||||
import {enableCache} from 'shared/ReactFeatureFlags';
|
||||
import {readContext} from './ReactFiberNewContext';
|
||||
import {CacheContext} from './ReactFiberCacheComponent';
|
||||
|
||||
import {disableStringRefs} from 'shared/ReactFeatureFlags';
|
||||
|
||||
function getCacheForType<T>(resourceType: () => T): T {
|
||||
if (!enableCache) {
|
||||
throw new Error('Not implemented.');
|
||||
@@ -27,6 +29,13 @@ function getCacheForType<T>(resourceType: () => T): T {
|
||||
return cacheForType;
|
||||
}
|
||||
|
||||
export const DefaultAsyncDispatcher: AsyncDispatcher = {
|
||||
export const DefaultAsyncDispatcher: AsyncDispatcher = ({
|
||||
getCacheForType,
|
||||
};
|
||||
}: any);
|
||||
|
||||
if (__DEV__ || !disableStringRefs) {
|
||||
DefaultAsyncDispatcher.getOwner = (): null | Fiber => {
|
||||
// TODO
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -436,4 +436,6 @@ export type Dispatcher = {
|
||||
|
||||
export type AsyncDispatcher = {
|
||||
getCacheForType: <T>(resourceType: () => T) => T,
|
||||
// DEV-only (or !disableStringRefs)
|
||||
getOwner: () => null | Fiber | ReactComponentInfo,
|
||||
};
|
||||
|
||||
+11
-2
@@ -9,10 +9,19 @@
|
||||
|
||||
import type {AsyncDispatcher} from 'react-reconciler/src/ReactInternalTypes';
|
||||
|
||||
import {disableStringRefs} from 'shared/ReactFeatureFlags';
|
||||
|
||||
function getCacheForType<T>(resourceType: () => T): T {
|
||||
throw new Error('Not implemented.');
|
||||
}
|
||||
|
||||
export const DefaultAsyncDispatcher: AsyncDispatcher = {
|
||||
export const DefaultAsyncDispatcher: AsyncDispatcher = ({
|
||||
getCacheForType,
|
||||
};
|
||||
}: any);
|
||||
|
||||
if (__DEV__ || !disableStringRefs) {
|
||||
// Fizz never tracks owner but the JSX runtime looks for this.
|
||||
DefaultAsyncDispatcher.getOwner = (): null => {
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
+18
-2
@@ -7,10 +7,14 @@
|
||||
* @flow
|
||||
*/
|
||||
|
||||
import type {ReactComponentInfo} from 'shared/ReactTypes';
|
||||
|
||||
import type {AsyncDispatcher} from 'react-reconciler/src/ReactInternalTypes';
|
||||
|
||||
import {resolveRequest, getCache} from '../ReactFlightServer';
|
||||
|
||||
import {disableStringRefs} from 'shared/ReactFeatureFlags';
|
||||
|
||||
function resolveCache(): Map<Function, mixed> {
|
||||
const request = resolveRequest();
|
||||
if (request) {
|
||||
@@ -19,7 +23,7 @@ function resolveCache(): Map<Function, mixed> {
|
||||
return new Map();
|
||||
}
|
||||
|
||||
export const DefaultAsyncDispatcher: AsyncDispatcher = {
|
||||
export const DefaultAsyncDispatcher: AsyncDispatcher = ({
|
||||
getCacheForType<T>(resourceType: () => T): T {
|
||||
const cache = resolveCache();
|
||||
let entry: T | void = (cache.get(resourceType): any);
|
||||
@@ -30,4 +34,16 @@ export const DefaultAsyncDispatcher: AsyncDispatcher = {
|
||||
}
|
||||
return entry;
|
||||
},
|
||||
};
|
||||
}: any);
|
||||
|
||||
if (__DEV__) {
|
||||
DefaultAsyncDispatcher.getOwner = (): null | ReactComponentInfo => {
|
||||
// TODO
|
||||
return null;
|
||||
};
|
||||
} else if (!disableStringRefs) {
|
||||
// Server Components never use string refs but the JSX runtime looks for it.
|
||||
DefaultAsyncDispatcher.getOwner = (): null | ReactComponentInfo => {
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -22,6 +22,9 @@ export function waitForSuspense<T>(fn: () => T): Promise<T> {
|
||||
}
|
||||
return entry;
|
||||
},
|
||||
getOwner(): null {
|
||||
return null;
|
||||
},
|
||||
};
|
||||
// Not using async/await because we don't compile it.
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
Reference in New Issue
Block a user