utilium 2.8.4 → 2.8.5
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 +8 -1
- package/dist/misc.js +12 -6
- package/package.json +1 -1
package/dist/misc.d.ts
CHANGED
|
@@ -9,4 +9,11 @@ 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
|
-
export declare function memoize<T, This extends object>(get: () => T, context: ClassGetterDecoratorContext<This, T>): (
|
|
12
|
+
export declare function memoize<T, This extends object>(get: () => T, context: ClassGetterDecoratorContext<This, T>): () => T;
|
|
13
|
+
export declare function memoize<T, This extends object>(value: {
|
|
14
|
+
get(): T;
|
|
15
|
+
set(value: T): void;
|
|
16
|
+
}, context: ClassGetterDecoratorContext<This, T>): {
|
|
17
|
+
get(): T;
|
|
18
|
+
set(value: T): void;
|
|
19
|
+
};
|
package/dist/misc.js
CHANGED
|
@@ -51,15 +51,21 @@ export function _throw(e) {
|
|
|
51
51
|
Error?.captureStackTrace(e, _throw);
|
|
52
52
|
throw e;
|
|
53
53
|
}
|
|
54
|
-
export function memoize(
|
|
55
|
-
if (context.kind
|
|
56
|
-
throw new Error('@memoize can only be used on getters');
|
|
54
|
+
export function memoize(value, context) {
|
|
55
|
+
if (!['getter', 'accessor'].includes(context.kind))
|
|
56
|
+
throw new Error('@memoize can only be used on getters and auto-accessors');
|
|
57
57
|
const cache = new WeakMap();
|
|
58
|
-
|
|
58
|
+
function get() {
|
|
59
59
|
if (cache.has(this))
|
|
60
60
|
return cache.get(this);
|
|
61
|
-
const result = get
|
|
61
|
+
const result = context.access.get(this);
|
|
62
62
|
cache.set(this, result);
|
|
63
63
|
return result;
|
|
64
|
-
}
|
|
64
|
+
}
|
|
65
|
+
switch (context.kind) {
|
|
66
|
+
case 'getter':
|
|
67
|
+
return get;
|
|
68
|
+
case 'accessor':
|
|
69
|
+
return { ...value, get };
|
|
70
|
+
}
|
|
65
71
|
}
|