-
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.
These will be available in more contexts than just render.
- Loading branch information
1 parent
5c0e252
commit 990a55e
Showing
22 changed files
with
293 additions
and
219 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.