Skip to content

Commit 0102de6

Browse files
committed
Add React.unstable_getCacheForType
1 parent 1e7e5a9 commit 0102de6

File tree

8 files changed

+18
-12
lines changed

8 files changed

+18
-12
lines changed

packages/react-fetch/src/ReactFetchBrowser.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import type {Wakeable} from 'shared/ReactTypes';
1111

12-
import * as React from 'react';
12+
import {getCacheForType} from 'react';
1313

1414
const Pending = 0;
1515
const Resolved = 1;
@@ -35,12 +35,8 @@ type Result = PendingResult | ResolvedResult | RejectedResult;
3535
// TODO: this is a browser-only version. Add a separate Node entry point.
3636
const nativeFetch = window.fetch;
3737

38-
const ReactCurrentDispatcher =
39-
React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
40-
.ReactCurrentDispatcher;
41-
4238
function getResultMap(): Map<string, Result> {
43-
return ReactCurrentDispatcher.current.getCacheForType(createResultMap);
39+
return getCacheForType(createResultMap);
4440
}
4541

4642
function createResultMap(): Map<string, Result> {

packages/react-fetch/src/ReactFetchNode.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type {Wakeable} from 'shared/ReactTypes';
1111

1212
import * as http from 'http';
1313
import * as https from 'https';
14-
import * as React from 'react';
14+
import {getCacheForType} from 'react';
1515

1616
type FetchResponse = {|
1717
// Properties
@@ -74,12 +74,8 @@ type RejectedResult = {|
7474

7575
type Result<V> = PendingResult | ResolvedResult<V> | RejectedResult;
7676

77-
const ReactCurrentDispatcher =
78-
React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
79-
.ReactCurrentDispatcher;
80-
8177
function getResultMap(): Map<string, Result<FetchResponse>> {
82-
return ReactCurrentDispatcher.current.getCacheForType(createResultMap);
78+
return getCacheForType(createResultMap);
8379
}
8480

8581
function createResultMap(): Map<string, Result<FetchResponse>> {

packages/react/index.classic.fb.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ export {
4242
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
4343
createFactory,
4444
// exposeConcurrentModeAPIs
45+
getCacheForType,
46+
getCacheForType as unstable_getCacheForType,
4547
useTransition,
4648
useTransition as unstable_useTransition,
4749
useDeferredValue,

packages/react/index.experimental.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export {
4040
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
4141
createFactory,
4242
// exposeConcurrentModeAPIs
43+
getCacheForType as unstable_getCacheForType,
4344
useTransition as unstable_useTransition,
4445
useDeferredValue as unstable_useDeferredValue,
4546
startTransition as unstable_startTransition,

packages/react/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ export {
7070
version,
7171
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
7272
createFactory,
73+
getCacheForType,
74+
getCacheForType as unstable_getCacheForType,
7375
useTransition,
7476
useTransition as unstable_useTransition,
7577
startTransition,

packages/react/index.modern.fb.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ export {
4141
version,
4242
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
4343
// exposeConcurrentModeAPIs
44+
getCacheForType,
45+
getCacheForType as unstable_getCacheForType,
4446
useTransition,
4547
useTransition as unstable_useTransition,
4648
useDeferredValue,

packages/react/src/React.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {lazy} from './ReactLazy';
3333
import {forwardRef} from './ReactForwardRef';
3434
import {memo} from './ReactMemo';
3535
import {
36+
getCacheForType,
3637
useCallback,
3738
useContext,
3839
useEffect,
@@ -105,6 +106,7 @@ export {
105106
// Deprecated behind disableCreateFactory
106107
createFactory,
107108
// Concurrent Mode
109+
getCacheForType,
108110
useTransition,
109111
startTransition,
110112
useDeferredValue,

packages/react/src/ReactHooks.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ function resolveDispatcher() {
3636
return dispatcher;
3737
}
3838

39+
export function getCacheForType<T>(resourceType: () => T): T {
40+
const dispatcher = resolveDispatcher();
41+
return dispatcher.getCacheForType(resourceType);
42+
}
43+
3944
export function useContext<T>(
4045
Context: ReactContext<T>,
4146
unstable_observedBits: number | boolean | void,

0 commit comments

Comments
 (0)