@praxisjs/decorators 1.7.0 → 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 +33 -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/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 +2 -1
- package/dist/functions/memo.d.ts.map +1 -1
- package/dist/functions/memo.js +41 -40
- 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 +5 -5
- 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 -60
- 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 -33
- 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 +24 -18
- 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/log.ts +44 -46
- package/src/functions/memo.ts +39 -37
- 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 +12 -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 +66 -64
- package/src/properties/function-prop.ts +25 -27
- package/src/properties/history.ts +34 -35
- package/src/properties/index.ts +1 -0
- package/src/properties/persisted.ts +30 -20
- 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 -221
- 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 -249
- 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 -227
- 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 -1253
- 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 -265
- 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 -293
- package/src/__tests__/properties-browser.test.ts +0 -288
- package/src/__tests__/properties.test.ts +0 -1556
- 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,12 +1,11 @@
|
|
|
1
1
|
import { persistedSignal, } from "@praxisjs/core/internal";
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { sharedField } from "../field";
|
|
3
|
+
import { addLifecycleHooks } from "../lifecycle";
|
|
4
|
+
// Fields of one instance that persist under the same key share one signal. Only read while the
|
|
5
|
+
// instance is built; each field then reads its signal from its own slot.
|
|
6
|
+
const SIGNALS = Symbol("praxis.persistedSignals");
|
|
4
7
|
function getOrCreateSignal(instance, storageKey, initialValue, options) {
|
|
5
|
-
|
|
6
|
-
if (!map) {
|
|
7
|
-
map = new Map();
|
|
8
|
-
signalMap.set(instance, map);
|
|
9
|
-
}
|
|
8
|
+
const map = (instance[SIGNALS] ??= new Map());
|
|
10
9
|
let sig = map.get(storageKey);
|
|
11
10
|
if (!sig) {
|
|
12
11
|
sig = persistedSignal(storageKey, initialValue, options);
|
|
@@ -15,18 +14,25 @@ function getOrCreateSignal(instance, storageKey, initialValue, options) {
|
|
|
15
14
|
return sig;
|
|
16
15
|
}
|
|
17
16
|
export function Persisted(key, options = {}) {
|
|
18
|
-
return
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
return sharedField((name) => {
|
|
18
|
+
const slot = Symbol(`praxis.persisted.${name}`);
|
|
19
|
+
const storageKey = key ?? name;
|
|
20
|
+
// Without this every mounted instance would leave a window "storage" listener behind.
|
|
21
|
+
const close = (instance) => { instance[slot].close(); };
|
|
22
|
+
return {
|
|
23
|
+
descriptor: {
|
|
24
|
+
get() {
|
|
25
|
+
return this[slot]();
|
|
26
|
+
},
|
|
27
|
+
set(value) {
|
|
28
|
+
this[slot].set(value);
|
|
25
29
|
},
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
},
|
|
31
|
+
init(instance, initialValue) {
|
|
32
|
+
instance[slot] = getOrCreateSignal(instance, storageKey, initialValue, options);
|
|
33
|
+
addLifecycleHooks(instance, undefined, close);
|
|
34
|
+
},
|
|
35
|
+
};
|
|
30
36
|
});
|
|
31
37
|
}
|
|
32
38
|
//# sourceMappingURL=persisted.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"persisted.js","sourceRoot":"","sources":["../../src/properties/persisted.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,GAGhB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,
|
|
1
|
+
{"version":3,"file":"persisted.js","sourceRoot":"","sources":["../../src/properties/persisted.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,GAGhB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAuC,WAAW,EAAE,MAAM,UAAU,CAAC;AAC5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEjD,+FAA+F;AAC/F,yEAAyE;AACzE,MAAM,OAAO,GAAkB,MAAM,CAAC,yBAAyB,CAAC,CAAC;AAMjE,SAAS,iBAAiB,CACxB,QAAuB,EACvB,UAAkB,EAClB,YAAe,EACf,OAAkC;IAElC,MAAM,GAAG,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,IAAI,GAAG,EAAoC,CAAC,CAAC;IAChF,IAAI,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAC9B,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,GAAG,GAAG,eAAe,CAAC,UAAU,EAAE,YAAY,EAAE,OAAO,CAA6B,CAAC;QACrF,GAAG,CAAC,GAAG,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;IAC3B,CAAC;IACD,OAAO,GAAyB,CAAC;AACnC,CAAC;AAED,MAAM,UAAU,SAAS,CACvB,GAAY,EACZ,UAAqC,EAAE;IAEvC,OAAO,WAAW,CAAC,CAAC,IAAI,EAAE,EAAE;QAC1B,MAAM,IAAI,GAAG,MAAM,CAAC,oBAAoB,IAAI,EAAE,CAAC,CAAC;QAChD,MAAM,UAAU,GAAG,GAAG,IAAI,IAAI,CAAC;QAC/B,sFAAsF;QACtF,MAAM,KAAK,GAAG,CAAC,QAAgB,EAAE,EAAE,GAAK,QAAsB,CAAC,IAAI,CAAwB,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;QACvG,OAAO;YACL,UAAU,EAAE;gBACV,GAAG;oBACD,OAAQ,IAAI,CAAC,IAAI,CAAwB,EAAE,CAAC;gBAC9C,CAAC;gBACD,GAAG,CAAkB,KAAQ;oBAC1B,IAAI,CAAC,IAAI,CAAwB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;gBAChD,CAAC;aACF;YACD,IAAI,CAAC,QAAQ,EAAE,YAAY;gBACzB,QAAQ,CAAC,IAAI,CAAC,GAAG,iBAAiB,CAAC,QAAQ,EAAE,UAAU,EAAE,YAAiB,EAAE,OAAO,CAAC,CAAC;gBACrF,iBAAiB,CAAC,QAAQ,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;YAChD,CAAC;SACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import type { StatefulComponent } from "@praxisjs/core";
|
|
2
|
+
export declare function Prop(): <This extends StatefulComponent, Value = unknown>(_value: undefined, context: ClassFieldDecoratorContext<This, Value>) => void;
|
|
2
3
|
//# sourceMappingURL=prop.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prop.d.ts","sourceRoot":"","sources":["../../src/properties/prop.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"prop.d.ts","sourceRoot":"","sources":["../../src/properties/prop.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AASxD,wBAAgB,IAAI,KACD,IAAI,SAAS,iBAAiB,EAAE,KAAK,GAAG,OAAO,EAC9D,QAAQ,SAAS,EACjB,SAAS,0BAA0B,CAAC,IAAI,EAAE,KAAK,CAAC,KAC/C,IAAI,CAyBR"}
|
package/dist/properties/prop.js
CHANGED
|
@@ -1,26 +1,30 @@
|
|
|
1
1
|
import { getComponentDefault, getComponentRawProp, setComponentDefault, } from "@praxisjs/core/internal";
|
|
2
|
-
import {
|
|
2
|
+
import { addClaimableInitializer, assertFieldContext } from "../field";
|
|
3
3
|
export function Prop() {
|
|
4
|
-
return
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
4
|
+
return function (_value, context) {
|
|
5
|
+
assertFieldContext(context, "@Prop()");
|
|
6
|
+
const name = context.name;
|
|
7
|
+
// Shared by every instance, like @State's accessors.
|
|
8
|
+
const descriptor = {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
configurable: true,
|
|
11
|
+
get() {
|
|
12
|
+
const fromParent = getComponentRawProp(this, name);
|
|
13
|
+
if (fromParent !== undefined) {
|
|
14
|
+
return typeof fromParent === "function"
|
|
15
|
+
? fromParent()
|
|
16
|
+
: fromParent;
|
|
17
|
+
}
|
|
18
|
+
return getComponentDefault(this, name);
|
|
19
|
+
},
|
|
20
|
+
set(value) {
|
|
21
|
+
setComponentDefault(this, name, value);
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
addClaimableInitializer(context, function (value) {
|
|
25
|
+
setComponentDefault(this, name, value);
|
|
26
|
+
Object.defineProperty(this, name, descriptor);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
25
29
|
}
|
|
26
30
|
//# sourceMappingURL=prop.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prop.js","sourceRoot":"","sources":["../../src/properties/prop.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"prop.js","sourceRoot":"","sources":["../../src/properties/prop.ts"],"names":[],"mappings":"AACA,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAEvE,MAAM,UAAU,IAAI;IAClB,OAAO,UACL,MAAiB,EACjB,OAAgD;QAEhD,kBAAkB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QACvC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAc,CAAC;QACpC,qDAAqD;QACrD,MAAM,UAAU,GAAuB;YACrC,UAAU,EAAE,IAAI;YAChB,YAAY,EAAE,IAAI;YAClB,GAAG;gBACD,MAAM,UAAU,GAAG,mBAAmB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;gBACnD,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;oBAC7B,OAAO,OAAO,UAAU,KAAK,UAAU;wBACrC,CAAC,CAAE,UAA4B,EAAE;wBACjC,CAAC,CAAC,UAAU,CAAC;gBACjB,CAAC;gBACD,OAAO,mBAAmB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YACzC,CAAC;YACD,GAAG,CAAe,KAAc;gBAC9B,mBAAmB,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;YACzC,CAAC;SACF,CAAC;QACF,uBAAuB,CAAC,OAAO,EAAE,UAAU,KAAK;YAC9C,mBAAmB,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;YACvC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC;QAChD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/properties/ref.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { type FieldDecorator } from "../field";
|
|
1
2
|
export type Ref<T extends Element = Element> = ((el: T | null) => void) & {
|
|
2
3
|
current: T | null;
|
|
3
4
|
};
|
|
4
5
|
/** Creates a standalone ref object for use outside of class fields (e.g. module-level or passed to @Lazy). */
|
|
5
6
|
export declare function createRef<T extends Element = Element>(): Ref<T>;
|
|
6
|
-
export declare function Ref<T extends Element = Element>():
|
|
7
|
+
export declare function Ref<T extends Element = Element>(): FieldDecorator;
|
|
7
8
|
//# sourceMappingURL=ref.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ref.d.ts","sourceRoot":"","sources":["../../src/properties/ref.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ref.d.ts","sourceRoot":"","sources":["../../src/properties/ref.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAA+B,MAAM,UAAU,CAAC;AAE5E,MAAM,MAAM,GAAG,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,IAAI,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,KAAK,IAAI,CAAC,GAAG;IACxE,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC;CACnB,CAAC;AAEF,8GAA8G;AAC9G,wBAAgB,SAAS,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,KAAK,GAAG,CAAC,CAAC,CAAC,CAM/D;AAGD,wBAAgB,GAAG,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,KAAK,cAAc,CAYjE"}
|
package/dist/properties/ref.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { sharedField } from "../field";
|
|
2
2
|
/** Creates a standalone ref object for use outside of class fields (e.g. module-level or passed to @Lazy). */
|
|
3
3
|
export function createRef() {
|
|
4
4
|
function refFn(el) {
|
|
@@ -9,13 +9,16 @@ export function createRef() {
|
|
|
9
9
|
}
|
|
10
10
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
|
|
11
11
|
export function Ref() {
|
|
12
|
-
return
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
return sharedField((name) => {
|
|
13
|
+
const ref = Symbol(`praxis.ref.${name}`);
|
|
14
|
+
return {
|
|
15
|
+
descriptor: {
|
|
16
|
+
// Created on first read: a ref that is never handed to an element costs nothing.
|
|
17
|
+
get() {
|
|
18
|
+
return (this[ref] ??= createRef());
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
};
|
|
19
22
|
});
|
|
20
23
|
}
|
|
21
24
|
//# sourceMappingURL=ref.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ref.js","sourceRoot":"","sources":["../../src/properties/ref.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"ref.js","sourceRoot":"","sources":["../../src/properties/ref.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuC,WAAW,EAAE,MAAM,UAAU,CAAC;AAM5E,8GAA8G;AAC9G,MAAM,UAAU,SAAS;IACvB,SAAS,KAAK,CAAC,EAAY;QACxB,KAAgB,CAAC,OAAO,GAAG,EAAE,CAAC;IACjC,CAAC;IACA,KAAgB,CAAC,OAAO,GAAG,IAAI,CAAC;IACjC,OAAO,KAAe,CAAC;AACzB,CAAC;AAED,6EAA6E;AAC7E,MAAM,UAAU,GAAG;IACjB,OAAO,WAAW,CAAC,CAAC,IAAI,EAAE,EAAE;QAC1B,MAAM,GAAG,GAAG,MAAM,CAAC,cAAc,IAAI,EAAE,CAAC,CAAC;QACzC,OAAO;YACL,UAAU,EAAE;gBACV,iFAAiF;gBACjF,GAAG;oBACD,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,SAAS,EAAK,CAAC,CAAC;gBACxC,CAAC;aACF;SACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../../src/properties/resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,QAAQ,IAAI,gBAAgB,EACjC,KAAK,eAAe,EACrB,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../../src/properties/resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,QAAQ,IAAI,gBAAgB,EACjC,KAAK,eAAe,EACrB,MAAM,yBAAyB,CAAC;AAKjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE,CAAC;AAElD,KAAK,oBAAoB,GAAG,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,0BAA0B,KAAK,IAAI,CAAC;AAE7F;;;;;;;;;;GAUG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,oBAAoB,CAAC;AAE3G,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,GAAG,GAAG,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,oBAAoB,CAAC"}
|
|
@@ -1,25 +1,30 @@
|
|
|
1
1
|
import { resource, } from "@praxisjs/core/internal";
|
|
2
|
-
import {
|
|
2
|
+
import { sharedField } from "../field";
|
|
3
|
+
import { addLifecycleHooks } from "../lifecycle";
|
|
3
4
|
export { invalidateResource } from "@praxisjs/core/internal";
|
|
4
5
|
export function Resource(
|
|
5
6
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6
7
|
fetcher, options = {}) {
|
|
7
|
-
return
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return {
|
|
15
|
-
descriptor: {
|
|
16
|
-
get() { return r; },
|
|
17
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
18
|
-
set() { },
|
|
8
|
+
return sharedField((name) => {
|
|
9
|
+
const slot = Symbol(`praxis.resource.${name}`);
|
|
10
|
+
const destroy = (instance) => { instance[slot].destroy(); };
|
|
11
|
+
return {
|
|
12
|
+
descriptor: {
|
|
13
|
+
get() {
|
|
14
|
+
return this[slot];
|
|
19
15
|
},
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
17
|
+
set() { },
|
|
18
|
+
},
|
|
19
|
+
init(instance) {
|
|
20
|
+
const bound = fetcher.length > 0
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
+
? () => fetcher(instance)
|
|
23
|
+
: fetcher;
|
|
24
|
+
instance[slot] = resource(bound, options);
|
|
25
|
+
addLifecycleHooks(instance, undefined, destroy);
|
|
26
|
+
},
|
|
27
|
+
};
|
|
23
28
|
});
|
|
24
29
|
}
|
|
25
30
|
//# sourceMappingURL=resource.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource.js","sourceRoot":"","sources":["../../src/properties/resource.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,GAGT,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"resource.js","sourceRoot":"","sources":["../../src/properties/resource.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,GAGT,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAkB,WAAW,EAAE,MAAM,UAAU,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAmB7D,MAAM,UAAU,QAAQ;AACtB,8DAA8D;AAC9D,OAAyD,EACzD,UAA8B,EAAE;IAEhC,OAAO,WAAW,CAAC,CAAC,IAAI,EAAE,EAAE;QAC1B,MAAM,IAAI,GAAG,MAAM,CAAC,mBAAmB,IAAI,EAAE,CAAC,CAAC;QAC/C,MAAM,OAAO,GAAG,CAAC,QAAgB,EAAE,EAAE,GAAK,QAAsB,CAAC,IAAI,CAAyB,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;QAC5G,OAAO;YACL,UAAU,EAAE;gBACV,GAAG;oBACD,OAAO,IAAI,CAAC,IAAI,CAAwB,CAAC;gBAC3C,CAAC;gBACD,gEAAgE;gBAChE,GAAG,KAAU,CAAC;aACf;YACD,IAAI,CAAC,QAAQ;gBACX,MAAM,KAAK,GACT,OAAO,CAAC,MAAM,GAAG,CAAC;oBAChB,8DAA8D;oBAC9D,CAAC,CAAC,GAAG,EAAE,CAAE,OAAqC,CAAC,QAAQ,CAAC;oBACxD,CAAC,CAAE,OAA4B,CAAC;gBACpC,QAAQ,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;gBAC1C,iBAAiB,CAAC,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;YAClD,CAAC;SACF,CAAC;IACJ,CAAC,CAAoC,CAAC;AACxC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Selector as SelectorFn, type SelectorEquals } from "@praxisjs/core/internal";
|
|
2
|
+
export type Selector<K> = SelectorFn<K>;
|
|
3
|
+
export interface SelectorOptions<K, T> {
|
|
4
|
+
/**
|
|
5
|
+
* Decides whether `key` is selected for the source value `value`. Defaults to a strict
|
|
6
|
+
* comparison (SameValueZero), which notifies only the previous and next keys; a custom function
|
|
7
|
+
* is evaluated against every key in use whenever the source changes.
|
|
8
|
+
*/
|
|
9
|
+
equals?: SelectorEquals<K, T>;
|
|
10
|
+
}
|
|
11
|
+
export declare function Selector<const Name extends string, K = unknown, T = unknown>(source: Name, options?: SelectorOptions<K, T>): <This extends Record<Name, unknown>, Value extends Selector<never>>(value: undefined, context: ClassFieldDecoratorContext<This, Value>) => void;
|
|
12
|
+
//# sourceMappingURL=selector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selector.d.ts","sourceRoot":"","sources":["../../src/properties/selector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,QAAQ,IAAI,UAAU,EAAE,KAAK,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAMrG,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;AAExC,MAAM,WAAW,eAAe,CAAC,CAAC,EAAE,CAAC;IACnC;;;;OAIG;IACH,MAAM,CAAC,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;CAC/B;AAUD,wBAAgB,QAAQ,CAAC,KAAK,CAAC,IAAI,SAAS,MAAM,EAAE,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,OAAO,EAC1E,MAAM,EAAE,IAAI,EACZ,OAAO,GAAE,eAAe,CAAC,CAAC,EAAE,CAAC,CAAM,GAaf,CAAC,IAAI,SAAS,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,KAAK,SAAS,QAAQ,CAAC,KAAK,CAAC,EACpF,KAAK,EAAE,SAAS,EAChB,OAAO,EAAE,0BAA0B,CAAC,IAAI,EAAE,KAAK,CAAC,KAC7C,IAAI,CACV"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { selector } from "@praxisjs/core/internal";
|
|
2
|
+
import { isComputed } from "@praxisjs/shared/internal";
|
|
3
|
+
import { sharedField } from "../field";
|
|
4
|
+
function createSelector(host, source, equals) {
|
|
5
|
+
const read = () => {
|
|
6
|
+
const raw = host[source];
|
|
7
|
+
return (isComputed(raw) ? raw() : raw);
|
|
8
|
+
};
|
|
9
|
+
return equals ? selector(read, equals) : selector(read);
|
|
10
|
+
}
|
|
11
|
+
export function Selector(source, options = {}) {
|
|
12
|
+
const decorator = sharedField((name) => {
|
|
13
|
+
const slot = Symbol(`praxis.selector.${name}`);
|
|
14
|
+
return {
|
|
15
|
+
descriptor: {
|
|
16
|
+
// Created on first read, so the source field may be declared after this one.
|
|
17
|
+
get() {
|
|
18
|
+
return (this[slot] ??= createSelector(this, source, options.equals));
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
return decorator;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=selector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selector.js","sourceRoot":"","sources":["../../src/properties/selector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAoD,MAAM,yBAAyB,CAAC;AAErG,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAEvD,OAAO,EAAkB,WAAW,EAAE,MAAM,UAAU,CAAC;AAavD,SAAS,cAAc,CAAO,IAAe,EAAE,MAAc,EAAE,MAAwC;IACrG,MAAM,IAAI,GAAG,GAAG,EAAE;QAChB,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;QACzB,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAE,GAAyB,EAAE,CAAC,CAAC,CAAC,GAAG,CAAM,CAAC;IACrE,CAAC,CAAC;IACF,OAAO,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,CAAE,QAAQ,CAAC,IAAI,CAA8B,CAAC;AACxF,CAAC;AAED,MAAM,UAAU,QAAQ,CACtB,MAAY,EACZ,UAAiC,EAAE;IAEnC,MAAM,SAAS,GAAG,WAAW,CAAS,CAAC,IAAI,EAAE,EAAE;QAC7C,MAAM,IAAI,GAAG,MAAM,CAAC,mBAAmB,IAAI,EAAE,CAAC,CAAC;QAC/C,OAAO;YACL,UAAU,EAAE;gBACV,6EAA6E;gBAC7E,GAAG;oBACD,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;gBACvE,CAAC;aACF;SACF,CAAC;IACJ,CAAC,CAAC,CAAC;IACH,OAAO,SAGE,CAAC;AACZ,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import { type FieldDecorator } from "../field";
|
|
1
2
|
export declare function initSlots(instance: object, children: unknown): void;
|
|
2
3
|
export declare function getSlot(instance: object, name: string): unknown[];
|
|
3
|
-
export declare function Slot(name?: string):
|
|
4
|
+
export declare function Slot(name?: string): FieldDecorator;
|
|
4
5
|
//# sourceMappingURL=slot.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slot.d.ts","sourceRoot":"","sources":["../../src/properties/slot.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"slot.d.ts","sourceRoot":"","sources":["../../src/properties/slot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAA+B,MAAM,UAAU,CAAC;AAqC5E,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,IAAI,CAEnE;AAED,wBAAgB,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,EAAE,CAEjE;AAED,wBAAgB,IAAI,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,cAAc,CAkBlD"}
|
package/dist/properties/slot.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { sharedField } from "../field";
|
|
2
|
+
// On the instance rather than in a WeakMap: every slot field read goes through here.
|
|
3
|
+
const SLOTS = Symbol("praxis.slots");
|
|
3
4
|
function resolveSlots(children) {
|
|
4
5
|
const slots = new Map();
|
|
5
6
|
const defaultSlot = [];
|
|
@@ -14,9 +15,10 @@ function resolveSlots(children) {
|
|
|
14
15
|
const slotName = child.getAttribute("slot");
|
|
15
16
|
if (slotName) {
|
|
16
17
|
child.removeAttribute("slot");
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
let named = slots.get(slotName);
|
|
19
|
+
if (!named)
|
|
20
|
+
slots.set(slotName, (named = []));
|
|
21
|
+
named.push(child);
|
|
20
22
|
continue;
|
|
21
23
|
}
|
|
22
24
|
}
|
|
@@ -26,26 +28,26 @@ function resolveSlots(children) {
|
|
|
26
28
|
return slots;
|
|
27
29
|
}
|
|
28
30
|
export function initSlots(instance, children) {
|
|
29
|
-
|
|
31
|
+
instance[SLOTS] = resolveSlots(children);
|
|
30
32
|
}
|
|
31
33
|
export function getSlot(instance, name) {
|
|
32
|
-
return
|
|
34
|
+
return instance[SLOTS]?.get(name) ?? [];
|
|
33
35
|
}
|
|
34
36
|
export function Slot(name) {
|
|
35
|
-
return
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
set: (_value) => {
|
|
42
|
-
if (process.env.NODE_ENV !== "production") {
|
|
43
|
-
console.warn(`[Slot] "${propName}" is a slot and cannot be assigned directly. Slots are filled by the parent component.`);
|
|
44
|
-
}
|
|
45
|
-
},
|
|
37
|
+
return sharedField((propName) => {
|
|
38
|
+
const slotName = name ?? propName;
|
|
39
|
+
return {
|
|
40
|
+
descriptor: {
|
|
41
|
+
get() {
|
|
42
|
+
return getSlot(this, slotName);
|
|
46
43
|
},
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
set(_value) {
|
|
45
|
+
if (process.env.NODE_ENV !== "production") {
|
|
46
|
+
console.warn(`[Slot] "${propName}" is a slot and cannot be assigned directly. Slots are filled by the parent component.`);
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
};
|
|
49
51
|
});
|
|
50
52
|
}
|
|
51
53
|
//# sourceMappingURL=slot.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slot.js","sourceRoot":"","sources":["../../src/properties/slot.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"slot.js","sourceRoot":"","sources":["../../src/properties/slot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuC,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5E,qFAAqF;AACrF,MAAM,KAAK,GAAkB,MAAM,CAAC,cAAc,CAAC,CAAC;AAMpD,SAAS,YAAY,CAAC,QAAiB;IACrC,MAAM,KAAK,GAAG,IAAI,GAAG,EAAqB,CAAC;IAC3C,MAAM,WAAW,GAAc,EAAE,CAAC;IAClC,KAAK,CAAC,GAAG,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;IAElC,IAAI,QAAQ,IAAI,IAAI;QAAE,OAAO,KAAK,CAAC;IAEnC,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC;QACjC,CAAC,CAAE,QAAsB,CAAC,IAAI,CAAC,QAAQ,CAAC;QACxC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;IAEf,KAAK,MAAM,KAAK,IAAI,GAAG,EAAE,CAAC;QACxB,IAAI,KAAK,YAAY,OAAO,EAAE,CAAC;YAC7B,MAAM,QAAQ,GAAG,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;YAC5C,IAAI,QAAQ,EAAE,CAAC;gBACb,KAAK,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;gBAC9B,IAAI,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;gBAChC,IAAI,CAAC,KAAK;oBAAE,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,KAAK,GAAG,EAAE,CAAC,CAAC,CAAC;gBAC9C,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBAClB,SAAS;YACX,CAAC;QACH,CAAC;QACD,IAAI,KAAK,IAAI,IAAI;YAAE,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC7C,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,QAAgB,EAAE,QAAiB;IAC1D,QAAqB,CAAC,KAAK,CAAC,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC;AACzD,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,QAAgB,EAAE,IAAY;IACpD,OAAQ,QAAqB,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;AACxD,CAAC;AAED,MAAM,UAAU,IAAI,CAAC,IAAa;IAChC,OAAO,WAAW,CAAC,CAAC,QAAQ,EAAE,EAAE;QAC9B,MAAM,QAAQ,GAAG,IAAI,IAAI,QAAQ,CAAC;QAClC,OAAO;YACL,UAAU,EAAE;gBACV,GAAG;oBACD,OAAO,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;gBACjC,CAAC;gBACD,GAAG,CAAC,MAAe;oBACjB,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE,CAAC;wBAC1C,OAAO,CAAC,IAAI,CACV,WAAW,QAAQ,wFAAwF,CAC5G,CAAC;oBACJ,CAAC;gBACH,CAAC;aACF;SACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../src/properties/state.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../src/properties/state.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAIrD,wBAAgB,KAAK,KACF,IAAI,SAAS,YAAY,EAAE,KAAK,GAAG,OAAO,EACzD,QAAQ,SAAS,EACjB,SAAS,0BAA0B,CAAC,IAAI,EAAE,KAAK,CAAC,KAC/C,IAAI,CAyBR"}
|
package/dist/properties/state.js
CHANGED
|
@@ -1,19 +1,30 @@
|
|
|
1
|
-
import { markStateDirty,
|
|
2
|
-
import {
|
|
1
|
+
import { markStateDirty, readSignal, SignalNode, writeSignal } from "@praxisjs/core/internal";
|
|
2
|
+
import { addClaimableInitializer, assertFieldContext } from "../field";
|
|
3
3
|
export function State() {
|
|
4
|
-
return
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
4
|
+
return function (_value, context) {
|
|
5
|
+
assertFieldContext(context, "@State()");
|
|
6
|
+
const name = context.name;
|
|
7
|
+
// One accessor pair per decorated field, shared by every instance: per-instance closures would
|
|
8
|
+
// give each instance its own hidden class, turning every field read into a megamorphic access.
|
|
9
|
+
// It stays an own property of each instance, so decorators stacked above @State (and custom ones
|
|
10
|
+
// built with createFieldDecorator) find and wrap it, and a Proxy around the instance works.
|
|
11
|
+
const node = Symbol(`praxis.state.${String(name)}`);
|
|
12
|
+
const descriptor = {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
configurable: true,
|
|
15
|
+
get() {
|
|
16
|
+
return readSignal(this[node]);
|
|
17
|
+
},
|
|
18
|
+
set(value) {
|
|
19
|
+
markStateDirty(this);
|
|
20
|
+
writeSignal(this[node], value);
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
addClaimableInitializer(context, function (value) {
|
|
24
|
+
const instance = this;
|
|
25
|
+
instance[node] = new SignalNode(value);
|
|
26
|
+
Object.defineProperty(instance, name, descriptor);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
18
29
|
}
|
|
19
30
|
//# sourceMappingURL=state.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/properties/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/properties/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE9F,OAAO,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAMvE,MAAM,UAAU,KAAK;IACnB,OAAO,UACL,MAAiB,EACjB,OAAgD;QAEhD,kBAAkB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;QACxC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QAC1B,+FAA+F;QAC/F,+FAA+F;QAC/F,iGAAiG;QACjG,4FAA4F;QAC5F,MAAM,IAAI,GAAG,MAAM,CAAC,gBAAgB,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACpD,MAAM,UAAU,GAAuB;YACrC,UAAU,EAAE,IAAI;YAChB,YAAY,EAAE,IAAI;YAClB,GAAG;gBACD,OAAO,UAAU,CAAC,IAAI,CAAC,IAAI,CAAe,CAAC,CAAC;YAC9C,CAAC;YACD,GAAG,CAAkB,KAAc;gBACjC,cAAc,CAAC,IAAI,CAAC,CAAC;gBACrB,WAAW,CAAC,IAAI,CAAC,IAAI,CAAe,EAAE,KAAK,CAAC,CAAC;YAC/C,CAAC;SACF,CAAC;QACF,uBAAuB,CAAC,OAAO,EAAE,UAAU,KAAK;YAC9C,MAAM,QAAQ,GAAG,IAA4B,CAAC;YAC9C,QAAQ,CAAC,IAAI,CAAC,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC;YACvC,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import { type FieldDecorator } from "../field";
|
|
2
|
+
export declare function Synced(channelName?: string): FieldDecorator;
|
|
2
3
|
//# sourceMappingURL=synced.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"synced.d.ts","sourceRoot":"","sources":["../../src/properties/synced.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"synced.d.ts","sourceRoot":"","sources":["../../src/properties/synced.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,cAAc,EAA+B,MAAM,UAAU,CAAC;AAW5E,wBAAgB,MAAM,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,cAAc,CA0B3D"}
|
|
@@ -1,26 +1,34 @@
|
|
|
1
1
|
import { syncedSignal } from "@praxisjs/core/internal";
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { sharedField } from "../field";
|
|
3
|
+
import { addLifecycleHooks } from "../lifecycle";
|
|
4
|
+
// Fields of one instance synced over the same channel share one signal. Only read while the
|
|
5
|
+
// instance is built; each field then reads its signal from its own slot.
|
|
6
|
+
const SIGNALS = Symbol("praxis.syncedSignals");
|
|
4
7
|
export function Synced(channelName) {
|
|
5
|
-
return
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const sig = map.get(key);
|
|
14
|
-
return {
|
|
15
|
-
descriptor: {
|
|
16
|
-
get: () => sig(),
|
|
17
|
-
set: (value) => { sig.set(value); },
|
|
8
|
+
return sharedField((name) => {
|
|
9
|
+
const slot = Symbol(`praxis.synced.${name}`);
|
|
10
|
+
const key = channelName ?? name;
|
|
11
|
+
const close = (instance) => { instance[slot].close(); };
|
|
12
|
+
return {
|
|
13
|
+
descriptor: {
|
|
14
|
+
get() {
|
|
15
|
+
return this[slot]();
|
|
18
16
|
},
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
set(value) {
|
|
18
|
+
this[slot].set(value);
|
|
21
19
|
},
|
|
22
|
-
}
|
|
23
|
-
|
|
20
|
+
},
|
|
21
|
+
init(instance, initialValue) {
|
|
22
|
+
const map = (instance[SIGNALS] ??= new Map());
|
|
23
|
+
let sig = map.get(key);
|
|
24
|
+
if (!sig) {
|
|
25
|
+
sig = syncedSignal(key, initialValue);
|
|
26
|
+
map.set(key, sig);
|
|
27
|
+
}
|
|
28
|
+
instance[slot] = sig;
|
|
29
|
+
addLifecycleHooks(instance, undefined, close);
|
|
30
|
+
},
|
|
31
|
+
};
|
|
24
32
|
});
|
|
25
33
|
}
|
|
26
34
|
//# sourceMappingURL=synced.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"synced.js","sourceRoot":"","sources":["../../src/properties/synced.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAqB,MAAM,yBAAyB,CAAC;AAE1E,OAAO,
|
|
1
|
+
{"version":3,"file":"synced.js","sourceRoot":"","sources":["../../src/properties/synced.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAqB,MAAM,yBAAyB,CAAC;AAE1E,OAAO,EAAuC,WAAW,EAAE,MAAM,UAAU,CAAC;AAC5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEjD,4FAA4F;AAC5F,yEAAyE;AACzE,MAAM,OAAO,GAAkB,MAAM,CAAC,sBAAsB,CAAC,CAAC;AAM9D,MAAM,UAAU,MAAM,CAAC,WAAoB;IACzC,OAAO,WAAW,CAAC,CAAC,IAAI,EAAE,EAAE;QAC1B,MAAM,IAAI,GAAG,MAAM,CAAC,iBAAiB,IAAI,EAAE,CAAC,CAAC;QAC7C,MAAM,GAAG,GAAG,WAAW,IAAI,IAAI,CAAC;QAChC,MAAM,KAAK,GAAG,CAAC,QAAgB,EAAE,EAAE,GAAK,QAAsB,CAAC,IAAI,CAA2B,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;QAC1G,OAAO;YACL,UAAU,EAAE;gBACV,GAAG;oBACD,OAAQ,IAAI,CAAC,IAAI,CAA2B,EAAE,CAAC;gBACjD,CAAC;gBACD,GAAG,CAAkB,KAAc;oBAChC,IAAI,CAAC,IAAI,CAA2B,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;gBACnD,CAAC;aACF;YACD,IAAI,CAAC,QAAQ,EAAE,YAAY;gBACzB,MAAM,GAAG,GAAG,CAAE,QAAuB,CAAC,OAAO,CAAC,KAAK,IAAI,GAAG,EAAiC,CAAC,CAAC;gBAC7F,IAAI,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;gBACvB,IAAI,CAAC,GAAG,EAAE,CAAC;oBACT,GAAG,GAAG,YAAY,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;oBACtC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;gBACpB,CAAC;gBACD,QAAQ,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC;gBACrB,iBAAiB,CAAC,QAAQ,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;YAChD,CAAC;SACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type AnyMethod = (this: any, ...args: any[]) => any;
|
|
2
|
+
export type MethodContext = ClassMethodDecoratorContext<any, any>;
|
|
3
|
+
/**
|
|
4
|
+
* Returns `method`, the decorator's replacement for `value`, set up so that reading it from an
|
|
5
|
+
* instance returns it bound to that instance, the same function on every read: detached calls
|
|
6
|
+
* (`onClick={this.save}`) keep working. `method` is shared by every instance and keeps any
|
|
7
|
+
* per-instance state in symbol slots.
|
|
8
|
+
*
|
|
9
|
+
* Rather than defining a bound wrapper on each instance as it is built, the first instance turns
|
|
10
|
+
* the method's prototype entry into an accessor: an instance pays for its bound copy only when the
|
|
11
|
+
* method is first read from it, and nothing if it never is.
|
|
12
|
+
*/
|
|
13
|
+
export declare function sharedMethod<F extends AnyMethod>(context: MethodContext, value: AnyMethod, method?: F): F;
|
|
14
|
+
//# sourceMappingURL=shared-method.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared-method.d.ts","sourceRoot":"","sources":["../src/shared-method.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,SAAS,GAAG,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;AAE3D,MAAM,MAAM,aAAa,GAAG,2BAA2B,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAsBlE;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,SAAS,EAC9C,OAAO,EAAE,aAAa,EACtB,KAAK,EAAE,SAAS,EAChB,MAAM,GAAE,CAAc,GACrB,CAAC,CA6DH"}
|