Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: rename caches to commonCaches #628

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: rename caches to commonCaches
Renames the `caches` variable because
it interferes with the global browser
API.

Fixes #492
  • Loading branch information
lekoaf committed Dec 14, 2023
commit 1c5d775d3003ec3d16d90c0c754c3a7dd9509a8f
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export interface OptionsWithCacheInstance<
cache: CommonCache<NoInfer<TCacheKey>, Entry<NoInfer<TArgs>, NoInfer<TResult>>>;
};

const caches = new Set<CommonCache<any, AnyEntry>>();
const commonCaches = new Set<CommonCache<any, AnyEntry>>();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__caches might be another alternative since it just seems like a local variable and it seems to be unintended to be accessed in the global scope.


export function wrap<
TArgs extends any[],
Expand Down Expand Up @@ -179,14 +179,14 @@ export function wrap<
// since we just finished computing its value.
cache.set(key, entry);

caches.add(cache);
commonCaches.add(cache);

// Clean up any excess entries in the cache, but only if there is no
// active parent entry, meaning we're not in the middle of a larger
// computation that might be flummoxed by the cleaning.
if (! parentEntrySlot.hasValue()) {
caches.forEach(cache => cache.clean());
caches.clear();
commonCaches.forEach(cache => cache.clean());
commonCaches.clear();
}

return value;
Expand Down