-
Notifications
You must be signed in to change notification settings - Fork 46.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split Cache into its own Dispatcher (#25474)
* Missing Hooks * Remove www forks. These can use __SECRET... instead. * Move cache to separate dispatcher These will be available in more contexts than just render.
- Loading branch information
1 parent
2cf4352
commit a8c16a0
Showing
24 changed files
with
293 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
import type {CacheDispatcher} from './ReactInternalTypes'; | ||
import type {Cache} from './ReactFiberCacheComponent.new'; | ||
|
||
import {enableCache} from 'shared/ReactFeatureFlags'; | ||
import {readContext} from './ReactFiberNewContext.new'; | ||
import {CacheContext} from './ReactFiberCacheComponent.new'; | ||
|
||
function getCacheSignal(): AbortSignal { | ||
if (!enableCache) { | ||
throw new Error('Not implemented.'); | ||
} | ||
const cache: Cache = readContext(CacheContext); | ||
return cache.controller.signal; | ||
} | ||
|
||
function getCacheForType<T>(resourceType: () => T): T { | ||
if (!enableCache) { | ||
throw new Error('Not implemented.'); | ||
} | ||
const cache: Cache = readContext(CacheContext); | ||
let cacheForType: T | void = (cache.data.get(resourceType): any); | ||
if (cacheForType === undefined) { | ||
cacheForType = resourceType(); | ||
cache.data.set(resourceType, cacheForType); | ||
} | ||
return cacheForType; | ||
} | ||
|
||
export const DefaultCacheDispatcher: CacheDispatcher = { | ||
getCacheSignal, | ||
getCacheForType, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
import type {CacheDispatcher} from './ReactInternalTypes'; | ||
import type {Cache} from './ReactFiberCacheComponent.old'; | ||
|
||
import {enableCache} from 'shared/ReactFeatureFlags'; | ||
import {readContext} from './ReactFiberNewContext.old'; | ||
import {CacheContext} from './ReactFiberCacheComponent.old'; | ||
|
||
function getCacheSignal(): AbortSignal { | ||
if (!enableCache) { | ||
throw new Error('Not implemented.'); | ||
} | ||
const cache: Cache = readContext(CacheContext); | ||
return cache.controller.signal; | ||
} | ||
|
||
function getCacheForType<T>(resourceType: () => T): T { | ||
if (!enableCache) { | ||
throw new Error('Not implemented.'); | ||
} | ||
const cache: Cache = readContext(CacheContext); | ||
let cacheForType: T | void = (cache.data.get(resourceType): any); | ||
if (cacheForType === undefined) { | ||
cacheForType = resourceType(); | ||
cache.data.set(resourceType, cacheForType); | ||
} | ||
return cacheForType; | ||
} | ||
|
||
export const DefaultCacheDispatcher: CacheDispatcher = { | ||
getCacheSignal, | ||
getCacheForType, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.