Skip to content

Commit

Permalink
wrap new functions in feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
josephsavona committed Oct 21, 2021
1 parent faf84fe commit dcf04a4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/react-reconciler/src/ReactFiberCacheComponent.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ const prevFreshCacheOnStack: StackCursor<Cache | null> = createCursor(null);
// for retaining the cache once it is in use (retainCache), and releasing the cache
// once it is no longer needed (releaseCache).
export function createCache(): Cache {
if (!enableCache) {
return (null: any);
}
const cache: Cache = {
controller: new AbortController(),
data: new Map(),
Expand All @@ -83,6 +86,9 @@ export function createCache(): Cache {
}

export function retainCache(cache: Cache) {
if (!enableCache) {
return;
}
if (__DEV__) {
if (cache.controller.signal.aborted) {
console.warn(
Expand All @@ -96,6 +102,9 @@ export function retainCache(cache: Cache) {

// Cleanup a cache instance, potentially freeing it if there are no more references
export function releaseCache(cache: Cache) {
if (!enableCache) {
return;
}
cache.refCount--;
if (__DEV__) {
if (cache.refCount < 0) {
Expand Down
9 changes: 9 additions & 0 deletions packages/react-reconciler/src/ReactFiberCacheComponent.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ const prevFreshCacheOnStack: StackCursor<Cache | null> = createCursor(null);
// for retaining the cache once it is in use (retainCache), and releasing the cache
// once it is no longer needed (releaseCache).
export function createCache(): Cache {
if (!enableCache) {
return (null: any);
}
const cache: Cache = {
controller: new AbortController(),
data: new Map(),
Expand All @@ -83,6 +86,9 @@ export function createCache(): Cache {
}

export function retainCache(cache: Cache) {
if (!enableCache) {
return;
}
if (__DEV__) {
if (cache.controller.signal.aborted) {
console.warn(
Expand All @@ -96,6 +102,9 @@ export function retainCache(cache: Cache) {

// Cleanup a cache instance, potentially freeing it if there are no more references
export function releaseCache(cache: Cache) {
if (!enableCache) {
return;
}
cache.refCount--;
if (__DEV__) {
if (cache.refCount < 0) {
Expand Down
3 changes: 3 additions & 0 deletions packages/react-reconciler/src/ReactFiberHooks.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -2124,6 +2124,9 @@ function updateRefresh() {
}

function refreshCache<T>(fiber: Fiber, seedKey: ?() => T, seedValue: T) {
if (!enableCache) {
return;
}
// TODO: Does Cache work in legacy mode? Should decide and write a test.
// TODO: Consider warning if the refresh is at discrete priority, or if we
// otherwise suspect that it wasn't batched properly.
Expand Down
3 changes: 3 additions & 0 deletions packages/react-reconciler/src/ReactFiberHooks.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -2124,6 +2124,9 @@ function updateRefresh() {
}

function refreshCache<T>(fiber: Fiber, seedKey: ?() => T, seedValue: T) {
if (!enableCache) {
return;
}
// TODO: Does Cache work in legacy mode? Should decide and write a test.
// TODO: Consider warning if the refresh is at discrete priority, or if we
// otherwise suspect that it wasn't batched properly.
Expand Down

0 comments on commit dcf04a4

Please sign in to comment.