Skip to content

Commit

Permalink
Simplify options.cache normalization logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamn committed Nov 28, 2023
1 parent 2b36aa5 commit f0133c0
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,19 +138,12 @@ export function wrap<
makeCacheKey = (defaultMakeCacheKey as () => TCacheKey),
keyArgs,
subscribe,
cache: cacheOption,
cache: cacheOption = StrongCache,
}: OptimisticWrapOptions<TArgs, TKeyArgs, TCacheKey, TResult> = Object.create(null)) {
let cache: CommonCache<TCacheKey, Entry<TArgs, TResult>>;
if (cacheOption) {
cache = typeof cacheOption === "function"
? new cacheOption(max)
const cache: CommonCache<TCacheKey, Entry<TArgs, TResult>> =
typeof cacheOption === "function"
? new cacheOption(max, entry => entry.dispose())
: cacheOption;
} else {
cache = new StrongCache<TCacheKey, Entry<TArgs, TResult>>(
max,
entry => entry.dispose(),
);
}

const optimistic = function (): TResult {
const key = makeCacheKey.apply(
Expand Down

0 comments on commit f0133c0

Please sign in to comment.