@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
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Composable } from "@praxisjs/core";
|
|
2
|
+
import { type FieldDecorator } from "../field";
|
|
2
3
|
interface ComposeFactory {
|
|
3
4
|
__isComposeFactory: true;
|
|
4
5
|
resolve: (instance: object) => unknown;
|
|
5
6
|
}
|
|
6
7
|
/** Wraps a property as a live getter — passes `() => instance[propName]` to the composable. */
|
|
7
8
|
export declare function getter(propName: string): ComposeFactory;
|
|
8
|
-
export declare function Compose(ComposableClass: new (...args: any[]) => Composable, ...ctorArgs: unknown[]):
|
|
9
|
+
export declare function Compose(ComposableClass: new (...args: any[]) => Composable, ...ctorArgs: unknown[]): FieldDecorator;
|
|
9
10
|
export {};
|
|
10
11
|
//# sourceMappingURL=compose.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compose.d.ts","sourceRoot":"","sources":["../../src/properties/compose.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"compose.d.ts","sourceRoot":"","sources":["../../src/properties/compose.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjD,OAAO,EAAE,KAAK,cAAc,EAA+B,MAAM,UAAU,CAAC;AAG5E,UAAU,cAAc;IAAG,kBAAkB,EAAE,IAAI,CAAC;IAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAA;CAAE;AAE7F,+FAA+F;AAC/F,wBAAgB,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc,CAKvD;AA6BD,wBAAgB,OAAO,CAErB,eAAe,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,UAAU,EACnD,GAAG,QAAQ,EAAE,OAAO,EAAE,GACrB,cAAc,CAgChB"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { sharedField } from "../field";
|
|
2
|
+
import { addLifecycleHooks } from "../lifecycle";
|
|
2
3
|
/** Wraps a property as a live getter — passes `() => instance[propName]` to the composable. */
|
|
3
4
|
export function getter(propName) {
|
|
4
5
|
return {
|
|
@@ -32,24 +33,37 @@ function buildView(bindings) {
|
|
|
32
33
|
export function Compose(
|
|
33
34
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
34
35
|
ComposableClass, ...ctorArgs) {
|
|
35
|
-
return
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
36
|
+
return sharedField((name) => {
|
|
37
|
+
const composableSlot = Symbol(`praxis.composable.${name}`);
|
|
38
|
+
const viewSlot = Symbol(`praxis.compose.${name}`);
|
|
39
|
+
const composableOf = (instance) => instance[composableSlot];
|
|
40
|
+
const mount = (instance) => { composableOf(instance).onMount?.(); };
|
|
41
|
+
const unmount = (instance) => { composableOf(instance).onUnmount?.(); };
|
|
42
|
+
return {
|
|
43
|
+
descriptor: {
|
|
44
|
+
get() {
|
|
45
|
+
return this[viewSlot];
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
init(instance) {
|
|
49
|
+
const resolvedArgs = ctorArgs.map((arg) => {
|
|
50
|
+
if (isFactory(arg))
|
|
51
|
+
return arg.resolve(instance);
|
|
52
|
+
if (typeof arg !== "string")
|
|
53
|
+
return arg;
|
|
54
|
+
const prop = instance[arg];
|
|
55
|
+
return prop !== undefined ? prop : arg;
|
|
56
|
+
});
|
|
57
|
+
const composable = new ComposableClass(...resolvedArgs);
|
|
58
|
+
instance[composableSlot] = composable;
|
|
59
|
+
instance[viewSlot] = buildView(composable.setup());
|
|
60
|
+
const hasMount = typeof composable.onMount === "function";
|
|
61
|
+
const hasUnmount = typeof composable.onUnmount === "function";
|
|
62
|
+
if (hasMount || hasUnmount) {
|
|
63
|
+
addLifecycleHooks(instance, hasMount ? mount : undefined, hasUnmount ? unmount : undefined);
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
};
|
|
53
67
|
});
|
|
54
68
|
}
|
|
55
69
|
//# sourceMappingURL=compose.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compose.js","sourceRoot":"","sources":["../../src/properties/compose.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"compose.js","sourceRoot":"","sources":["../../src/properties/compose.ts"],"names":[],"mappings":"AAEA,OAAO,EAAuC,WAAW,EAAE,MAAM,UAAU,CAAC;AAC5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAIjD,+FAA+F;AAC/F,MAAM,UAAU,MAAM,CAAC,QAAgB;IACrC,OAAO;QACL,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,GAAG,EAAE,CAAE,QAAoC,CAAC,QAAQ,CAAC;KAC7E,CAAC;AACJ,CAAC;AAED,SAAS,SAAS,CAAC,KAAc;IAC/B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,oBAAoB,IAAI,KAAK,CAAC;AACtF,CAAC;AAED,SAAS,UAAU,CAAC,KAAc;IAChC,OAAO,CACL,OAAO,KAAK,KAAK,UAAU;QAC3B,CAAC,YAAY,IAAK,KAAgB,IAAI,cAAc,IAAK,KAAgB,CAAC,CAC3E,CAAC;AACJ,CAAC;AAED,SAAS,SAAS,CAAC,QAAiC;IAClD,MAAM,IAAI,GAA4B,EAAE,CAAC;IACzC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QACpD,IAAI,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;YACtB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,EAAE;gBAC/B,GAAG,EAAE,GAAG,EA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CAAC;oBAC3B,OAAO,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC;gBACzC,CAAC,CAAC,CAAC;gBAEH,MAAM,UAAU,GAAG,IAAI,eAAe,CAAC,GAAG,YAAY,CAAC,CAAC;gBACxD,QAAQ,CAAC,cAAc,CAAC,GAAG,UAAU,CAAC;gBACtC,QAAQ,CAAC,QAAQ,CAAC,GAAG,SAAS,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC;gBACnD,MAAM,QAAQ,GAAG,OAAO,UAAU,CAAC,OAAO,KAAK,UAAU,CAAC;gBAC1D,MAAM,UAAU,GAAG,OAAO,UAAU,CAAC,SAAS,KAAK,UAAU,CAAC;gBAC9D,IAAI,QAAQ,IAAI,UAAU,EAAE,CAAC;oBAC3B,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;gBAC9F,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { type GetterDecorator } from "../create-getter-decorator";
|
|
2
|
+
export interface ComputedOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Handles writes to the property. A `set` accessor declared next to the getter in the class
|
|
5
|
+
* does the same, and TypeScript sees it.
|
|
6
|
+
*/
|
|
7
|
+
set?(this: object, value: unknown): void;
|
|
4
8
|
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export declare function Computed(options?:
|
|
10
|
-
set?: (this: object, value: unknown) => void;
|
|
11
|
-
}): <This, R>(target: (this: This) => R, context: ClassGetterDecoratorContext<This, R>) => (this: This) => R;
|
|
9
|
+
/**
|
|
10
|
+
* Caches a getter as a reactive computed. A `set` accessor declared next to the getter makes the
|
|
11
|
+
* property writable.
|
|
12
|
+
*/
|
|
13
|
+
export declare function Computed(options?: ComputedOptions): GetterDecorator;
|
|
12
14
|
//# sourceMappingURL=computed.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"computed.d.ts","sourceRoot":"","sources":["../../src/properties/computed.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"computed.d.ts","sourceRoot":"","sources":["../../src/properties/computed.ts"],"names":[],"mappings":"AAEA,OAAO,EAAyB,KAAK,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAEzF,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;CAC1C;AASD;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,OAAO,CAAC,EAAE,eAAe,GAAG,eAAe,CAqBnE"}
|
|
@@ -1,26 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { ComputedNode, readComputed } from "@praxisjs/core/internal";
|
|
2
|
+
import { createGetterDecorator } from "../create-getter-decorator";
|
|
3
|
+
// Kept out of the getter: a closure created inside it would make every read allocate a context.
|
|
4
|
+
function computedFor(instance, getter) {
|
|
5
|
+
return new ComputedNode(() => getter.call(instance));
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Caches a getter as a reactive computed. A `set` accessor declared next to the getter makes the
|
|
9
|
+
* property writable.
|
|
10
|
+
*/
|
|
4
11
|
export function Computed(options) {
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return {
|
|
12
|
-
get: c,
|
|
13
|
-
set: optionsSet ? (value) => { optionsSet.call(instance, value); } : undefined,
|
|
14
|
-
};
|
|
15
|
-
},
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
return createWritableGetterDecorator({
|
|
19
|
-
bind(instance, _name, original) {
|
|
20
|
-
const c = computed(() => original.call(instance));
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method -- installed on the class, which calls it with the instance as `this`
|
|
13
|
+
const set = options?.set;
|
|
14
|
+
return createGetterDecorator({
|
|
15
|
+
label: "@Computed()",
|
|
16
|
+
setup(original, context) {
|
|
17
|
+
const node = Symbol(`praxis.computed.${String(context.name)}`);
|
|
21
18
|
return {
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
// Shared by every instance; the computed itself is only created the first time it is read,
|
|
20
|
+
// so a getter that a component never reads costs nothing beyond its slot.
|
|
21
|
+
get() {
|
|
22
|
+
return readComputed((this[node] ??= computedFor(this, original)));
|
|
23
|
+
},
|
|
24
|
+
set,
|
|
25
|
+
init(instance) {
|
|
26
|
+
// The slot is created up front so every instance keeps the same shape.
|
|
27
|
+
instance[node] = undefined;
|
|
28
|
+
},
|
|
24
29
|
};
|
|
25
30
|
},
|
|
26
31
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"computed.js","sourceRoot":"","sources":["../../src/properties/computed.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"computed.js","sourceRoot":"","sources":["../../src/properties/computed.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAErE,OAAO,EAAE,qBAAqB,EAAwB,MAAM,4BAA4B,CAAC;AAYzF,gGAAgG;AAChG,SAAS,WAAW,CAAI,QAAW,EAAE,MAA4B;IAC/D,OAAO,IAAI,YAAY,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;AACvD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,QAAQ,CAAC,OAAyB;IAChD,mIAAmI;IACnI,MAAM,GAAG,GAAG,OAAO,EAAE,GAAG,CAAC;IACzB,OAAO,qBAAqB,CAAO;QACjC,KAAK,EAAE,aAAa;QACpB,KAAK,CAAC,QAAQ,EAAE,OAAO;YACrB,MAAM,IAAI,GAAG,MAAM,CAAC,mBAAmB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAC/D,OAAO;gBACL,2FAA2F;gBAC3F,0EAA0E;gBAC1E,GAAG;oBACD,OAAO,YAAY,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,WAAW,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;gBACpE,CAAC;gBACD,GAAG;gBACH,IAAI,CAAC,QAAQ;oBACX,uEAAuE;oBACvE,QAAQ,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC;gBAC7B,CAAC;aACF,CAAC;QACJ,CAAC;KACF,CAAoB,CAAC;AACxB,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type FieldDecorator } from "../field";
|
|
1
2
|
import type { ReactiveHost } from "../reactive-host";
|
|
2
|
-
export declare function DeepState(): <
|
|
3
|
+
export declare function DeepState(): FieldDecorator<ReactiveHost>;
|
|
3
4
|
//# sourceMappingURL=deep-state.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deep-state.d.ts","sourceRoot":"","sources":["../../src/properties/deep-state.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"deep-state.d.ts","sourceRoot":"","sources":["../../src/properties/deep-state.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,cAAc,EAA+B,MAAM,UAAU,CAAC;AAE5E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAmDrD,wBAAgB,SAAS,IAAI,cAAc,CAAC,YAAY,CAAC,CAqBxD"}
|
|
@@ -1,55 +1,72 @@
|
|
|
1
|
-
import { markStateDirty,
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
import { markStateDirty, readSignal, SignalNode, writeSignal } from "@praxisjs/core/internal";
|
|
2
|
+
import { sharedField } from "../field";
|
|
3
|
+
// One per decorated field per instance. It is also the handler of every proxy it hands out, so
|
|
4
|
+
// proxying a nested object allocates only the Proxy itself.
|
|
5
|
+
class DeepStateCell {
|
|
6
|
+
host;
|
|
7
|
+
version = new SignalNode(0);
|
|
8
|
+
// One proxy per raw object: repeated reads return the same reference (so `a.b === a.b` and
|
|
9
|
+
// identity comparisons in effects hold) and don't allocate a new Proxy on every access.
|
|
10
|
+
proxies = undefined;
|
|
11
|
+
current;
|
|
12
|
+
constructor(host, value) {
|
|
13
|
+
this.host = host;
|
|
14
|
+
this.current = this.wrap(value);
|
|
15
|
+
}
|
|
16
|
+
wrap(value) {
|
|
17
|
+
if (value === null || typeof value !== "object")
|
|
18
|
+
return value;
|
|
19
|
+
const proxies = (this.proxies ??= new WeakMap());
|
|
20
|
+
let proxy = proxies.get(value);
|
|
21
|
+
if (proxy === undefined) {
|
|
22
|
+
proxy = new Proxy(value, this);
|
|
23
|
+
proxies.set(value, proxy);
|
|
24
|
+
}
|
|
25
|
+
return proxy;
|
|
26
|
+
}
|
|
27
|
+
changed() {
|
|
28
|
+
markStateDirty(this.host);
|
|
29
|
+
writeSignal(this.version, this.version.value + 1);
|
|
30
|
+
}
|
|
31
|
+
get(obj, key, receiver) {
|
|
32
|
+
return this.wrap(Reflect.get(obj, key, receiver));
|
|
33
|
+
}
|
|
34
|
+
set(obj, key, value) {
|
|
35
|
+
const had = Object.hasOwn(obj, key);
|
|
36
|
+
const prev = Reflect.get(obj, key);
|
|
37
|
+
const result = Reflect.set(obj, key, value);
|
|
38
|
+
if (!had || !Object.is(prev, value))
|
|
39
|
+
this.changed();
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
deleteProperty(obj, key) {
|
|
43
|
+
const had = Object.hasOwn(obj, key);
|
|
44
|
+
const result = Reflect.deleteProperty(obj, key);
|
|
45
|
+
if (had)
|
|
46
|
+
this.changed();
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
23
49
|
}
|
|
24
50
|
export function DeepState() {
|
|
25
|
-
return
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
get() {
|
|
39
|
-
version();
|
|
40
|
-
return proxy;
|
|
41
|
-
},
|
|
42
|
-
set(value) {
|
|
43
|
-
current = value;
|
|
44
|
-
proxy =
|
|
45
|
-
value !== null && typeof value === "object"
|
|
46
|
-
? deepProxy(value, notify)
|
|
47
|
-
: value;
|
|
48
|
-
notify();
|
|
49
|
-
},
|
|
51
|
+
return sharedField((name) => {
|
|
52
|
+
const slot = Symbol(`praxis.deepState.${name}`);
|
|
53
|
+
return {
|
|
54
|
+
descriptor: {
|
|
55
|
+
get() {
|
|
56
|
+
const cell = this[slot];
|
|
57
|
+
readSignal(cell.version);
|
|
58
|
+
return cell.current;
|
|
59
|
+
},
|
|
60
|
+
set(value) {
|
|
61
|
+
const cell = this[slot];
|
|
62
|
+
cell.current = cell.wrap(value);
|
|
63
|
+
cell.changed();
|
|
50
64
|
},
|
|
51
|
-
}
|
|
52
|
-
|
|
65
|
+
},
|
|
66
|
+
init(instance, initialValue) {
|
|
67
|
+
instance[slot] = new DeepStateCell(instance, initialValue);
|
|
68
|
+
},
|
|
69
|
+
};
|
|
53
70
|
});
|
|
54
71
|
}
|
|
55
72
|
//# sourceMappingURL=deep-state.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deep-state.js","sourceRoot":"","sources":["../../src/properties/deep-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"deep-state.js","sourceRoot":"","sources":["../../src/properties/deep-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE9F,OAAO,EAAuC,WAAW,EAAE,MAAM,UAAU,CAAC;AAI5E,+FAA+F;AAC/F,4DAA4D;AAC5D,MAAM,aAAa;IAOY;IANpB,OAAO,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;IACrC,2FAA2F;IAC3F,wFAAwF;IAChF,OAAO,GAAwC,SAAS,CAAC;IACjE,OAAO,CAAU;IAEjB,YAA6B,IAAY,EAAE,KAAc;QAA5B,SAAI,GAAJ,IAAI,CAAQ;QACvC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;IAED,IAAI,CAAC,KAAc;QACjB,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ;YAAE,OAAO,KAAK,CAAC;QAC9D,MAAM,OAAO,GAAG,CAAC,IAAI,CAAC,OAAO,KAAK,IAAI,OAAO,EAAE,CAAC,CAAC;QACjD,IAAI,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAC/B,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,KAAK,GAAG,IAAI,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;YAC/B,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAC5B,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO;QACL,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1B,WAAW,CAAC,IAAI,C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oBACzC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;oBACzB,OAAO,IAAI,CAAC,OAAO,CAAC;gBACtB,CAAC;gBACD,GAAG,CAAkB,KAAc;oBACjC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAkB,CAAC;oBACzC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;oBAChC,IAAI,CAAC,OAAO,EAAE,CAAC;gBACjB,CAAC;aACF;YACD,IAAI,CAAC,QAAQ,EAAE,YAAY;gBACzB,QAAQ,CAAC,IAAI,CAAC,GAAG,IAAI,aAAa,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;YAC7D,CAAC;SACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import { type FieldDecorator } from "../field";
|
|
2
|
+
export declare function FunctionProp(): FieldDecorator;
|
|
2
3
|
//# sourceMappingURL=function-prop.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"function-prop.d.ts","sourceRoot":"","sources":["../../src/properties/function-prop.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"function-prop.d.ts","sourceRoot":"","sources":["../../src/properties/function-prop.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,cAAc,EAA+B,MAAM,UAAU,CAAC;AAE5E,wBAAgB,YAAY,IAAI,cAAc,CA0B7C"}
|
|
@@ -1,28 +1,26 @@
|
|
|
1
1
|
import { getComponentDefault, getComponentRawProp, setComponentDefault, } from "@praxisjs/core/internal";
|
|
2
|
-
import {
|
|
2
|
+
import { sharedField } from "../field";
|
|
3
3
|
export function FunctionProp() {
|
|
4
|
-
return
|
|
5
|
-
|
|
4
|
+
return sharedField((name) => ({
|
|
5
|
+
descriptor: {
|
|
6
|
+
get() {
|
|
7
|
+
const fromParent = getComponentRawProp(this, name);
|
|
8
|
+
if (fromParent !== undefined) {
|
|
9
|
+
if (process.env.NODE_ENV !== "production" &&
|
|
10
|
+
typeof fromParent !== "function") {
|
|
11
|
+
console.warn(`[FunctionProp] "${name}" received a non-function value (${typeof fromParent}). @FunctionProp() expects a function.`);
|
|
12
|
+
}
|
|
13
|
+
return fromParent;
|
|
14
|
+
}
|
|
15
|
+
return getComponentDefault(this, name);
|
|
16
|
+
},
|
|
17
|
+
set(value) {
|
|
18
|
+
setComponentDefault(this, name, value);
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
init(instance, initialValue) {
|
|
6
22
|
setComponentDefault(instance, name, initialValue);
|
|
7
|
-
return {
|
|
8
|
-
descriptor: {
|
|
9
|
-
get() {
|
|
10
|
-
const fromParent = getComponentRawProp(instance, name);
|
|
11
|
-
if (fromParent !== undefined) {
|
|
12
|
-
if (process.env.NODE_ENV !== "production" &&
|
|
13
|
-
typeof fromParent !== "function") {
|
|
14
|
-
console.warn(`[FunctionProp] "${name}" received a non-function value (${typeof fromParent}). @FunctionProp() expects a function.`);
|
|
15
|
-
}
|
|
16
|
-
return fromParent;
|
|
17
|
-
}
|
|
18
|
-
return getComponentDefault(instance, name);
|
|
19
|
-
},
|
|
20
|
-
set(value) {
|
|
21
|
-
setComponentDefault(instance, name, value);
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
};
|
|
25
23
|
},
|
|
26
|
-
});
|
|
24
|
+
}));
|
|
27
25
|
}
|
|
28
26
|
//# sourceMappingURL=function-prop.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"function-prop.js","sourceRoot":"","sources":["../../src/properties/function-prop.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,
|
|
1
|
+
{"version":3,"file":"function-prop.js","sourceRoot":"","sources":["../../src/properties/function-prop.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAuC,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5E,MAAM,UAAU,YAAY;IAC1B,OAAO,WAAW,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAC5B,UAAU,EAAE;YACV,GAAG;gBACD,MAAM,UAAU,GAAG,mBAAmB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;gBACnD,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;oBAC7B,IACE,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;wBACrC,OAAO,UAAU,KAAK,UAAU,EAChC,CAAC;wBACD,OAAO,CAAC,IAAI,CACV,mBAAmB,IAAI,oCAAoC,OAAO,UAAU,wCAAwC,CACrH,CAAC;oBACJ,CAAC;oBACD,OAAO,UAAU,CAAC;gBACpB,CAAC;gBACD,OAAO,mBAAmB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YACzC,CAAC;YACD,GAAG,CAAkB,KAAc;gBACjC,mBAAmB,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;YACzC,CAAC;SACF;QACD,IAAI,CAAC,QAAQ,EAAE,YAAY;YACzB,mBAAmB,CAAC,QAAQ,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC;QACpD,CAAC;KACF,CAAC,CAAC,CAAC;AACN,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { StatefulComponent } from "@praxisjs/core";
|
|
2
1
|
import { type HistoryElement } from "@praxisjs/core/internal";
|
|
2
|
+
import { type FieldDecorator } from "../field";
|
|
3
3
|
export type HistoryOf<C, K extends keyof C> = HistoryElement<C[K]>;
|
|
4
|
-
export declare function History(fieldName: string, limit?: number):
|
|
4
|
+
export declare function History(fieldName: string, limit?: number): FieldDecorator;
|
|
5
5
|
//# sourceMappingURL=history.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"history.d.ts","sourceRoot":"","sources":["../../src/properties/history.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"history.d.ts","sourceRoot":"","sources":["../../src/properties/history.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAW,MAAM,yBAAyB,CAAC;AAGvE,OAAO,EAAE,KAAK,cAAc,EAA+B,MAAM,UAAU,CAAC;AAG5E,MAAM,MAAM,SAAS,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAmBnE,wBAAgB,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,SAAK,GAAG,cAAc,CAkBrE"}
|
|
@@ -1,37 +1,40 @@
|
|
|
1
1
|
import { history } from "@praxisjs/core/internal";
|
|
2
|
-
import {
|
|
2
|
+
import { sharedField } from "../field";
|
|
3
|
+
import { addLifecycleHooks } from "../lifecycle";
|
|
4
|
+
function createHistory(host, fieldName, limit) {
|
|
5
|
+
const h = history((() => host[fieldName]), limit);
|
|
6
|
+
const undo = h.undo.bind(h);
|
|
7
|
+
const redo = h.redo.bind(h);
|
|
8
|
+
h.undo = () => {
|
|
9
|
+
const prev = h.values()[h.values().length - 2];
|
|
10
|
+
if (prev === undefined)
|
|
11
|
+
return;
|
|
12
|
+
undo();
|
|
13
|
+
host[fieldName] = prev;
|
|
14
|
+
};
|
|
15
|
+
h.redo = () => {
|
|
16
|
+
redo();
|
|
17
|
+
host[fieldName] = h.current();
|
|
18
|
+
};
|
|
19
|
+
return h;
|
|
20
|
+
}
|
|
3
21
|
export function History(fieldName, limit = 50) {
|
|
4
|
-
return
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const _undo = hInst.undo.bind(hInst);
|
|
15
|
-
const _redo = hInst.redo.bind(hInst);
|
|
16
|
-
hInst.undo = () => {
|
|
17
|
-
const prev = hInst.values()[hInst.values().length - 2];
|
|
18
|
-
if (prev === undefined)
|
|
19
|
-
return;
|
|
20
|
-
_undo();
|
|
21
|
-
inst[fieldName] = prev;
|
|
22
|
-
};
|
|
23
|
-
hInst.redo = () => {
|
|
24
|
-
_redo();
|
|
25
|
-
inst[fieldName] = hInst.current();
|
|
26
|
-
};
|
|
27
|
-
h = hInst;
|
|
28
|
-
}
|
|
29
|
-
return h;
|
|
30
|
-
},
|
|
31
|
-
enumerable: false,
|
|
22
|
+
return sharedField((name) => {
|
|
23
|
+
const slot = Symbol(`praxis.history.${name}`);
|
|
24
|
+
// The tracking effect would otherwise keep recording a source that outlives the component.
|
|
25
|
+
const destroy = (instance) => { instance[slot]?.destroy(); };
|
|
26
|
+
return {
|
|
27
|
+
descriptor: {
|
|
28
|
+
enumerable: false,
|
|
29
|
+
// Created on first read, so an instance whose history is never read records nothing.
|
|
30
|
+
get() {
|
|
31
|
+
return (this[slot] ??= createHistory(this, fieldName, limit));
|
|
32
32
|
},
|
|
33
|
-
}
|
|
34
|
-
|
|
33
|
+
},
|
|
34
|
+
init(instance) {
|
|
35
|
+
addLifecycleHooks(instance, undefined, destroy);
|
|
36
|
+
},
|
|
37
|
+
};
|
|
35
38
|
});
|
|
36
39
|
}
|
|
37
40
|
//# sourceMappingURL=history.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"history.js","sourceRoot":"","sources":["../../src/properties/history.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"history.js","sourceRoot":"","sources":["../../src/properties/history.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAGvE,OAAO,EAAuC,WAAW,EAAE,MAAM,UAAU,CAAC;AAC5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAIjD,SAAS,aAAa,CAAC,IA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AAC,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC;gBAChE,CAAC;aACF;YACD,IAAI,CAAC,QAAQ;gBACX,iBAAiB,CAAC,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;YAClD,CAAC;SACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -10,4 +10,5 @@ export { Resource, invalidateResource, type ResourceInstance, type ResourceOptio
|
|
|
10
10
|
export { Synced } from "./synced";
|
|
11
11
|
export { DeepState } from "./deep-state";
|
|
12
12
|
export { Ref, createRef } from "./ref";
|
|
13
|
+
export { Selector, type SelectorOptions } from "./selector";
|
|
13
14
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/properties/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,KAAK,gBAAgB,EAAE,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AACvG,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/properties/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,KAAK,gBAAgB,EAAE,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AACvG,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/properties/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/properties/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,EAAE,OAAO,EAAkB,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAA+C,MAAM,YAAY,CAAC;AACvG,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/properties/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,EAAE,OAAO,EAAkB,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAA+C,MAAM,YAAY,CAAC;AACvG,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAwB,MAAM,YAAY,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { type PersistedSignalOptions } from "@praxisjs/core/internal";
|
|
2
|
-
|
|
2
|
+
import { type FieldDecorator } from "../field";
|
|
3
|
+
export declare function Persisted<T>(key?: string, options?: PersistedSignalOptions<T>): FieldDecorator;
|
|
3
4
|
//# sourceMappingURL=persisted.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"persisted.d.ts","sourceRoot":"","sources":["../../src/properties/persisted.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"persisted.d.ts","sourceRoot":"","sources":["../../src/properties/persisted.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,sBAAsB,EAC5B,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,KAAK,cAAc,EAA+B,MAAM,UAAU,CAAC;AA0B5E,wBAAgB,SAAS,CAAC,CAAC,EACzB,GAAG,CAAC,EAAE,MAAM,EACZ,OAAO,GAAE,sBAAsB,CAAC,CAAC,CAAM,GACtC,cAAc,CAqBhB"}
|