Skip to content

Commit aefefb7

Browse files
committed
Unique symbols per decorator/method
1 parent cd3c563 commit aefefb7

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/index.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ export interface MemoizePropertyDescriptor<T, U extends any[], R>
33
value?: (this: T, ...args: U) => R;
44
}
55

6-
const PREV = Symbol("memoizeOnePrev");
7-
const RESULT = Symbol("memoizeOneResult");
8-
96
/**
107
* Memoize the last call to a function.
118
*/
@@ -20,15 +17,19 @@ export function memoizeOne<T, U extends any[], R>(
2017
throw new TypeError("Property descriptor expected to be a function");
2118
}
2219

20+
// Track unique symbols per class and method.
21+
const PREV = Symbol(`memoizePrev[${func.name}]`);
22+
const RESULT = Symbol(`memoizeResult[${func.name}]`);
23+
2324
descriptor.value = function memoizeOne(
2425
this: T & { [PREV]?: U; [RESULT]?: R },
2526
...args: U
2627
) {
2728
const shouldUpdate = this[PREV] === undefined || !equal(this[PREV]!, args);
2829

2930
if (shouldUpdate) {
30-
this[PREV] = args;
3131
this[RESULT] = func.apply(this, args);
32+
this[PREV] = args;
3233
}
3334

3435
return this[RESULT]!;

0 commit comments

Comments
 (0)