Skip to content

Commit

Permalink
Use object for initial cache key in memoize again
Browse files Browse the repository at this point in the history
  • Loading branch information
mythmon committed May 26, 2022
1 parent d692adb commit 30da5cb
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/memoize.ts
@@ -1,8 +1,8 @@
export function memoize1<R extends Array<unknown>, T>(compute: (...rest: R) => T): (...rest: R) => T {
let cacheValue: T;
let cacheKeys: R | null = null;
let cacheKeys: R | {length?: undefined} = {};
return (...keys: R) => {
if (cacheKeys?.length !== keys.length || cacheKeys.some((k, i) => k !== keys[i])) {
if (cacheKeys.length !== keys.length || cacheKeys.some((k, i) => k !== keys[i])) {
cacheKeys = keys;
cacheValue = compute(...keys);
}
Expand Down

0 comments on commit 30da5cb

Please sign in to comment.