utilium 2.8.2 → 2.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/misc.d.ts +1 -4
- package/dist/misc.js +6 -10
- package/package.json +1 -1
package/dist/misc.d.ts
CHANGED
|
@@ -9,7 +9,4 @@ export declare function canary(error?: Error): () => void;
|
|
|
9
9
|
* @see https://github.com/tc39/proposal-throw-expressions
|
|
10
10
|
*/
|
|
11
11
|
export declare function _throw(e: unknown): never;
|
|
12
|
-
|
|
13
|
-
* Decorator for memoizing the result of a getter.
|
|
14
|
-
*/
|
|
15
|
-
export declare function memoize<T, This>(get: () => T, context: ClassGetterDecoratorContext<This, T>): (this: This) => T;
|
|
12
|
+
export declare function memoize<T, This extends object>(get: () => T, context: ClassGetterDecoratorContext<This, T>): (this: This) => T;
|
package/dist/misc.js
CHANGED
|
@@ -51,19 +51,15 @@ export function _throw(e) {
|
|
|
51
51
|
Error?.captureStackTrace(e, _throw);
|
|
52
52
|
throw e;
|
|
53
53
|
}
|
|
54
|
-
const missing = Symbol('not memoized');
|
|
55
|
-
/**
|
|
56
|
-
* Decorator for memoizing the result of a getter.
|
|
57
|
-
*/
|
|
58
54
|
export function memoize(get, context) {
|
|
59
55
|
if (context.kind != 'getter')
|
|
60
56
|
throw new Error('@memoize can only be used on getters');
|
|
61
|
-
|
|
57
|
+
const cache = new WeakMap();
|
|
62
58
|
return function () {
|
|
63
|
-
if (
|
|
64
|
-
return
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return
|
|
59
|
+
if (cache.has(this))
|
|
60
|
+
return cache.get(this);
|
|
61
|
+
const result = get.call(this);
|
|
62
|
+
cache.set(this, result);
|
|
63
|
+
return result;
|
|
68
64
|
};
|
|
69
65
|
}
|