Skip to content

Commit 8139299

Browse files
committed
readCache -> getCacheForType<T>
1 parent 38de6e6 commit 8139299

File tree

9 files changed

+66
-92
lines changed

9 files changed

+66
-92
lines changed

packages/react-debug-tools/src/ReactDebugHooks.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import type {
1313
MutableSourceSubscribeFn,
1414
ReactContext,
1515
ReactProviderType,
16-
ReactCache,
1716
} from 'shared/ReactTypes';
1817
import type {
1918
Fiber,
@@ -102,7 +101,7 @@ function nextHook(): null | Hook {
102101
return hook;
103102
}
104103

105-
function readCache(): ReactCache {
104+
function getCacheForType<T>(resourceType: () => T): T {
106105
invariant(false, 'Not implemented.');
107106
}
108107

@@ -304,7 +303,7 @@ function useOpaqueIdentifier(): OpaqueIDType | void {
304303
}
305304

306305
const Dispatcher: DispatcherType = {
307-
readCache,
306+
getCacheForType,
308307
readContext,
309308
useCallback,
310309
useContext,

packages/react-dom/src/server/ReactPartialRendererHooks.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import type {
1414
MutableSourceGetSnapshotFn,
1515
MutableSourceSubscribeFn,
1616
ReactContext,
17-
ReactCache,
1817
} from 'shared/ReactTypes';
1918
import type PartialRenderer from './ReactPartialRenderer';
2019

@@ -215,7 +214,7 @@ export function resetHooksState(): void {
215214
workInProgressHook = null;
216215
}
217216

218-
function readCache(): ReactCache {
217+
function getCacheForType(resourceType: () => T): T {
219218
invariant(false, 'Not implemented.');
220219
}
221220

@@ -497,7 +496,7 @@ export function setCurrentPartialRenderer(renderer: PartialRenderer) {
497496
}
498497

499498
export const Dispatcher: DispatcherType = {
500-
readCache,
499+
getCacheForType,
501500
readContext,
502501
useContext,
503502
useMemo,

packages/react-fetch/src/ReactFetchBrowser.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @flow
88
*/
99

10-
import type {Wakeable, ReactCache} from 'shared/ReactTypes';
10+
import type {Wakeable} from 'shared/ReactTypes';
1111

1212
import * as React from 'react';
1313

@@ -34,24 +34,17 @@ type Result = PendingResult | ResolvedResult | RejectedResult;
3434

3535
// TODO: this is a browser-only version. Add a separate Node entry point.
3636
const nativeFetch = window.fetch;
37-
const fetchKey = {};
3837

3938
const ReactCurrentDispatcher =
4039
React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
4140
.ReactCurrentDispatcher;
4241

43-
function readCache(): ReactCache {
44-
return ReactCurrentDispatcher.current.readCache();
42+
function getResultMap(): Map<string, Result> {
43+
return ReactCurrentDispatcher.current.getCacheForType(createResultMap);
4544
}
4645

47-
function readResultMap(): Map<string, Result> {
48-
const resources = readCache().resources;
49-
let map = resources.get(fetchKey);
50-
if (map === undefined) {
51-
map = new Map();
52-
resources.set(fetchKey, map);
53-
}
54-
return map;
46+
function createResultMap(): Map<string, Result> {
47+
return new Map();
5548
}
5649

5750
function toResult(thenable): Result {
@@ -128,7 +121,7 @@ Response.prototype = {
128121
};
129122

130123
function preloadResult(url: string, options: mixed): Result {
131-
const map = readResultMap();
124+
const map = getResultMap();
132125
let entry = map.get(url);
133126
if (!entry) {
134127
if (options) {

packages/react-fetch/src/ReactFetchNode.js

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @flow
88
*/
99

10-
import type {Wakeable, ReactCache} from 'shared/ReactTypes';
10+
import type {Wakeable} from 'shared/ReactTypes';
1111

1212
import * as http from 'http';
1313
import * as https from 'https';
@@ -78,20 +78,12 @@ const ReactCurrentDispatcher =
7878
React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
7979
.ReactCurrentDispatcher;
8080

81-
function readCache(): ReactCache {
82-
return ReactCurrentDispatcher.current.readCache();
81+
function getResultMap(): Map<string, Result> {
82+
return ReactCurrentDispatcher.current.getCacheForType(createResultMap);
8383
}
8484

85-
const fetchKey = {};
86-
87-
function readResultMap(): Map<string, Result<FetchResponse>> {
88-
const resources = readCache().resources;
89-
let map = resources.get(fetchKey);
90-
if (map === undefined) {
91-
map = new Map();
92-
resources.set(fetchKey, map);
93-
}
94-
return map;
85+
function createResultMap(): Map<string, Result> {
86+
return new Map();
9587
}
9688

9789
function readResult<T>(result: Result<T>): T {
@@ -173,7 +165,7 @@ Response.prototype = {
173165
};
174166

175167
function preloadResult(url: string, options: mixed): Result<FetchResponse> {
176-
const map = readResultMap();
168+
const map = getResultMap();
177169
let entry = map.get(url);
178170
if (!entry) {
179171
if (options) {

packages/react-reconciler/src/ReactFiberHooks.new.js

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import type {
1212
MutableSourceGetSnapshotFn,
1313
MutableSourceSubscribeFn,
1414
ReactContext,
15-
ReactCache,
1615
} from 'shared/ReactTypes';
1716
import type {Fiber, Dispatcher, HookType} from './ReactInternalTypes';
1817
import type {Lanes, Lane} from './ReactFiberLane';
@@ -1816,12 +1815,12 @@ function dispatchAction<S, A>(
18161815
}
18171816
}
18181817

1819-
function readCache() {
1818+
function getCacheForType() {
18201819
invariant(false, 'Not implemented.');
18211820
}
18221821

18231822
export const ContextOnlyDispatcher: Dispatcher = {
1824-
readCache,
1823+
getCacheForType,
18251824
readContext,
18261825

18271826
useCallback: throwInvalidHookError,
@@ -1843,7 +1842,7 @@ export const ContextOnlyDispatcher: Dispatcher = {
18431842
};
18441843

18451844
const HooksDispatcherOnMount: Dispatcher = {
1846-
readCache,
1845+
getCacheForType,
18471846
readContext,
18481847

18491848
useCallback: mountCallback,
@@ -1865,7 +1864,7 @@ const HooksDispatcherOnMount: Dispatcher = {
18651864
};
18661865

18671866
const HooksDispatcherOnUpdate: Dispatcher = {
1868-
readCache,
1867+
getCacheForType,
18691868
readContext,
18701869

18711870
useCallback: updateCallback,
@@ -1887,7 +1886,7 @@ const HooksDispatcherOnUpdate: Dispatcher = {
18871886
};
18881887

18891888
const HooksDispatcherOnRerender: Dispatcher = {
1890-
readCache,
1889+
getCacheForType,
18911890
readContext,
18921891

18931892
useCallback: updateCallback,
@@ -1936,8 +1935,8 @@ if (__DEV__) {
19361935
};
19371936

19381937
HooksDispatcherOnMountInDEV = {
1939-
readCache(): ReactCache {
1940-
return readCache();
1938+
getCacheForType<T>(resourceType: () => T): T {
1939+
return getCacheForType(resourceType);
19411940
},
19421941
readContext<T>(
19431942
context: ReactContext<T>,
@@ -2066,8 +2065,8 @@ if (__DEV__) {
20662065
};
20672066

20682067
HooksDispatcherOnMountWithHookTypesInDEV = {
2069-
readCache(): ReactCache {
2070-
return readCache();
2068+
getCacheForType<T>(resourceType: () => T): T {
2069+
return getCacheForType(resourceType);
20712070
},
20722071
readContext<T>(
20732072
context: ReactContext<T>,
@@ -2191,8 +2190,8 @@ if (__DEV__) {
21912190
};
21922191

21932192
HooksDispatcherOnUpdateInDEV = {
2194-
readCache(): ReactCache {
2195-
return readCache();
2193+
getCacheForType<T>(resourceType: () => T): T {
2194+
return getCacheForType(resourceType);
21962195
},
21972196
readContext<T>(
21982197
context: ReactContext<T>,
@@ -2316,8 +2315,8 @@ if (__DEV__) {
23162315
};
23172316

23182317
HooksDispatcherOnRerenderInDEV = {
2319-
readCache(): ReactCache {
2320-
return readCache();
2318+
getCacheForType<T>(resourceType: () => T): T {
2319+
return getCacheForType(resourceType);
23212320
},
23222321
readContext<T>(
23232322
context: ReactContext<T>,
@@ -2442,8 +2441,8 @@ if (__DEV__) {
24422441
};
24432442

24442443
InvalidNestedHooksDispatcherOnMountInDEV = {
2445-
readCache(): ReactCache {
2446-
return readCache();
2444+
getCacheForType<T>(resourceType: () => T): T {
2445+
return getCacheForType(resourceType);
24472446
},
24482447
readContext<T>(
24492448
context: ReactContext<T>,
@@ -2582,8 +2581,8 @@ if (__DEV__) {
25822581
};
25832582

25842583
InvalidNestedHooksDispatcherOnUpdateInDEV = {
2585-
readCache(): ReactCache {
2586-
return readCache();
2584+
getCacheForType<T>(resourceType: () => T): T {
2585+
return getCacheForType(resourceType);
25872586
},
25882587
readContext<T>(
25892588
context: ReactContext<T>,
@@ -2722,8 +2721,8 @@ if (__DEV__) {
27222721
};
27232722

27242723
InvalidNestedHooksDispatcherOnRerenderInDEV = {
2725-
readCache(): ReactCache {
2726-
return readCache();
2724+
getCacheForType<T>(resourceType: () => T): T {
2725+
return getCacheForType(resourceType);
27272726
},
27282727
readContext<T>(
27292728
context: ReactContext<T>,

packages/react-reconciler/src/ReactFiberHooks.old.js

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import type {
1212
MutableSourceGetSnapshotFn,
1313
MutableSourceSubscribeFn,
1414
ReactContext,
15-
ReactCache,
1615
} from 'shared/ReactTypes';
1716
import type {Fiber, Dispatcher, HookType} from './ReactInternalTypes';
1817
import type {Lanes, Lane} from './ReactFiberLane';
@@ -1816,12 +1815,12 @@ function dispatchAction<S, A>(
18161815
}
18171816
}
18181817

1819-
function readCache() {
1818+
function getCacheForType<T>(resourceType: () => T): T {
18201819
invariant(false, 'Not implemented.');
18211820
}
18221821

18231822
export const ContextOnlyDispatcher: Dispatcher = {
1824-
readCache,
1823+
getCacheForType,
18251824
readContext,
18261825

18271826
useCallback: throwInvalidHookError,
@@ -1843,7 +1842,7 @@ export const ContextOnlyDispatcher: Dispatcher = {
18431842
};
18441843

18451844
const HooksDispatcherOnMount: Dispatcher = {
1846-
readCache,
1845+
getCacheForType,
18471846
readContext,
18481847

18491848
useCallback: mountCallback,
@@ -1865,7 +1864,7 @@ const HooksDispatcherOnMount: Dispatcher = {
18651864
};
18661865

18671866
const HooksDispatcherOnUpdate: Dispatcher = {
1868-
readCache,
1867+
getCacheForType,
18691868
readContext,
18701869

18711870
useCallback: updateCallback,
@@ -1887,7 +1886,7 @@ const HooksDispatcherOnUpdate: Dispatcher = {
18871886
};
18881887

18891888
const HooksDispatcherOnRerender: Dispatcher = {
1890-
readCache,
1889+
getCacheForType,
18911890
readContext,
18921891

18931892
useCallback: updateCallback,
@@ -1936,8 +1935,8 @@ if (__DEV__) {
19361935
};
19371936

19381937
HooksDispatcherOnMountInDEV = {
1939-
readCache(): ReactCache {
1940-
return readCache();
1938+
getCacheForType<T>(resourceType: () => T): T {
1939+
return getCacheForType(resourceType);
19411940
},
19421941
readContext<T>(
19431942
context: ReactContext<T>,
@@ -2066,8 +2065,8 @@ if (__DEV__) {
20662065
};
20672066

20682067
HooksDispatcherOnMountWithHookTypesInDEV = {
2069-
readCache(): ReactCache {
2070-
return readCache();
2068+
getCacheForType<T>(resourceType: () => T): T {
2069+
return getCacheForType(resourceType);
20712070
},
20722071
readContext<T>(
20732072
context: ReactContext<T>,
@@ -2191,8 +2190,8 @@ if (__DEV__) {
21912190
};
21922191

21932192
HooksDispatcherOnUpdateInDEV = {
2194-
readCache(): ReactCache {
2195-
return readCache();
2193+
getCacheForType<T>(resourceType: () => T): T {
2194+
return getCacheForType(resourceType);
21962195
},
21972196
readContext<T>(
21982197
context: ReactContext<T>,
@@ -2316,8 +2315,8 @@ if (__DEV__) {
23162315
};
23172316

23182317
HooksDispatcherOnRerenderInDEV = {
2319-
readCache(): ReactCache {
2320-
return readCache();
2318+
getCacheForType<T>(resourceType: () => T): T {
2319+
return getCacheForType(resourceType);
23212320
},
23222321
readContext<T>(
23232322
context: ReactContext<T>,
@@ -2442,8 +2441,8 @@ if (__DEV__) {
24422441
};
24432442

24442443
InvalidNestedHooksDispatcherOnMountInDEV = {
2445-
readCache(): ReactCache {
2446-
return readCache();
2444+
getCacheForType<T>(resourceType: () => T): T {
2445+
return getCacheForType(resourceType);
24472446
},
24482447
readContext<T>(
24492448
context: ReactContext<T>,
@@ -2582,8 +2581,8 @@ if (__DEV__) {
25822581
};
25832582

25842583
InvalidNestedHooksDispatcherOnUpdateInDEV = {
2585-
readCache(): ReactCache {
2586-
return readCache();
2584+
getCacheForType<T>(resourceType: () => T): T {
2585+
return getCacheForType(resourceType);
25872586
},
25882587
readContext<T>(
25892588
context: ReactContext<T>,
@@ -2722,8 +2721,8 @@ if (__DEV__) {
27222721
};
27232722

27242723
InvalidNestedHooksDispatcherOnRerenderInDEV = {
2725-
readCache(): ReactCache {
2726-
return readCache();
2724+
getCacheForType<T>(resourceType: () => T): T {
2725+
return getCacheForType(resourceType);
27272726
},
27282727
readContext<T>(
27292728
context: ReactContext<T>,

0 commit comments

Comments
 (0)