@praxisjs/decorators 1.6.1 → 2.0.0
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/CHANGELOG.md +46 -0
- package/dist/component/component.d.ts +1 -1
- package/dist/component/component.d.ts.map +1 -1
- package/dist/component/component.js +8 -15
- package/dist/component/component.js.map +1 -1
- package/dist/component/lazy.d.ts +1 -1
- package/dist/component/lazy.d.ts.map +1 -1
- package/dist/component/lazy.js +44 -36
- package/dist/component/lazy.js.map +1 -1
- package/dist/create-class-decorator.d.ts +27 -5
- package/dist/create-class-decorator.d.ts.map +1 -1
- package/dist/create-class-decorator.js +53 -18
- package/dist/create-class-decorator.js.map +1 -1
- package/dist/create-field-decorator.d.ts +42 -3
- package/dist/create-field-decorator.d.ts.map +1 -1
- package/dist/create-field-decorator.js +63 -27
- package/dist/create-field-decorator.js.map +1 -1
- package/dist/create-getter-decorator.d.ts +81 -16
- package/dist/create-getter-decorator.d.ts.map +1 -1
- package/dist/create-getter-decorator.js +127 -15
- package/dist/create-getter-decorator.js.map +1 -1
- package/dist/create-lifecycle-method-decorator.d.ts +21 -3
- package/dist/create-lifecycle-method-decorator.d.ts.map +1 -1
- package/dist/create-lifecycle-method-decorator.js +25 -18
- package/dist/create-lifecycle-method-decorator.js.map +1 -1
- package/dist/create-method-decorator.d.ts +43 -3
- package/dist/create-method-decorator.d.ts.map +1 -1
- package/dist/create-method-decorator.js +49 -8
- package/dist/create-method-decorator.js.map +1 -1
- package/dist/events/command.d.ts +2 -1
- package/dist/events/command.d.ts.map +1 -1
- package/dist/events/command.js +10 -8
- package/dist/events/command.js.map +1 -1
- package/dist/events/emit.d.ts +2 -2
- package/dist/events/emit.d.ts.map +1 -1
- package/dist/events/emit.js +18 -24
- package/dist/events/emit.js.map +1 -1
- package/dist/events/on-command.d.ts +2 -1
- package/dist/events/on-command.d.ts.map +1 -1
- package/dist/events/on-command.js +12 -14
- package/dist/events/on-command.js.map +1 -1
- package/dist/field.d.ts +51 -0
- package/dist/field.d.ts.map +1 -0
- package/dist/field.js +82 -0
- package/dist/field.js.map +1 -0
- package/dist/functions/bind.d.ts +2 -1
- package/dist/functions/bind.d.ts.map +1 -1
- package/dist/functions/bind.js +4 -4
- package/dist/functions/bind.js.map +1 -1
- package/dist/functions/debounce.d.ts +2 -2
- package/dist/functions/debounce.d.ts.map +1 -1
- package/dist/functions/debounce.js +25 -23
- package/dist/functions/debounce.js.map +1 -1
- package/dist/functions/index.d.ts +1 -1
- package/dist/functions/index.d.ts.map +1 -1
- package/dist/functions/index.js.map +1 -1
- package/dist/functions/log.d.ts +2 -1
- package/dist/functions/log.d.ts.map +1 -1
- package/dist/functions/log.js +38 -40
- package/dist/functions/log.js.map +1 -1
- package/dist/functions/memo.d.ts +9 -1
- package/dist/functions/memo.d.ts.map +1 -1
- package/dist/functions/memo.js +44 -30
- package/dist/functions/memo.js.map +1 -1
- package/dist/functions/once.d.ts +2 -1
- package/dist/functions/once.d.ts.map +1 -1
- package/dist/functions/once.js +10 -14
- package/dist/functions/once.js.map +1 -1
- package/dist/functions/retry.d.ts +2 -1
- package/dist/functions/retry.d.ts.map +1 -1
- package/dist/functions/retry.js +21 -23
- package/dist/functions/retry.js.map +1 -1
- package/dist/functions/throttle.d.ts +2 -1
- package/dist/functions/throttle.d.ts.map +1 -1
- package/dist/functions/throttle.js +12 -14
- package/dist/functions/throttle.js.map +1 -1
- package/dist/functions/until.d.ts +2 -1
- package/dist/functions/until.d.ts.map +1 -1
- package/dist/functions/until.js +13 -14
- package/dist/functions/until.js.map +1 -1
- package/dist/functions/watch.d.ts +1 -1
- package/dist/functions/watch.d.ts.map +1 -1
- package/dist/functions/watch.js +36 -34
- package/dist/functions/watch.js.map +1 -1
- package/dist/functions/when.d.ts +1 -1
- package/dist/functions/when.d.ts.map +1 -1
- package/dist/functions/when.js +19 -21
- package/dist/functions/when.js.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/lifecycle.d.ts +24 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle.js +55 -0
- package/dist/lifecycle.js.map +1 -0
- package/dist/properties/compose.d.ts +3 -2
- package/dist/properties/compose.d.ts.map +1 -1
- package/dist/properties/compose.js +33 -19
- package/dist/properties/compose.js.map +1 -1
- package/dist/properties/computed.d.ts +12 -10
- package/dist/properties/computed.d.ts.map +1 -1
- package/dist/properties/computed.js +26 -21
- package/dist/properties/computed.js.map +1 -1
- package/dist/properties/deep-state.d.ts +2 -1
- package/dist/properties/deep-state.d.ts.map +1 -1
- package/dist/properties/deep-state.js +66 -49
- package/dist/properties/deep-state.js.map +1 -1
- package/dist/properties/function-prop.d.ts +2 -1
- package/dist/properties/function-prop.d.ts.map +1 -1
- package/dist/properties/function-prop.js +20 -22
- package/dist/properties/function-prop.js.map +1 -1
- package/dist/properties/history.d.ts +2 -2
- package/dist/properties/history.d.ts.map +1 -1
- package/dist/properties/history.js +34 -31
- package/dist/properties/history.js.map +1 -1
- package/dist/properties/index.d.ts +1 -0
- package/dist/properties/index.d.ts.map +1 -1
- package/dist/properties/index.js +1 -0
- package/dist/properties/index.js.map +1 -1
- package/dist/properties/persisted.d.ts +2 -1
- package/dist/properties/persisted.d.ts.map +1 -1
- package/dist/properties/persisted.js +30 -19
- package/dist/properties/persisted.js.map +1 -1
- package/dist/properties/prop.d.ts +2 -1
- package/dist/properties/prop.d.ts.map +1 -1
- package/dist/properties/prop.js +26 -22
- package/dist/properties/prop.js.map +1 -1
- package/dist/properties/ref.d.ts +2 -1
- package/dist/properties/ref.d.ts.map +1 -1
- package/dist/properties/ref.js +11 -8
- package/dist/properties/ref.js.map +1 -1
- package/dist/properties/resource.d.ts.map +1 -1
- package/dist/properties/resource.js +21 -16
- package/dist/properties/resource.js.map +1 -1
- package/dist/properties/selector.d.ts +12 -0
- package/dist/properties/selector.d.ts.map +1 -0
- package/dist/properties/selector.js +25 -0
- package/dist/properties/selector.js.map +1 -0
- package/dist/properties/slot.d.ts +2 -1
- package/dist/properties/slot.d.ts.map +1 -1
- package/dist/properties/slot.js +22 -20
- package/dist/properties/slot.js.map +1 -1
- package/dist/properties/state.d.ts.map +1 -1
- package/dist/properties/state.js +27 -16
- package/dist/properties/state.js.map +1 -1
- package/dist/properties/synced.d.ts +2 -1
- package/dist/properties/synced.d.ts.map +1 -1
- package/dist/properties/synced.js +27 -19
- package/dist/properties/synced.js.map +1 -1
- package/dist/shared-method.d.ts +14 -0
- package/dist/shared-method.d.ts.map +1 -0
- package/dist/shared-method.js +87 -0
- package/dist/shared-method.js.map +1 -0
- package/package.json +14 -5
- package/src/component/component.ts +8 -27
- package/src/component/lazy.ts +51 -41
- package/src/create-class-decorator.ts +90 -31
- package/src/create-field-decorator.ts +120 -43
- package/src/create-getter-decorator.ts +263 -66
- package/src/create-lifecycle-method-decorator.ts +50 -28
- package/src/create-method-decorator.ts +119 -13
- package/src/events/command.ts +11 -9
- package/src/events/emit.ts +16 -22
- package/src/events/on-command.ts +17 -18
- package/src/field.ts +116 -0
- package/src/functions/bind.ts +4 -4
- package/src/functions/debounce.ts +25 -23
- package/src/functions/index.ts +1 -1
- package/src/functions/log.ts +44 -46
- package/src/functions/memo.ts +54 -28
- package/src/functions/once.ts +10 -13
- package/src/functions/retry.ts +19 -21
- package/src/functions/throttle.ts +12 -13
- package/src/functions/until.ts +14 -14
- package/src/functions/watch.ts +37 -36
- package/src/functions/when.ts +18 -20
- package/src/index.ts +13 -5
- package/src/lifecycle.ts +74 -0
- package/src/properties/compose.ts +33 -20
- package/src/properties/computed.ts +35 -45
- package/src/properties/deep-state.ts +68 -53
- package/src/properties/function-prop.ts +25 -27
- package/src/properties/history.ts +34 -33
- package/src/properties/index.ts +1 -0
- package/src/properties/persisted.ts +41 -27
- package/src/properties/prop.ts +30 -22
- package/src/properties/ref.ts +12 -10
- package/src/properties/resource.ts +22 -17
- package/src/properties/selector.ts +45 -0
- package/src/properties/slot.ts +28 -22
- package/src/properties/state.ts +32 -16
- package/src/properties/synced.ts +31 -19
- package/src/shared-method.ts +101 -0
- package/dist/__tests__/component.test.d.ts +0 -2
- package/dist/__tests__/component.test.d.ts.map +0 -1
- package/dist/__tests__/component.test.js +0 -147
- package/dist/__tests__/component.test.js.map +0 -1
- package/dist/__tests__/compose.test.d.ts +0 -2
- package/dist/__tests__/compose.test.d.ts.map +0 -1
- package/dist/__tests__/compose.test.js +0 -164
- package/dist/__tests__/compose.test.js.map +0 -1
- package/dist/__tests__/deep-state.test.d.ts +0 -2
- package/dist/__tests__/deep-state.test.d.ts.map +0 -1
- package/dist/__tests__/deep-state.test.js +0 -150
- package/dist/__tests__/deep-state.test.js.map +0 -1
- package/dist/__tests__/events.test.d.ts +0 -2
- package/dist/__tests__/events.test.d.ts.map +0 -1
- package/dist/__tests__/events.test.js +0 -295
- package/dist/__tests__/events.test.js.map +0 -1
- package/dist/__tests__/functions.test.d.ts +0 -2
- package/dist/__tests__/functions.test.d.ts.map +0 -1
- package/dist/__tests__/functions.test.js +0 -618
- package/dist/__tests__/functions.test.js.map +0 -1
- package/dist/__tests__/lazy.test.d.ts +0 -2
- package/dist/__tests__/lazy.test.d.ts.map +0 -1
- package/dist/__tests__/lazy.test.js +0 -227
- package/dist/__tests__/lazy.test.js.map +0 -1
- package/dist/__tests__/memo.test.d.ts +0 -2
- package/dist/__tests__/memo.test.d.ts.map +0 -1
- package/dist/__tests__/memo.test.js +0 -168
- package/dist/__tests__/memo.test.js.map +0 -1
- package/dist/__tests__/properties-browser.test.d.ts +0 -2
- package/dist/__tests__/properties-browser.test.d.ts.map +0 -1
- package/dist/__tests__/properties-browser.test.js +0 -178
- package/dist/__tests__/properties-browser.test.js.map +0 -1
- package/dist/__tests__/properties.test.d.ts +0 -2
- package/dist/__tests__/properties.test.d.ts.map +0 -1
- package/dist/__tests__/properties.test.js +0 -1226
- package/dist/__tests__/properties.test.js.map +0 -1
- package/dist/__tests__/ref.test.d.ts +0 -2
- package/dist/__tests__/ref.test.d.ts.map +0 -1
- package/dist/__tests__/ref.test.js +0 -106
- package/dist/__tests__/ref.test.js.map +0 -1
- package/dist/__tests__/resource.test.d.ts +0 -2
- package/dist/__tests__/resource.test.d.ts.map +0 -1
- package/dist/__tests__/resource.test.js +0 -217
- package/dist/__tests__/resource.test.js.map +0 -1
- package/dist/__tests__/slot.test.d.ts +0 -2
- package/dist/__tests__/slot.test.d.ts.map +0 -1
- package/dist/__tests__/slot.test.js +0 -147
- package/dist/__tests__/slot.test.js.map +0 -1
- package/dist/__tests__/synced.test.d.ts +0 -2
- package/dist/__tests__/synced.test.d.ts.map +0 -1
- package/dist/__tests__/synced.test.js +0 -161
- package/dist/__tests__/synced.test.js.map +0 -1
- package/dist/__tests__/until.test.d.ts +0 -2
- package/dist/__tests__/until.test.d.ts.map +0 -1
- package/dist/__tests__/until.test.js +0 -88
- package/dist/__tests__/until.test.js.map +0 -1
- package/dist/create-accessor-decorator.d.ts +0 -14
- package/dist/create-accessor-decorator.d.ts.map +0 -1
- package/dist/create-accessor-decorator.js +0 -27
- package/dist/create-accessor-decorator.js.map +0 -1
- package/src/__tests__/component.test.ts +0 -167
- package/src/__tests__/compose.test.ts +0 -202
- package/src/__tests__/deep-state.test.ts +0 -185
- package/src/__tests__/events.test.ts +0 -366
- package/src/__tests__/functions.test.ts +0 -803
- package/src/__tests__/lazy.test.ts +0 -296
- package/src/__tests__/memo.test.ts +0 -208
- package/src/__tests__/properties-browser.test.ts +0 -234
- package/src/__tests__/properties.test.ts +0 -1526
- package/src/__tests__/ref.test.ts +0 -131
- package/src/__tests__/resource.test.ts +0 -246
- package/src/__tests__/slot.test.ts +0 -179
- package/src/__tests__/synced.test.ts +0 -193
- package/src/__tests__/until.test.ts +0 -113
- package/src/create-accessor-decorator.ts +0 -45
- package/tsconfig.json +0 -9
package/dist/events/emit.js
CHANGED
|
@@ -1,29 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { sharedMethod } from "../shared-method";
|
|
2
2
|
import { readProp } from "./helper";
|
|
3
3
|
export function Emit(propName) {
|
|
4
|
-
return
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const result = original.apply(instance, args);
|
|
10
|
-
const callback = readProp(comp, propName);
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
12
|
-
if (typeof callback !== "function")
|
|
13
|
-
return result;
|
|
14
|
-
if (result !== undefined) {
|
|
15
|
-
callback(result);
|
|
16
|
-
}
|
|
17
|
-
else if (args.length > 0) {
|
|
18
|
-
callback(...args);
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
callback();
|
|
22
|
-
}
|
|
23
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
4
|
+
return function (value, context) {
|
|
5
|
+
return sharedMethod(context, value, function (...args) {
|
|
6
|
+
const result = value.apply(this, args);
|
|
7
|
+
const callback = readProp(this, propName);
|
|
8
|
+
if (typeof callback !== "function")
|
|
24
9
|
return result;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
10
|
+
if (result !== undefined) {
|
|
11
|
+
callback(result);
|
|
12
|
+
}
|
|
13
|
+
else if (args.length > 0) {
|
|
14
|
+
callback(...args);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
callback();
|
|
18
|
+
}
|
|
19
|
+
return result;
|
|
20
|
+
});
|
|
21
|
+
};
|
|
28
22
|
}
|
|
29
23
|
//# sourceMappingURL=emit.js.map
|
package/dist/events/emit.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emit.js","sourceRoot":"","sources":["../../src/events/emit.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"emit.js","sourceRoot":"","sources":["../../src/events/emit.ts"],"names":[],"mappings":"AAEA,OAAO,EAAsC,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACpF,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC,MAAM,UAAU,IAAI,CAAC,QAAgB;IACnC,OAAO,UAAU,KAAgB,EAAE,OAAsB;QACvD,OAAO,YAAY,CAAC,OAAO,EAAE,KAAK,EAAE,UAAmC,GAAG,IAAe;YACvF,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAY,CAAC;YAElD,MAAM,QAAQ,GAAG,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;YAC1C,IAAI,OAAO,QAAQ,KAAK,UAAU;gBAAE,OAAO,MAAM,CAAC;YAElD,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;gBACxB,QAAiC,CAAC,MAAM,CAAC,CAAC;YAC7C,CAAC;iBAAM,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC1B,QAAsC,CAAC,GAAG,IAAI,CAAC,CAAC;YACnD,CAAC;iBAAM,CAAC;gBACL,QAAuB,EAAE,CAAC;YAC7B,CAAC;YAED,OAAO,MAAM,CAAC;QAChB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import type { StatefulComponent } from "@praxisjs/core";
|
|
2
|
+
export declare function OnCommand(propName: string): (value: (this: StatefulComponent, ...args: any[]) => void, context: ClassMethodDecoratorContext<StatefulComponent, (this: StatefulComponent, ...args: any) => any>) => void;
|
|
2
3
|
//# sourceMappingURL=on-command.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"on-command.d.ts","sourceRoot":"","sources":["../../src/events/on-command.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"on-command.d.ts","sourceRoot":"","sources":["../../src/events/on-command.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAOxD,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,+KAoBzC"}
|
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { lifecycleMethodDecorator } from "../create-lifecycle-method-decorator";
|
|
2
2
|
import { readProp } from "./helper";
|
|
3
3
|
export function OnCommand(propName) {
|
|
4
|
-
return
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return command.subscribe((...args) => { callback(...args); });
|
|
16
|
-
},
|
|
4
|
+
return lifecycleMethodDecorator((instance, method) => {
|
|
5
|
+
const command = readProp(instance, propName);
|
|
6
|
+
if (!command) {
|
|
7
|
+
console.warn(`[OnCommand] prop "${propName}" was not provided to ${instance.constructor.name ?? "unknown"}`);
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
if (typeof command.subscribe !== "function") {
|
|
11
|
+
console.warn(`[OnCommand] prop "${propName}" is not a valid Command in ${instance.constructor.name ?? "unknown"}`);
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
return command.subscribe((...args) => { method.apply(instance, args); });
|
|
17
15
|
});
|
|
18
16
|
}
|
|
19
17
|
//# sourceMappingURL=on-command.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"on-command.js","sourceRoot":"","sources":["../../src/events/on-command.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"on-command.js","sourceRoot":"","sources":["../../src/events/on-command.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AAChF,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAIpC,MAAM,UAAU,SAAS,CAAC,QAAgB;IACxC,OAAO,wBAAwB,CAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE;QACtE,MAAM,OAAO,GAAG,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAiC,CAAC;QAE7E,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,CAAC,IAAI,CACV,qBAAqB,QAAQ,yBAA0B,QAAQ,CAAC,WAAiC,CAAC,IAAI,IAAI,SAAS,EAAE,CACtH,CAAC;YACF,OAAO;QACT,CAAC;QAED,IAAI,OAAO,OAAO,CAAC,SAAS,KAAK,UAAU,EAAE,CAAC;YAC5C,OAAO,CAAC,IAAI,CACV,qBAAqB,QAAQ,+BAAgC,QAAQ,CAAC,WAAiC,CAAC,IAAI,IAAI,SAAS,EAAE,CAC5H,CAAC;YACF,OAAO;QACT,CAAC;QAED,OAAO,OAAO,CAAC,SAAS,CAAC,CAAC,GAAG,IAAe,EAAE,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACtF,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/field.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { StatefulComponent } from "@praxisjs/core";
|
|
2
|
+
/**
|
|
3
|
+
* The signature of a field decorator: usable on fields of classes extending `Base` whose type is
|
|
4
|
+
* assignable to `Value`, so TypeScript rejects `@Clamp() name = ''` for a number-only decorator.
|
|
5
|
+
*/
|
|
6
|
+
export type FieldDecorator<Base = StatefulComponent, Value = unknown> = <This extends Base, V extends Value = Value>(value: undefined, context: ClassFieldDecoratorContext<This, V>) => void;
|
|
7
|
+
export type FieldHost = Record<PropertyKey, unknown>;
|
|
8
|
+
export declare function describeValue(value: unknown): string;
|
|
9
|
+
/**
|
|
10
|
+
* Throws when a decorator built for one kind of member is applied to another, naming the member,
|
|
11
|
+
* e.g. `@Confirm() decorates methods only, not the field "title".`
|
|
12
|
+
*/
|
|
13
|
+
export declare function assertMemberKind(context: {
|
|
14
|
+
readonly kind: DecoratorContext["kind"];
|
|
15
|
+
readonly name: string | symbol | undefined;
|
|
16
|
+
}, kind: DecoratorContext["kind"], decorator: string): void;
|
|
17
|
+
/**
|
|
18
|
+
* Throws when a field decorator is applied to anything but a plain class field. Above all an
|
|
19
|
+
* `accessor`: the decorator would install its property on the instance, shadowing the accessor,
|
|
20
|
+
* and decorators stacked on the same member would wrap the wrong thing.
|
|
21
|
+
*/
|
|
22
|
+
export declare function assertFieldContext(context: DecoratorContext, decorator?: string): void;
|
|
23
|
+
/**
|
|
24
|
+
* Lets the decorator lowering of `@praxisjs/vite-plugin` define a decorated field through its
|
|
25
|
+
* innermost decorator: an initializer added with `addClaimableInitializer` carries a `claim`
|
|
26
|
+
* function under this key, which installs the decorator's property directly with the field's
|
|
27
|
+
* initial value. The field is then never defined as a data property first, which in V8 would turn
|
|
28
|
+
* every instance into a slow dictionary-mode object when the accessor replaces it. Without the
|
|
29
|
+
* plugin (or under another decorator in the innermost position), the field is defined as usual and
|
|
30
|
+
* the initializer runs as an ordinary one.
|
|
31
|
+
*/
|
|
32
|
+
export declare const CLAIM: unique symbol;
|
|
33
|
+
/**
|
|
34
|
+
* Registers `claim` as the field's initializer: run as an ordinary extra initializer, it reads the
|
|
35
|
+
* value from the data property the field was defined with; the lowering can call it with the
|
|
36
|
+
* value instead (see CLAIM).
|
|
37
|
+
*/
|
|
38
|
+
export declare function addClaimableInitializer<This, Value>(context: ClassFieldDecoratorContext<This, Value>, claim: (this: This, value: Value) => void): void;
|
|
39
|
+
export interface SharedField {
|
|
40
|
+
/** Installed on every instance in place of the field. */
|
|
41
|
+
descriptor: PropertyDescriptor;
|
|
42
|
+
/** Runs per instance before the descriptor is installed, with the field's initial value. */
|
|
43
|
+
init?: (instance: FieldHost, initialValue: unknown) => void;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Builds a field decorator whose accessors are created once per decorated field (by `setup`, at
|
|
47
|
+
* class definition) and shared by every instance, which keeps its own state in symbol slots: all
|
|
48
|
+
* instances share one hidden class and building one allocates no closures.
|
|
49
|
+
*/
|
|
50
|
+
export declare function sharedField<Base = StatefulComponent>(setup: (name: string) => SharedField): FieldDecorator<Base>;
|
|
51
|
+
//# sourceMappingURL=field.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../src/field.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAExD;;;GAGG;AACH,MAAM,MAAM,cAAc,CAAC,IAAI,GAAG,iBAAiB,EAAE,KAAK,GAAG,OAAO,IAAI,CAAC,IAAI,SAAS,IAAI,EAAE,CAAC,SAAS,KAAK,GAAG,KAAK,EACjH,KAAK,EAAE,SAAS,EAChB,OAAO,EAAE,0BAA0B,CAAC,IAAI,EAAE,CAAC,CAAC,KACzC,IAAI,CAAC;AAEV,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;AAWrD,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAIpD;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE;IAAE,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;CAAE,EAChG,IAAI,EAAE,gBAAgB,CAAC,MAAM,CAAC,EAC9B,SAAS,EAAE,MAAM,GAChB,IAAI,CAON;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,gBAAgB,EAAE,SAAS,SAAyB,GAAG,IAAI,CAQtG;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,KAAK,eAAqC,CAAC;AAExD;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,KAAK,EACjD,OAAO,EAAE,0BAA0B,CAAC,IAAI,EAAE,KAAK,CAAC,EAChD,KAAK,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,KAAK,IAAI,GACxC,IAAI,CAON;AAED,MAAM,WAAW,WAAW;IAC1B,yDAAyD;IACzD,UAAU,EAAE,kBAAkB,CAAC;IAC/B,4FAA4F;IAC5F,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE,SAAS,EAAE,YAAY,EAAE,OAAO,KAAK,IAAI,CAAC;CAC7D;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,GAAG,iBAAiB,EAClD,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,WAAW,GACnC,cAAc,CAAC,IAAI,CAAC,CAatB"}
|
package/dist/field.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
const KIND_NAMES = {
|
|
2
|
+
class: "classes",
|
|
3
|
+
method: "methods",
|
|
4
|
+
getter: "getters",
|
|
5
|
+
setter: "setters",
|
|
6
|
+
field: "class fields",
|
|
7
|
+
accessor: "accessors",
|
|
8
|
+
};
|
|
9
|
+
export function describeValue(value) {
|
|
10
|
+
if (typeof value === "function")
|
|
11
|
+
return "a function";
|
|
12
|
+
if (typeof value === "object" && value !== null)
|
|
13
|
+
return "an object";
|
|
14
|
+
return String(value);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Throws when a decorator built for one kind of member is applied to another, naming the member,
|
|
18
|
+
* e.g. `@Confirm() decorates methods only, not the field "title".`
|
|
19
|
+
*/
|
|
20
|
+
export function assertMemberKind(context, kind, decorator) {
|
|
21
|
+
// A context without a kind was built by hand (decorators called directly in tests), not by a
|
|
22
|
+
// decorator application, which always has one.
|
|
23
|
+
if (context.kind === kind || context.kind === undefined)
|
|
24
|
+
return;
|
|
25
|
+
throw new TypeError(`${decorator} decorates ${KIND_NAMES[kind]} only, not the ${context.kind} "${String(context.name)}".`);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Throws when a field decorator is applied to anything but a plain class field. Above all an
|
|
29
|
+
* `accessor`: the decorator would install its property on the instance, shadowing the accessor,
|
|
30
|
+
* and decorators stacked on the same member would wrap the wrong thing.
|
|
31
|
+
*/
|
|
32
|
+
export function assertFieldContext(context, decorator = "This field decorator") {
|
|
33
|
+
if (context.kind === "field")
|
|
34
|
+
return;
|
|
35
|
+
const member = String(context.name);
|
|
36
|
+
throw new TypeError(context.kind === "accessor"
|
|
37
|
+
? `${decorator} decorates plain class fields only: remove \`accessor\` from "${member}".`
|
|
38
|
+
: `${decorator} decorates class fields only, not the ${context.kind} "${member}".`);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Lets the decorator lowering of `@praxisjs/vite-plugin` define a decorated field through its
|
|
42
|
+
* innermost decorator: an initializer added with `addClaimableInitializer` carries a `claim`
|
|
43
|
+
* function under this key, which installs the decorator's property directly with the field's
|
|
44
|
+
* initial value. The field is then never defined as a data property first, which in V8 would turn
|
|
45
|
+
* every instance into a slow dictionary-mode object when the accessor replaces it. Without the
|
|
46
|
+
* plugin (or under another decorator in the innermost position), the field is defined as usual and
|
|
47
|
+
* the initializer runs as an ordinary one.
|
|
48
|
+
*/
|
|
49
|
+
export const CLAIM = Symbol.for("praxisjs.field.claim");
|
|
50
|
+
/**
|
|
51
|
+
* Registers `claim` as the field's initializer: run as an ordinary extra initializer, it reads the
|
|
52
|
+
* value from the data property the field was defined with; the lowering can call it with the
|
|
53
|
+
* value instead (see CLAIM).
|
|
54
|
+
*/
|
|
55
|
+
export function addClaimableInitializer(context, claim) {
|
|
56
|
+
const name = context.name;
|
|
57
|
+
const init = function () {
|
|
58
|
+
claim.call(this, this[name]);
|
|
59
|
+
};
|
|
60
|
+
init[CLAIM] = claim;
|
|
61
|
+
context.addInitializer(init);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Builds a field decorator whose accessors are created once per decorated field (by `setup`, at
|
|
65
|
+
* class definition) and shared by every instance, which keeps its own state in symbol slots: all
|
|
66
|
+
* instances share one hidden class and building one allocates no closures.
|
|
67
|
+
*/
|
|
68
|
+
export function sharedField(setup) {
|
|
69
|
+
return function (_value, context) {
|
|
70
|
+
assertFieldContext(context);
|
|
71
|
+
const name = context.name;
|
|
72
|
+
const { descriptor, init } = setup(name);
|
|
73
|
+
descriptor.enumerable ??= true;
|
|
74
|
+
descriptor.configurable ??= true;
|
|
75
|
+
addClaimableInitializer(context, function (value) {
|
|
76
|
+
const instance = this;
|
|
77
|
+
init?.(instance, value);
|
|
78
|
+
Object.defineProperty(instance, name, descriptor);
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=field.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"field.js","sourceRoot":"","sources":["../src/field.ts"],"names":[],"mappings":"AAaA,MAAM,UAAU,GAA6C;IAC3D,KAAK,EAAE,SAAS;IAChB,MAAM,EAAE,SAAS;IACjB,MAAM,EAAE,SAAS;IACjB,MAAM,EAAE,SAAS;IACjB,KAAK,EAAE,cAAc;IACrB,QAAQ,EAAE,WAAW;CACtB,CAAC;AAEF,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,IAAI,OAAO,KAAK,KAAK,UAAU;QAAE,OAAO,YAAY,CAAC;IACrD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,WAAW,CAAC;IACpE,OAAO,MAAM,CAAC,KAAuE,CAAC,CAAC;AACzF,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAC9B,OAAgG,EAChG,IAA8B,EAC9B,SAAiB;IAEjB,6FAA6F;IAC7F,+CAA+C;IAC/C,IAAI,OAAO,CAAC,IAAI,KAAK,IAAI,IAAK,OAAO,CAAC,IAA2B,KAAK,SAAS;QAAE,OAAO;IACxF,MAAM,IAAI,SAAS,CACjB,GAAG,SAAS,cAAc,UAAU,CAAC,IAAI,CAAC,kBAAkB,OAAO,CAAC,IAAI,KAAK,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CACtG,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAyB,EAAE,SAAS,GAAG,sBAAsB;IAC9F,IAAI,OAAO,CAAC,IAAI,KAAK,OAAO;QAAE,OAAO;IACrC,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACpC,MAAM,IAAI,SAAS,CACjB,OAAO,CAAC,IAAI,KAAK,UAAU;QACzB,CAAC,CAAC,GAAG,SAAS,iEAAiE,MAAM,IAAI;QACzF,CAAC,CAAC,GAAG,SAAS,yCAAyC,OAAO,CAAC,IAAI,KAAK,MAAM,IAAI,CACrF,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;AAExD;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CACrC,OAAgD,EAChD,KAAyC;IAEzC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAC1B,MAAM,IAAI,GAAG;QACX,KAAK,CAAC,IAAI,CAAC,IAAI,EAAG,IAAkB,CAAC,IAAI,CAAU,CAAC,CAAC;IACvD,CAAwD,CAAC;IACzD,IAAI,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC;IACpB,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;AAC/B,CAAC;AASD;;;;GAIG;AACH,MAAM,UAAU,WAAW,CACzB,KAAoC;IAEpC,OAAO,UAAU,MAAM,EAAE,OAAO;QAC9B,kBAAkB,CAAC,OAAO,CAAC,CAAC;QAC5B,MAAM,IAAI,GAAG,OAAO,CAAC,IAAc,CAAC;QACpC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;QACzC,UAAU,CAAC,UAAU,KAAK,IAAI,CAAC;QAC/B,UAAU,CAAC,YAAY,KAAK,IAAI,CAAC;QACjC,uBAAuB,CAAC,OAAO,EAAE,UAAU,KAAK;YAC9C,MAAM,QAAQ,GAAG,IAA4B,CAAC;YAC9C,IAAI,EAAE,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;YACxB,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/functions/bind.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import { type AnyMethod, type MethodContext } from "../shared-method";
|
|
2
|
+
export declare function Bind(): (value: AnyMethod, context: MethodContext) => AnyMethod;
|
|
2
3
|
//# sourceMappingURL=bind.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bind.d.ts","sourceRoot":"","sources":["../../src/functions/bind.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bind.d.ts","sourceRoot":"","sources":["../../src/functions/bind.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,aAAa,EAAgB,MAAM,kBAAkB,CAAC;AAEpF,wBAAgB,IAAI,KACD,OAAO,SAAS,EAAE,SAAS,aAAa,KAAG,SAAS,CAGtE"}
|
package/dist/functions/bind.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { sharedMethod } from "../shared-method";
|
|
2
2
|
export function Bind() {
|
|
3
|
-
return
|
|
4
|
-
|
|
5
|
-
}
|
|
3
|
+
return function (value, context) {
|
|
4
|
+
return sharedMethod(context, value);
|
|
5
|
+
};
|
|
6
6
|
}
|
|
7
7
|
//# sourceMappingURL=bind.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bind.js","sourceRoot":"","sources":["../../src/functions/bind.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"bind.js","sourceRoot":"","sources":["../../src/functions/bind.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsC,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEpF,MAAM,UAAU,IAAI;IAClB,OAAO,UAAU,KAAgB,EAAE,OAAsB;QACvD,OAAO,YAAY,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACtC,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type
|
|
2
|
-
export declare function Debounce(ms: number): (value:
|
|
1
|
+
import { type AnyMethod, type MethodContext } from "../shared-method";
|
|
2
|
+
export declare function Debounce(ms: number): (value: AnyMethod, context: MethodContext) => AnyMethod;
|
|
3
3
|
//# sourceMappingURL=debounce.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debounce.d.ts","sourceRoot":"","sources":["../../src/functions/debounce.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"debounce.d.ts","sourceRoot":"","sources":["../../src/functions/debounce.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,aAAa,EAAgB,MAAM,kBAAkB,CAAC;AAIpF,wBAAgB,QAAQ,CAAC,EAAE,EAAE,MAAM,IAChB,OAAO,SAAS,EAAE,SAAS,aAAa,KAAG,SAAS,CAwBtE"}
|
|
@@ -1,26 +1,28 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { addLifecycleHooks } from "../lifecycle";
|
|
2
|
+
import { sharedMethod } from "../shared-method";
|
|
2
3
|
export function Debounce(ms) {
|
|
3
|
-
return
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
4
|
+
return function (value, context) {
|
|
5
|
+
// undefined: never called. null: called, nothing pending.
|
|
6
|
+
const timer = Symbol(`praxis.debounce.${String(context.name)}`);
|
|
7
|
+
function cancel(instance) {
|
|
8
|
+
const pending = instance[timer];
|
|
9
|
+
if (pending != null) {
|
|
10
|
+
clearTimeout(pending);
|
|
11
|
+
instance[timer] = null;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return sharedMethod(context, value, function (...args) {
|
|
15
|
+
const pending = this[timer];
|
|
16
|
+
// Only an instance that has called the method can have a timer to cancel on unmount.
|
|
17
|
+
if (pending === undefined)
|
|
18
|
+
addLifecycleHooks(this, undefined, cancel);
|
|
19
|
+
else if (pending !== null)
|
|
20
|
+
clearTimeout(pending);
|
|
21
|
+
this[timer] = setTimeout(() => {
|
|
22
|
+
this[timer] = null;
|
|
23
|
+
value.apply(this, args);
|
|
24
|
+
}, ms);
|
|
25
|
+
});
|
|
26
|
+
};
|
|
25
27
|
}
|
|
26
28
|
//# sourceMappingURL=debounce.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debounce.js","sourceRoot":"","sources":["../../src/functions/debounce.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"debounce.js","sourceRoot":"","sources":["../../src/functions/debounce.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAsC,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAIpF,MAAM,UAAU,QAAQ,CAAC,EAAU;IACjC,OAAO,UAAU,KAAgB,EAAE,OAAsB;QACvD,0DAA0D;QAC1D,MAAM,KAAK,GAAG,MAAM,CAAC,mBAAmB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAGhE,SAAS,MAAM,CAAC,QAAgB;YAC9B,MAAM,OAAO,GAAI,QAAiB,CAAC,KAAK,CAAC,CAAC;YAC1C,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;gBACpB,YAAY,CAAC,OAAO,CAAC,CAAC;gBACrB,QAAiB,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;YACnC,CAAC;QACH,CAAC;QAED,OAAO,YAAY,CAAC,OAAO,EAAE,KAAK,EAAE,UAAsB,GAAG,IAAe;YAC1E,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;YAC5B,qFAAqF;YACrF,IAAI,OAAO,KAAK,SAAS;gBAAE,iBAAiB,CAAC,IAAI,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;iBACjE,IAAI,OAAO,KAAK,IAAI;gBAAE,YAAY,CAAC,OAAO,CAAC,CAAC;YACjD,IAAI,CAAC,KAAK,CAAC,GAAG,UAAU,CAAC,GAAG,EAAE;gBAC5B,IAAI,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;gBACnB,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YAC1B,CAAC,EAAE,EAAE,CAAC,CAAC;QACT,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/functions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/functions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,KAAK,WAAW,EAAE,MAAM,QAAQ,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,KAAK,EAAE,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/functions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/functions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAoB,MAAM,QAAQ,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,KAAK,EAAiC,MAAM,SAAS,CAAC"}
|
package/dist/functions/log.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type AnyMethod, type MethodContext } from "../shared-method";
|
|
1
2
|
export interface LogOptions {
|
|
2
3
|
level?: "log" | "warn" | "error" | "debug";
|
|
3
4
|
args?: boolean;
|
|
@@ -5,5 +6,5 @@ export interface LogOptions {
|
|
|
5
6
|
time?: boolean;
|
|
6
7
|
devOnly?: boolean;
|
|
7
8
|
}
|
|
8
|
-
export declare function Log(options?: LogOptions): (value:
|
|
9
|
+
export declare function Log(options?: LogOptions): (value: AnyMethod, context: MethodContext) => AnyMethod;
|
|
9
10
|
//# sourceMappingURL=log.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../src/functions/log.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../src/functions/log.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,aAAa,EAAgB,MAAM,kBAAkB,CAAC;AAEpF,MAAM,WAAW,UAAU;IACzB,KAAK,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;IAC3C,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,wBAAgB,GAAG,CAAC,OAAO,GAAE,UAAe,IASzB,OAAO,SAAS,EAAE,SAAS,aAAa,KAAG,SAAS,CA2CtE"}
|
package/dist/functions/log.js
CHANGED
|
@@ -1,44 +1,42 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { sharedMethod } from "../shared-method";
|
|
2
2
|
export function Log(options = {}) {
|
|
3
3
|
const { level = "log", args: logArgs = true, result = true, time = false, devOnly = true, } = options;
|
|
4
|
-
return
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
},
|
|
42
|
-
});
|
|
4
|
+
return function (value, context) {
|
|
5
|
+
const name = String(context.name);
|
|
6
|
+
return sharedMethod(context, value, function (...args) {
|
|
7
|
+
if (devOnly &&
|
|
8
|
+
typeof process !== "undefined" &&
|
|
9
|
+
process.env.NODE_ENV === "production") {
|
|
10
|
+
return value.apply(this, args);
|
|
11
|
+
}
|
|
12
|
+
const className = this.constructor.name ?? "Unknown";
|
|
13
|
+
const label = `[${className}.${name}]`;
|
|
14
|
+
if (logArgs)
|
|
15
|
+
console[level](`${label} args:`, args);
|
|
16
|
+
const start = time ? performance.now() : 0;
|
|
17
|
+
const output = value.apply(this, args);
|
|
18
|
+
if (output instanceof Promise) {
|
|
19
|
+
return output
|
|
20
|
+
.then((resolved) => {
|
|
21
|
+
const elapsed = time
|
|
22
|
+
? ` (${(performance.now() - start).toFixed(2)}ms)`
|
|
23
|
+
: "";
|
|
24
|
+
if (result)
|
|
25
|
+
console[level](`${label} resolved:`, resolved, elapsed);
|
|
26
|
+
return resolved;
|
|
27
|
+
})
|
|
28
|
+
.catch((e) => {
|
|
29
|
+
console[level](`${label} rejected:`, e);
|
|
30
|
+
throw e;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
const elapsed = time
|
|
34
|
+
? ` (${(performance.now() - start).toFixed(2)}ms)`
|
|
35
|
+
: "";
|
|
36
|
+
if (result)
|
|
37
|
+
console[level](`${label} returned:`, output, elapsed);
|
|
38
|
+
return output;
|
|
39
|
+
});
|
|
40
|
+
};
|
|
43
41
|
}
|
|
44
42
|
//# sourceMappingURL=log.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.js","sourceRoot":"","sources":["../../src/functions/log.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"log.js","sourceRoot":"","sources":["../../src/functions/log.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsC,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAUpF,MAAM,UAAU,GAAG,CAAC,UAAsB,EAAE;IAC1C,MAAM,EACJ,KAAK,GAAG,KAAK,EACb,IAAI,EAAE,OAAO,GAAG,IAAI,EACpB,MAAM,GAAG,IAAI,EACb,IAAI,GAAG,KAAK,EACZ,OAAO,GAAG,IAAI,GACf,GAAG,OAAO,CAAC;IAEZ,OAAO,UAAU,KAAgB,EAAE,OAAsB;QACvD,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAClC,OAAO,YAAY,CAAC,OAAO,EAAE,KAAK,EAAE,UAAwB,GAAG,IAAe;YAC5E,IACE,OAAO;gBACP,OAAO,OAAO,KAAK,WAAW;gBAC9B,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EACrC,CAAC;gBACD,OAAO,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAY,CAAC;YAC5C,CAAC;YAED,MAAM,SAAS,GACZ,IAAI,CAAC,WAAiC,CAAC,IAAI,IAAI,SAAS,CAAC;YAC5D,MAAM,KAAK,GAAG,IAAI,SAAS,IAAI,IAAI,GAAG,CAAC;YAEvC,IAAI,OAAO;gBAAE,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,KAAK,QAAQ,EAAE,IAAI,CAAC,CAAC;YAEpD,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;YAC3C,MAAM,MAAM,GAAY,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAY,CAAC;YAE3D,IAAI,MAAM,YAAY,OAAO,EAAE,CAAC;gBAC9B,OAAQ,MAA2B;qBAChC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE;oBACjB,MAAM,OAAO,GAAG,IAAI;wBAClB,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK;wBAClD,CAAC,CAAC,EAAE,CAAC;oBACP,IAAI,MAAM;wBAAE,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,KAAK,YAAY,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;oBACpE,OAAO,QAAQ,CAAC;gBAClB,CAAC,CAAC;qBACD,KAAK,CAAC,CAAC,CAAU,EAAE,EAAE;oBACpB,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,KAAK,YAAY,EAAE,CAAC,CAAC,CAAC;oBACxC,MAAM,CAAC,CAAC;gBACV,CAAC,CAAC,CAAC;YACP,CAAC;YAED,MAAM,OAAO,GAAG,IAAI;gBAClB,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK;gBAClD,CAAC,CAAC,EAAE,CAAC;YACP,IAAI,MAAM;gBAAE,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,KAAK,YAAY,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;YAElE,OAAO,MAAM,CAAC;QAChB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/functions/memo.d.ts
CHANGED
|
@@ -1,2 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import { type AnyMethod, type MethodContext } from "../shared-method";
|
|
2
|
+
export interface MemoOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Maximum number of cached argument combinations. When exceeded, the least recently used entry
|
|
5
|
+
* is dropped. Defaults to 100; pass `Infinity` to keep every combination.
|
|
6
|
+
*/
|
|
7
|
+
max?: number;
|
|
8
|
+
}
|
|
9
|
+
export declare function Memo(options?: MemoOptions): (value: AnyMethod, context: MethodContext) => AnyMethod;
|
|
2
10
|
//# sourceMappingURL=memo.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memo.d.ts","sourceRoot":"","sources":["../../src/functions/memo.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"memo.d.ts","sourceRoot":"","sources":["../../src/functions/memo.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,aAAa,EAAgB,MAAM,kBAAkB,CAAC;AA+BpF,MAAM,WAAW,WAAW;IAC1B;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAMD,wBAAgB,IAAI,CAAC,OAAO,GAAE,WAAgB,IAG3B,OAAO,SAAS,EAAE,SAAS,aAAa,KAAG,SAAS,CAwBtE"}
|
package/dist/functions/memo.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { computed } from "@praxisjs/core/internal";
|
|
2
|
-
import {
|
|
2
|
+
import { sharedMethod } from "../shared-method";
|
|
3
3
|
const objectIdMap = new WeakMap();
|
|
4
4
|
let objectIdCounter = 0;
|
|
5
5
|
function objectIdentityKey(obj) {
|
|
@@ -8,39 +8,53 @@ function objectIdentityKey(obj) {
|
|
|
8
8
|
}
|
|
9
9
|
return `__obj_${String(objectIdMap.get(obj))}__`;
|
|
10
10
|
}
|
|
11
|
+
function serializeArg(a) {
|
|
12
|
+
if (a === null || typeof a === "object") {
|
|
13
|
+
try {
|
|
14
|
+
return JSON.stringify(a);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return objectIdentityKey(a);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (typeof a === "symbol")
|
|
21
|
+
return a.toString();
|
|
22
|
+
return String(a);
|
|
23
|
+
}
|
|
11
24
|
function serializeArgs(args) {
|
|
12
25
|
if (args.length === 0)
|
|
13
26
|
return "__no_args__";
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return JSON.stringify(a);
|
|
19
|
-
}
|
|
20
|
-
catch {
|
|
21
|
-
return objectIdentityKey(a);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
if (typeof a === "symbol")
|
|
25
|
-
return a.toString();
|
|
26
|
-
return String(a);
|
|
27
|
-
})
|
|
28
|
-
.join("|");
|
|
27
|
+
// The common single-argument call skips the intermediate array and join.
|
|
28
|
+
if (args.length === 1)
|
|
29
|
+
return serializeArg(args[0]);
|
|
30
|
+
return args.map(serializeArg).join("|");
|
|
29
31
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
32
|
+
const DEFAULT_MAX = 100;
|
|
33
|
+
export function Memo(options = {}) {
|
|
34
|
+
const { max = DEFAULT_MAX } = options;
|
|
35
|
+
return function (value, context) {
|
|
36
|
+
const caches = Symbol(`praxis.memo.${String(context.name)}`);
|
|
37
|
+
return sharedMethod(context, value, function (...args) {
|
|
38
|
+
const cache = (this[caches] ??= new Map());
|
|
39
|
+
const key = serializeArgs(args);
|
|
40
|
+
let memoized = cache.get(key);
|
|
41
|
+
if (memoized) {
|
|
42
|
+
// Re-insert so Map order tracks recency.
|
|
43
|
+
cache.delete(key);
|
|
44
|
+
cache.set(key, memoized);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
memoized = computed(() => value.apply(this, args));
|
|
48
|
+
cache.set(key, memoized);
|
|
49
|
+
if (cache.size > max) {
|
|
50
|
+
const [oldestKey, oldest] = cache.entries().next().value;
|
|
51
|
+
cache.delete(oldestKey);
|
|
52
|
+
// Releases the entry's hold on the signals it read; a no-op if a binding still uses it.
|
|
53
|
+
oldest.dispose();
|
|
40
54
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
}
|
|
55
|
+
}
|
|
56
|
+
return memoized();
|
|
57
|
+
});
|
|
58
|
+
};
|
|
45
59
|
}
|
|
46
60
|
//# sourceMappingURL=memo.js.map
|