@praxisjs/decorators 0.4.3 → 0.5.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 +25 -0
- package/dist/__tests__/component.test.js +10 -1
- package/dist/__tests__/component.test.js.map +1 -1
- package/dist/__tests__/compose.test.d.ts +2 -0
- package/dist/__tests__/compose.test.d.ts.map +1 -0
- package/dist/__tests__/compose.test.js +171 -0
- package/dist/__tests__/compose.test.js.map +1 -0
- package/dist/__tests__/events.test.js +26 -0
- package/dist/__tests__/events.test.js.map +1 -1
- package/dist/__tests__/functions.test.js +142 -47
- package/dist/__tests__/functions.test.js.map +1 -1
- package/dist/__tests__/lazy.test.js +5 -7
- package/dist/__tests__/lazy.test.js.map +1 -1
- package/dist/__tests__/memo.test.js +61 -25
- package/dist/__tests__/memo.test.js.map +1 -1
- package/dist/__tests__/resource.test.d.ts +2 -0
- package/dist/__tests__/resource.test.d.ts.map +1 -0
- package/dist/__tests__/resource.test.js +103 -0
- package/dist/__tests__/resource.test.js.map +1 -0
- package/dist/__tests__/slot.test.js +32 -0
- package/dist/__tests__/slot.test.js.map +1 -1
- package/dist/__tests__/virtual.test.js +56 -15
- package/dist/__tests__/virtual.test.js.map +1 -1
- package/dist/component/component.d.ts +1 -1
- package/dist/component/component.d.ts.map +1 -1
- package/dist/component/component.js +15 -10
- package/dist/component/component.js.map +1 -1
- package/dist/component/lazy.d.ts.map +1 -1
- package/dist/component/lazy.js +29 -30
- package/dist/component/lazy.js.map +1 -1
- package/dist/component/virtual.d.ts.map +1 -1
- package/dist/component/virtual.js +46 -50
- package/dist/component/virtual.js.map +1 -1
- package/dist/create-class-decorator.d.ts +16 -0
- package/dist/create-class-decorator.d.ts.map +1 -0
- package/dist/create-class-decorator.js +35 -0
- package/dist/create-class-decorator.js.map +1 -0
- package/dist/create-field-decorator.d.ts +14 -0
- package/dist/create-field-decorator.d.ts.map +1 -0
- package/dist/create-field-decorator.js +37 -0
- package/dist/create-field-decorator.js.map +1 -0
- package/dist/create-getter-decorator.d.ts +18 -0
- package/dist/create-getter-decorator.d.ts.map +1 -0
- package/dist/create-getter-decorator.js +15 -0
- package/dist/create-getter-decorator.js.map +1 -0
- package/dist/create-lifecycle-method-decorator.d.ts +6 -0
- package/dist/create-lifecycle-method-decorator.d.ts.map +1 -0
- package/dist/create-lifecycle-method-decorator.js +22 -0
- package/dist/create-lifecycle-method-decorator.js.map +1 -0
- package/dist/create-method-decorator.d.ts +6 -0
- package/dist/create-method-decorator.d.ts.map +1 -0
- package/dist/create-method-decorator.js +14 -0
- package/dist/create-method-decorator.js.map +1 -0
- package/dist/events/emit.d.ts +1 -1
- package/dist/events/emit.d.ts.map +1 -1
- package/dist/events/emit.js +24 -29
- package/dist/events/emit.js.map +1 -1
- package/dist/events/on-command.d.ts +1 -2
- package/dist/events/on-command.d.ts.map +1 -1
- package/dist/events/on-command.js +15 -32
- package/dist/events/on-command.js.map +1 -1
- package/dist/functions/bind.d.ts +1 -2
- package/dist/functions/bind.d.ts.map +1 -1
- package/dist/functions/bind.js +4 -11
- package/dist/functions/bind.js.map +1 -1
- package/dist/functions/debounce.d.ts +1 -2
- package/dist/functions/debounce.d.ts.map +1 -1
- package/dist/functions/debounce.js +12 -20
- package/dist/functions/debounce.js.map +1 -1
- package/dist/functions/log.d.ts +1 -2
- package/dist/functions/log.d.ts.map +1 -1
- package/dist/functions/log.js +40 -38
- package/dist/functions/log.js.map +1 -1
- package/dist/functions/memo.d.ts +1 -2
- package/dist/functions/memo.d.ts.map +1 -1
- package/dist/functions/memo.js +15 -27
- package/dist/functions/memo.js.map +1 -1
- package/dist/functions/once.d.ts +1 -2
- package/dist/functions/once.d.ts.map +1 -1
- package/dist/functions/once.js +14 -12
- package/dist/functions/once.js.map +1 -1
- package/dist/functions/retry.d.ts +1 -2
- package/dist/functions/retry.d.ts.map +1 -1
- package/dist/functions/retry.js +23 -20
- package/dist/functions/retry.js.map +1 -1
- package/dist/functions/throttle.d.ts +1 -2
- package/dist/functions/throttle.d.ts.map +1 -1
- package/dist/functions/throttle.js +9 -16
- package/dist/functions/throttle.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 +25 -39
- package/dist/functions/watch.js.map +1 -1
- package/dist/functions/when.d.ts +1 -2
- package/dist/functions/when.d.ts.map +1 -1
- package/dist/functions/when.js +10 -26
- package/dist/functions/when.js.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/properties/compose.d.ts +3 -0
- package/dist/properties/compose.d.ts.map +1 -0
- package/dist/properties/compose.js +40 -0
- package/dist/properties/compose.js.map +1 -0
- package/dist/properties/computed.d.ts +1 -2
- package/dist/properties/computed.d.ts.map +1 -1
- package/dist/properties/computed.js +10 -9
- package/dist/properties/computed.js.map +1 -1
- package/dist/properties/history.d.ts.map +1 -1
- package/dist/properties/history.js +37 -32
- package/dist/properties/history.js.map +1 -1
- package/dist/properties/index.d.ts +2 -0
- package/dist/properties/index.d.ts.map +1 -1
- package/dist/properties/index.js +2 -0
- package/dist/properties/index.js.map +1 -1
- package/dist/properties/persisted.d.ts +1 -2
- package/dist/properties/persisted.d.ts.map +1 -1
- package/dist/properties/persisted.js +13 -29
- package/dist/properties/persisted.js.map +1 -1
- package/dist/properties/prop.d.ts +1 -2
- package/dist/properties/prop.d.ts.map +1 -1
- package/dist/properties/prop.js +21 -25
- package/dist/properties/prop.js.map +1 -1
- package/dist/properties/resource.d.ts +14 -0
- package/dist/properties/resource.d.ts.map +1 -0
- package/dist/properties/resource.js +27 -0
- package/dist/properties/resource.js.map +1 -0
- package/dist/properties/slot.d.ts +1 -2
- package/dist/properties/slot.d.ts.map +1 -1
- package/dist/properties/slot.js +15 -20
- package/dist/properties/slot.js.map +1 -1
- package/dist/properties/state.d.ts +1 -2
- package/dist/properties/state.d.ts.map +1 -1
- package/dist/properties/state.js +13 -18
- package/dist/properties/state.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/component.test.ts +10 -0
- package/src/__tests__/compose.test.ts +202 -0
- package/src/__tests__/events.test.ts +32 -0
- package/src/__tests__/functions.test.ts +177 -46
- package/src/__tests__/lazy.test.ts +3 -5
- package/src/__tests__/memo.test.ts +76 -25
- package/src/__tests__/resource.test.ts +113 -0
- package/src/__tests__/slot.test.ts +38 -0
- package/src/__tests__/virtual.test.ts +26 -7
- package/src/component/component.ts +27 -12
- package/src/component/lazy.ts +33 -37
- package/src/component/virtual.tsx +62 -75
- package/src/create-class-decorator.ts +61 -0
- package/src/create-field-decorator.ts +66 -0
- package/src/create-getter-decorator.ts +52 -0
- package/src/create-lifecycle-method-decorator.ts +38 -0
- package/src/create-method-decorator.ts +26 -0
- package/src/events/emit.ts +22 -33
- package/src/events/on-command.ts +22 -47
- package/src/functions/bind.ts +4 -15
- package/src/functions/debounce.ts +11 -26
- package/src/functions/log.ts +40 -43
- package/src/functions/memo.ts +15 -45
- package/src/functions/once.ts +13 -16
- package/src/functions/retry.ts +21 -22
- package/src/functions/throttle.ts +9 -23
- package/src/functions/watch.ts +27 -43
- package/src/functions/when.ts +11 -36
- package/src/index.ts +28 -0
- package/src/properties/compose.ts +53 -0
- package/src/properties/computed.ts +11 -13
- package/src/properties/history.ts +42 -41
- package/src/properties/index.ts +2 -0
- package/src/properties/persisted.ts +17 -58
- package/src/properties/prop.ts +21 -31
- package/src/properties/resource.ts +34 -0
- package/src/properties/slot.ts +17 -30
- package/src/properties/state.ts +14 -24
package/dist/functions/watch.js
CHANGED
|
@@ -1,49 +1,35 @@
|
|
|
1
1
|
import { effect } from "@praxisjs/core/internal";
|
|
2
2
|
import { isComputed } from "@praxisjs/shared/internal";
|
|
3
|
+
import { createLifecycleMethodDecorator } from "../create-lifecycle-method-decorator";
|
|
3
4
|
function readValue(instance, key) {
|
|
4
5
|
const raw = instance[key];
|
|
5
6
|
return isComputed(raw) ? raw() : raw;
|
|
6
7
|
}
|
|
7
8
|
export function Watch(...propNames) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
9
|
+
const props = propNames;
|
|
10
|
+
return createLifecycleMethodDecorator({
|
|
11
|
+
register(callback, instance) {
|
|
12
|
+
const inst = instance;
|
|
13
|
+
if (props.length === 1) {
|
|
14
|
+
let oldVal = readValue(inst, props[0]);
|
|
15
|
+
return effect(() => {
|
|
16
|
+
const newVal = readValue(inst, props[0]);
|
|
17
|
+
if (!Object.is(newVal, oldVal)) {
|
|
18
|
+
callback(newVal, oldVal);
|
|
19
|
+
oldVal = newVal;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
const read = () => Object.fromEntries(props.map((p) => [p, readValue(inst, p)]));
|
|
24
|
+
let oldVals = read();
|
|
25
|
+
return effect(() => {
|
|
26
|
+
const newVals = read();
|
|
27
|
+
if (props.some((p) => !Object.is(newVals[p], oldVals[p]))) {
|
|
28
|
+
callback(newVals, oldVals);
|
|
29
|
+
oldVals = newVals;
|
|
28
30
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
stopEffect = effect(() => {
|
|
33
|
-
const newVals = read();
|
|
34
|
-
if (props.some((p) => !Object.is(newVals[p], oldVals[p]))) {
|
|
35
|
-
value.call(this, newVals, oldVals);
|
|
36
|
-
oldVals = newVals;
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
instance.onUnmount = function () {
|
|
42
|
-
originalOnUnmount?.call(this);
|
|
43
|
-
stopEffect?.();
|
|
44
|
-
stopEffect = undefined;
|
|
45
|
-
};
|
|
46
|
-
});
|
|
47
|
-
};
|
|
31
|
+
});
|
|
32
|
+
},
|
|
33
|
+
});
|
|
48
34
|
}
|
|
49
35
|
//# sourceMappingURL=watch.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watch.js","sourceRoot":"","sources":["../../src/functions/watch.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEjD,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"watch.js","sourceRoot":"","sources":["../../src/functions/watch.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEjD,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAEvD,OAAO,EAAE,8BAA8B,EAAE,MAAM,sCAAsC,CAAC;AA4CtF,SAAS,SAAS,CAAC,QAAiC,EAAE,GAAW;IAC/D,MAAM,GAAG,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;IAC1B,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAE,GAAyB,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;AAC9D,CAAC;AAED,MAAM,UAAU,KAAK,CAGnB,GAAG,SAAgC;IACnC,MAAM,KAAK,GAAG,SAAgC,CAAC;IAE/C,OAAO,8BAA8B,CAAI;QACvC,QAAQ,CAAC,QAAQ,EAAE,QAAQ;YACzB,MAAM,IAAI,GAAG,QAAuC,CAAC;YAErD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACvB,IAAI,MAAM,GAAG,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;gBACvC,OAAO,MAAM,CAAC,GAAG,EAAE;oBACjB,MAAM,MAAM,GAAG,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;oBACzC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;wBAC/B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;wBACzB,MAAM,GAAG,MAAM,CAAC;oBAClB,CAAC;gBACH,CAAC,CAAC,CAAC;YACL,CAAC;YAED,MAAM,IAAI,GAAG,GAAG,EAAE,CAChB,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAChE,IAAI,OAAO,GAAG,IAAI,EAAE,CAAC;YACrB,OAAO,MAAM,CAAC,GAAG,EAAE;gBACjB,MAAM,OAAO,GAAG,IAAI,EAAE,CAAC;gBACvB,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;oBAC1D,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;oBAC3B,OAAO,GAAG,OAAO,CAAC;gBACpB,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
package/dist/functions/when.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function When(propName: string): (value: (this: StatefulComponent, val: unknown) => void, context: ClassMethodDecoratorContext<StatefulComponent>) => void;
|
|
1
|
+
export declare function When(propName: string): (value: (this: import("@praxisjs/core").StatefulComponent, ...args: unknown[]) => void, _context: ClassMethodDecoratorContext<import("@praxisjs/core").StatefulComponent, (this: import("@praxisjs/core").StatefulComponent, ...args: any) => any>) => void;
|
|
3
2
|
//# sourceMappingURL=when.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"when.d.ts","sourceRoot":"","sources":["../../src/functions/when.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"when.d.ts","sourceRoot":"","sources":["../../src/functions/when.ts"],"names":[],"mappings":"AAMA,wBAAgB,IAAI,CAAC,QAAQ,EAAE,MAAM,+PAUpC"}
|
package/dist/functions/when.js
CHANGED
|
@@ -1,31 +1,15 @@
|
|
|
1
1
|
import { when } from "@praxisjs/core/internal";
|
|
2
2
|
import { isComputed } from "@praxisjs/shared/internal";
|
|
3
|
+
import { createLifecycleMethodDecorator } from "../create-lifecycle-method-decorator";
|
|
3
4
|
export function When(propName) {
|
|
4
|
-
return
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
originalOnMount?.call(this);
|
|
14
|
-
const raw = this[propName];
|
|
15
|
-
const source = isComputed(raw)
|
|
16
|
-
? raw
|
|
17
|
-
: raw;
|
|
18
|
-
const cancel = when(source, (val) => {
|
|
19
|
-
value.call(this, val);
|
|
20
|
-
});
|
|
21
|
-
cancels.set(this, cancel);
|
|
22
|
-
};
|
|
23
|
-
instance.onUnmount = function () {
|
|
24
|
-
originalOnUnmount?.call(this);
|
|
25
|
-
cancels.get(this)?.();
|
|
26
|
-
cancels.delete(this);
|
|
27
|
-
};
|
|
28
|
-
});
|
|
29
|
-
};
|
|
5
|
+
return createLifecycleMethodDecorator({
|
|
6
|
+
register(callback, instance) {
|
|
7
|
+
const raw = instance[propName];
|
|
8
|
+
const source = isComputed(raw)
|
|
9
|
+
? raw
|
|
10
|
+
: raw;
|
|
11
|
+
return when(source, (val) => { callback(val); });
|
|
12
|
+
},
|
|
13
|
+
});
|
|
30
14
|
}
|
|
31
15
|
//# sourceMappingURL=when.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"when.js","sourceRoot":"","sources":["../../src/functions/when.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"when.js","sourceRoot":"","sources":["../../src/functions/when.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAE/C,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAEvD,OAAO,EAAE,8BAA8B,EAAE,MAAM,sCAAsC,CAAC;AAEtF,MAAM,UAAU,IAAI,CAAC,QAAgB;IACnC,OAAO,8BAA8B,CAAC;QACpC,QAAQ,CAAC,QAAQ,EAAE,QAAQ;YACzB,MAAM,GAAG,GAAI,QAA+C,CAAC,QAAQ,CAAC,CAAC;YACvE,MAAM,MAAM,GAAG,UAAU,CAAC,GAAG,CAAC;gBAC5B,CAAC,CAAE,GAAyB;gBAC5B,CAAC,CAAE,GAAuB,CAAC;YAC7B,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACnD,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
export { Component, Lazy, Virtual } from "./component";
|
|
2
2
|
export { Memo, Bind, Log, Once, Retry, Debounce, Throttle, When, Watch, type WatchVal, type WatchVals, } from "./functions";
|
|
3
|
-
export { Prop, State, Computed, Persisted, Slot, initSlots, History, type WithHistory, } from "./properties";
|
|
3
|
+
export { Prop, State, Computed, Persisted, Slot, initSlots, History, type WithHistory, Compose, Resource, type ResourceInstance, type ResourceOptions, } from "./properties";
|
|
4
4
|
export { type Command, createCommand, Emit, OnCommand } from "./events";
|
|
5
|
+
export { createFieldDecorator, type FieldBehavior, type FieldBinding, } from "./create-field-decorator";
|
|
6
|
+
export { createClassDecorator, ClassBehavior, type ClassEnhancement, } from "./create-class-decorator";
|
|
7
|
+
export { createMethodDecorator, type MethodBehavior, } from "./create-method-decorator";
|
|
8
|
+
export { createLifecycleMethodDecorator, type LifecycleMethodBehavior, } from "./create-lifecycle-method-decorator";
|
|
9
|
+
export { createGetterDecorator, type GetterBehavior, createGetterObserverDecorator, type GetterObserverBehavior, } from "./create-getter-decorator";
|
|
5
10
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EACL,IAAI,EACJ,IAAI,EACJ,GAAG,EACH,IAAI,EACJ,KAAK,EACL,QAAQ,EACR,QAAQ,EACR,IAAI,EACJ,KAAK,EACL,KAAK,QAAQ,EACb,KAAK,SAAS,GACf,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,IAAI,EACJ,KAAK,EACL,QAAQ,EACR,SAAS,EACT,IAAI,EACJ,SAAS,EACT,OAAO,EACP,KAAK,WAAW,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EACL,IAAI,EACJ,IAAI,EACJ,GAAG,EACH,IAAI,EACJ,KAAK,EACL,QAAQ,EACR,QAAQ,EACR,IAAI,EACJ,KAAK,EACL,KAAK,QAAQ,EACb,KAAK,SAAS,GACf,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,IAAI,EACJ,KAAK,EACL,QAAQ,EACR,SAAS,EACT,IAAI,EACJ,SAAS,EACT,OAAO,EACP,KAAK,WAAW,EAChB,OAAO,EACP,QAAQ,EACR,KAAK,gBAAgB,EACrB,KAAK,eAAe,GACrB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,KAAK,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACxE,OAAO,EACL,oBAAoB,EACpB,KAAK,aAAa,EAClB,KAAK,YAAY,GAClB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,oBAAoB,EACpB,aAAa,EACb,KAAK,gBAAgB,GACtB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,qBAAqB,EACrB,KAAK,cAAc,GACpB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,8BAA8B,EAC9B,KAAK,uBAAuB,GAC7B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,qBAAqB,EACrB,KAAK,cAAc,EACnB,6BAA6B,EAC7B,KAAK,sBAAsB,GAC5B,MAAM,2BAA2B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
export { Component, Lazy, Virtual } from "./component";
|
|
2
2
|
export { Memo, Bind, Log, Once, Retry, Debounce, Throttle, When, Watch, } from "./functions";
|
|
3
|
-
export { Prop, State, Computed, Persisted, Slot, initSlots, History, } from "./properties";
|
|
3
|
+
export { Prop, State, Computed, Persisted, Slot, initSlots, History, Compose, Resource, } from "./properties";
|
|
4
4
|
export { createCommand, Emit, OnCommand } from "./events";
|
|
5
|
+
export { createFieldDecorator, } from "./create-field-decorator";
|
|
6
|
+
export { createClassDecorator, ClassBehavior, } from "./create-class-decorator";
|
|
7
|
+
export { createMethodDecorator, } from "./create-method-decorator";
|
|
8
|
+
export { createLifecycleMethodDecorator, } from "./create-lifecycle-method-decorator";
|
|
9
|
+
export { createGetterDecorator, createGetterObserverDecorator, } from "./create-getter-decorator";
|
|
5
10
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EACL,IAAI,EACJ,IAAI,EACJ,GAAG,EACH,IAAI,EACJ,KAAK,EACL,QAAQ,EACR,QAAQ,EACR,IAAI,EACJ,KAAK,GAGN,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,IAAI,EACJ,KAAK,EACL,QAAQ,EACR,SAAS,EACT,IAAI,EACJ,SAAS,EACT,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EACL,IAAI,EACJ,IAAI,EACJ,GAAG,EACH,IAAI,EACJ,KAAK,EACL,QAAQ,EACR,QAAQ,EACR,IAAI,EACJ,KAAK,GAGN,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,IAAI,EACJ,KAAK,EACL,QAAQ,EACR,SAAS,EACT,IAAI,EACJ,SAAS,EACT,OAAO,EAEP,OAAO,EACP,QAAQ,GAGT,MAAM,cAAc,CAAC;AACtB,OAAO,EAAgB,aAAa,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACxE,OAAO,EACL,oBAAoB,GAGrB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,oBAAoB,EACpB,aAAa,GAEd,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,qBAAqB,GAEtB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,8BAA8B,GAE/B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,qBAAqB,EAErB,6BAA6B,GAE9B,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { StatefulComponent, Composable } from "@praxisjs/core";
|
|
2
|
+
export declare function Compose(ComposableClass: new (...args: any[]) => Composable, ...ctorArgs: unknown[]): (_value: undefined, context: ClassFieldDecoratorContext<StatefulComponent>) => void;
|
|
3
|
+
//# sourceMappingURL=compose.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compose.d.ts","sourceRoot":"","sources":["../../src/properties/compose.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AA6BpE,wBAAgB,OAAO,CAErB,eAAe,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,UAAU,EACnD,GAAG,QAAQ,EAAE,OAAO,EAAE,uFAoBvB"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { createFieldDecorator } from "../create-field-decorator";
|
|
2
|
+
function isReactive(value) {
|
|
3
|
+
return (typeof value === "function" &&
|
|
4
|
+
("__isSignal" in value || "__isComputed" in value));
|
|
5
|
+
}
|
|
6
|
+
function buildView(bindings) {
|
|
7
|
+
const view = {};
|
|
8
|
+
for (const [key, value] of Object.entries(bindings)) {
|
|
9
|
+
if (isReactive(value)) {
|
|
10
|
+
Object.defineProperty(view, key, {
|
|
11
|
+
get: () => value(),
|
|
12
|
+
enumerable: true,
|
|
13
|
+
configurable: true,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
view[key] = value;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return view;
|
|
21
|
+
}
|
|
22
|
+
export function Compose(
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
|
+
ComposableClass, ...ctorArgs) {
|
|
25
|
+
return createFieldDecorator({
|
|
26
|
+
bind(instance, _name, _initialValue) {
|
|
27
|
+
const resolvedArgs = ctorArgs.map((arg) => typeof arg === "string"
|
|
28
|
+
? instance[arg]
|
|
29
|
+
: arg);
|
|
30
|
+
const composable = new ComposableClass(...resolvedArgs);
|
|
31
|
+
const view = buildView(composable.setup());
|
|
32
|
+
return {
|
|
33
|
+
descriptor: { get: () => view },
|
|
34
|
+
onMount: composable.onMount?.bind(composable),
|
|
35
|
+
onUnmount: composable.onUnmount?.bind(composable),
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=compose.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compose.js","sourceRoot":"","sources":["../../src/properties/compose.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,SAAS,UAAU,CACjB,KAAc;IAEd,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,EAAE,CAAE,KAAuB,EAAE;gBACrC,UAAU,EAAE,IAAI;gBAChB,YAAY,EAAE,IAAI;aACnB,CAAC,CAAC;QACL,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACpB,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,OAAO;AACrB,8DAA8D;AAC9D,eAAmD,EACnD,GAAG,QAAmB;IAEtB,OAAO,oBAAoB,CAAC;QAC1B,IAAI,CAAC,QAA2B,EAAE,KAAa,EAAE,aAAsB;YACrE,MAAM,YAAY,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CACxC,OAAO,GAAG,KAAK,QAAQ;gBACrB,CAAC,CAAE,QAA+C,CAAC,GAAG,CAAC;gBACvD,CAAC,CAAC,GAAG,CACR,CAAC;YAEF,MAAM,UAAU,GAAG,IAAI,eAAe,CAAC,GAAG,YAAY,CAAC,CAAC;YACxD,MAAM,IAAI,GAAG,SAAS,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC;YAE3C,OAAO;gBACL,UAAU,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE;gBAC/B,OAAO,EAAE,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC;gBAC7C,SAAS,EAAE,UAAU,CAAC,SAAS,EAAE,IAAI,CAAC,UAAU,CAAC;aAClD,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function Computed(): <This extends StatefulComponent, T>(target: (this: This) => T, _context: ClassGetterDecoratorContext<This, T>) => (this: This) => T;
|
|
1
|
+
export declare function Computed(): <This, T>(target: (this: This) => T, _context: ClassGetterDecoratorContext<This, T>) => (this: This) => T;
|
|
3
2
|
//# 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":"AAIA,wBAAgB,QAAQ,8GAavB"}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { computed } from "@praxisjs/core/internal";
|
|
2
|
+
import { createGetterDecorator } from "../create-getter-decorator";
|
|
2
3
|
export function Computed() {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
let c =
|
|
4
|
+
const cache = new WeakMap();
|
|
5
|
+
return createGetterDecorator({
|
|
6
|
+
wrap(original, instance) {
|
|
7
|
+
let c = cache.get(instance);
|
|
7
8
|
if (!c) {
|
|
8
|
-
c = computed(() =>
|
|
9
|
-
|
|
9
|
+
c = computed(() => original.call(instance));
|
|
10
|
+
cache.set(instance, c);
|
|
10
11
|
}
|
|
11
|
-
return c
|
|
12
|
-
}
|
|
13
|
-
};
|
|
12
|
+
return c;
|
|
13
|
+
},
|
|
14
|
+
});
|
|
14
15
|
}
|
|
15
16
|
//# sourceMappingURL=computed.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"computed.js","sourceRoot":"","sources":["../../src/properties/computed.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"computed.js","sourceRoot":"","sources":["../../src/properties/computed.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAEnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE,MAAM,UAAU,QAAQ;IACtB,MAAM,KAAK,GAAG,IAAI,OAAO,EAAyB,CAAC;IAEnD,OAAO,qBAAqB,CAAC;QAC3B,IAAI,CAAC,QAAQ,EAAE,QAAQ;YACrB,IAAI,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YAC5B,IAAI,CAAC,CAAC,EAAE,CAAC;gBACP,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;gBAC5C,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;YACzB,CAAC;YACD,OAAO,CAAC,CAAC;QACX,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"history.d.ts","sourceRoot":"","sources":["../../src/properties/history.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,KAAK,cAAc,EAAW,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"history.d.ts","sourceRoot":"","sources":["../../src/properties/history.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,KAAK,cAAc,EAAW,MAAM,yBAAyB,CAAC;AAKvE,MAAM,MAAM,WAAW,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,MAAM,CACpD,GAAG,MAAM,GAAG,CAAC,SAAS,EACtB,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CACrB,CAAC;AAEF,wBAAgB,OAAO,CAAC,KAAK,SAAK,uFA0CjC"}
|
|
@@ -1,37 +1,42 @@
|
|
|
1
1
|
import { history } from "@praxisjs/core/internal";
|
|
2
|
+
import { createFieldDecorator } from "../create-field-decorator";
|
|
2
3
|
export function History(limit = 50) {
|
|
3
|
-
return
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
4
|
+
return createFieldDecorator({
|
|
5
|
+
bind(instance, name, _initialValue) {
|
|
6
|
+
const historyKey = `${name}History`;
|
|
7
|
+
const inst = instance;
|
|
8
|
+
let h;
|
|
9
|
+
return {
|
|
10
|
+
// descriptor omitted — @History does not replace the original field
|
|
11
|
+
additional: {
|
|
12
|
+
[historyKey]: {
|
|
13
|
+
get() {
|
|
14
|
+
if (!h) {
|
|
15
|
+
const source = () => inst[name];
|
|
16
|
+
const hInst = history(source, limit);
|
|
17
|
+
const _undo = hInst.undo.bind(hInst);
|
|
18
|
+
const _redo = hInst.redo.bind(hInst);
|
|
19
|
+
hInst.undo = () => {
|
|
20
|
+
const prev = hInst.values()[hInst.values().length - 2];
|
|
21
|
+
if (prev === undefined)
|
|
22
|
+
return;
|
|
23
|
+
_undo();
|
|
24
|
+
inst[name] = prev;
|
|
25
|
+
};
|
|
26
|
+
hInst.redo = () => {
|
|
27
|
+
_redo();
|
|
28
|
+
inst[name] = hInst.current();
|
|
29
|
+
};
|
|
30
|
+
h = hInst;
|
|
31
|
+
}
|
|
32
|
+
return h;
|
|
33
|
+
},
|
|
34
|
+
enumerable: false,
|
|
35
|
+
configurable: true,
|
|
36
|
+
},
|
|
30
37
|
},
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
});
|
|
35
|
-
};
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
});
|
|
36
41
|
}
|
|
37
42
|
//# sourceMappingURL=history.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"history.js","sourceRoot":"","sources":["../../src/properties/history.ts"],"names":[],"mappings":"AACA,OAAO,EAAuB,OAAO,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"history.js","sourceRoot":"","sources":["../../src/properties/history.ts"],"names":[],"mappings":"AACA,OAAO,EAAuB,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAGvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAOjE,MAAM,UAAU,OAAO,CAAC,KAAK,GAAG,EAAE;IAChC,OAAO,oBAAoB,CAAC;QAC1B,IAAI,CAAC,QAA2B,EAAE,IAAY,EAAE,aAAsB;YACpE,MAAM,UAAU,GAAG,GAAG,IAAI,SAAS,CAAC;YACpC,MAAM,IAAI,GAAG,QAA8C,CAAC;YAC5D,IAAI,CAAsC,CAAC;YAE3C,OAAO;gBACL,oEAAoE;gBACpE,UAAU,EAAE;oBACV,CAAC,UAAU,CAAC,EAAE;wBACZ,GAAG;4BACD,IAAI,CAAC,CAAC,EAAE,CAAC;gCACP,MAAM,MAAM,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gCAChC,MAAM,KAAK,GAAG,OAAO,CAAC,MAAyB,EAAE,KAAK,CAAC,CAAC;gCAExD,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gCACrC,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gCAErC,KAAK,CAAC,IAAI,GAAG,GAAG,EAAE;oCAChB,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;oCACvD,IAAI,IAAI,KAAK,SAAS;wCAAE,OAAO;oCAC/B,KAAK,EAAE,CAAC;oCACR,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;gCACpB,CAAC,CAAC;gCAEF,KAAK,CAAC,IAAI,GAAG,GAAG,EAAE;oCAChB,KAAK,EAAE,CAAC;oCACR,IAAI,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,OAAO,EAAE,CAAC;gCAC/B,CAAC,CAAC;gCAEF,CAAC,GAAG,KAAK,CAAC;4BACZ,CAAC;4BACD,OAAO,CAAC,CAAC;wBACX,CAAC;wBACD,UAAU,EAAE,KAAK;wBACjB,YAAY,EAAE,IAAI;qBACnB;iBACF;aACF,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -4,4 +4,6 @@ export { Computed } from "./computed";
|
|
|
4
4
|
export { Persisted } from "./persisted";
|
|
5
5
|
export { Slot, initSlots } from "./slot";
|
|
6
6
|
export { History, type WithHistory } from "./history";
|
|
7
|
+
export { Compose } from "./compose";
|
|
8
|
+
export { Resource, type ResourceInstance, type ResourceOptions } from "./resource";
|
|
7
9
|
//# 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,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,WAAW,EAAE,MAAM,WAAW,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,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,WAAW,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,KAAK,gBAAgB,EAAE,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/properties/index.js
CHANGED
|
@@ -4,4 +4,6 @@ export { Computed } from "./computed";
|
|
|
4
4
|
export { Persisted } from "./persisted";
|
|
5
5
|
export { Slot, initSlots } from "./slot";
|
|
6
6
|
export { History } from "./history";
|
|
7
|
+
export { Compose } from "./compose";
|
|
8
|
+
export { Resource } from "./resource";
|
|
7
9
|
//# sourceMappingURL=index.js.map
|
|
@@ -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,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,EAAoB,MAAM,WAAW,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,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,EAAoB,MAAM,WAAW,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,QAAQ,EAA+C,MAAM,YAAY,CAAC"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { StatefulComponent } from "@praxisjs/core";
|
|
2
1
|
import { type PersistedSignalOptions } from "@praxisjs/core/internal";
|
|
3
|
-
export declare function Persisted<T>(key?: string, options?: PersistedSignalOptions<T>): (_value: undefined, context: ClassFieldDecoratorContext<StatefulComponent>) => void;
|
|
2
|
+
export declare function Persisted<T>(key?: string, options?: PersistedSignalOptions<T>): (_value: undefined, context: ClassFieldDecoratorContext<import("@praxisjs/core").StatefulComponent>) => void;
|
|
4
3
|
//# 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,EAAmB,KAAK,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAwBvF,wBAAgB,SAAS,CAAC,CAAC,EACzB,GAAG,CAAC,EAAE,MAAM,EACZ,OAAO,GAAE,sBAAsB,CAAC,CAAC,CAAM,gHAgBxC"}
|
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
import { persistedSignal
|
|
1
|
+
import { persistedSignal } from "@praxisjs/core/internal";
|
|
2
|
+
import { createFieldDecorator } from "../create-field-decorator";
|
|
2
3
|
const signalMap = new WeakMap();
|
|
3
|
-
const initMap = new WeakMap();
|
|
4
|
-
function markInitialized(instance, propKey) {
|
|
5
|
-
if (!initMap.has(instance)) {
|
|
6
|
-
initMap.set(instance, new Set());
|
|
7
|
-
}
|
|
8
|
-
initMap.get(instance).add(propKey);
|
|
9
|
-
}
|
|
10
4
|
function getOrCreateSignal(instance, storageKey, initialValue, options) {
|
|
11
|
-
if (!signalMap.has(instance))
|
|
5
|
+
if (!signalMap.has(instance))
|
|
12
6
|
signalMap.set(instance, new Map());
|
|
13
|
-
}
|
|
14
7
|
const map = signalMap.get(instance);
|
|
15
8
|
if (!map.has(storageKey)) {
|
|
16
9
|
map.set(storageKey, persistedSignal(storageKey, initialValue, options));
|
|
@@ -18,26 +11,17 @@ function getOrCreateSignal(instance, storageKey, initialValue, options) {
|
|
|
18
11
|
return map.get(storageKey);
|
|
19
12
|
}
|
|
20
13
|
export function Persisted(key, options = {}) {
|
|
21
|
-
return
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
const propertyKey = context.name;
|
|
25
|
-
const storageKey = key ?? propertyKey;
|
|
26
|
-
const initialValue = instance[propertyKey];
|
|
27
|
-
Reflect.deleteProperty(instance, propertyKey);
|
|
28
|
-
markInitialized(instance, propertyKey);
|
|
14
|
+
return createFieldDecorator({
|
|
15
|
+
bind(instance, name, initialValue) {
|
|
16
|
+
const storageKey = key ?? name;
|
|
29
17
|
getOrCreateSignal(instance, storageKey, initialValue, options);
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
set(value) {
|
|
35
|
-
getOrCreateSignal(instance, storageKey, undefined, options).set(value);
|
|
18
|
+
return {
|
|
19
|
+
descriptor: {
|
|
20
|
+
get: () => getOrCreateSignal(instance, storageKey, undefined, options)(),
|
|
21
|
+
set: (value) => { getOrCreateSignal(instance, storageKey, undefined, options).set(value); },
|
|
36
22
|
},
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
});
|
|
41
|
-
};
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
});
|
|
42
26
|
}
|
|
43
27
|
//# sourceMappingURL=persisted.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"persisted.js","sourceRoot":"","sources":["../../src/properties/persisted.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"persisted.js","sourceRoot":"","sources":["../../src/properties/persisted.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAA+B,MAAM,yBAAyB,CAAC;AAGvF,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,MAAM,SAAS,GAAG,IAAI,OAAO,EAAwC,CAAC;AAEtE,SAAS,iBAAiB,CACxB,QAAgB,EAChB,UAAkB,EAClB,YAAe,EACf,OAAkC;IAElC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC;QAAE,SAAS,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;IACjE,MAAM,GAAG,GAAG,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAiC,CAAC;IACpE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC;QACzB,GAAG,CAAC,GAAG,CACL,UAAU,EACV,eAAe,CAAC,UAAU,EAAE,YAAY,EAAE,OAAO,CAAoB,CACtE,CAAC;IACJ,CAAC;IACD,OAAO,GAAG,CAAC,GAAG,CAAC,UAAU,CAAc,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,SAAS,CACvB,GAAY,EACZ,UAAqC,EAAE;IAEvC,OAAO,oBAAoB,CAAC;QAC1B,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,YAAY;YAC/B,MAAM,UAAU,GAAG,GAAG,IAAI,IAAI,CAAC;YAC/B,iBAAiB,CAAC,QAAQ,EAAE,UAAU,EAAE,YAAiB,EAAE,OAAO,CAAC,CAAC;YACpE,OAAO;gBACL,UAAU,EAAE;oBACV,GAAG,EAAE,GAAG,EAAE,CACR,iBAAiB,CAAI,QAAQ,EAAE,UAAU,EAAE,SAAc,EAAE,OAAO,CAAC,EAAE;oBACvE,GAAG,EAAE,CAAC,KAAQ,EAAE,EAAE,GACd,iBAAiB,CAAI,QAAQ,EAAE,UAAU,EAAE,SAAc,EAAE,OAAO,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;iBACtF;aACF,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function Prop(): (_value: undefined, context: ClassFieldDecoratorContext<StatefulComponent>) => void;
|
|
1
|
+
export declare function Prop(): (_value: undefined, context: ClassFieldDecoratorContext<import("@praxisjs/core").StatefulComponent>) => void;
|
|
3
2
|
//# 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":"AAEA,wBAAgB,IAAI,iHAsBnB"}
|
package/dist/properties/prop.js
CHANGED
|
@@ -1,29 +1,25 @@
|
|
|
1
|
+
import { createFieldDecorator } from "../create-field-decorator";
|
|
1
2
|
export function Prop() {
|
|
2
|
-
return
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
3
|
+
return createFieldDecorator({
|
|
4
|
+
bind(instance, name, initialValue) {
|
|
5
|
+
instance._defaults[name] = initialValue;
|
|
6
|
+
return {
|
|
7
|
+
descriptor: {
|
|
8
|
+
get() {
|
|
9
|
+
const fromParent = (instance._rawProps)[name];
|
|
10
|
+
if (fromParent !== undefined) {
|
|
11
|
+
return typeof fromParent === "function"
|
|
12
|
+
? fromParent()
|
|
13
|
+
: fromParent;
|
|
14
|
+
}
|
|
15
|
+
return instance._defaults[name];
|
|
16
|
+
},
|
|
17
|
+
set(value) {
|
|
18
|
+
instance._defaults[name] = value;
|
|
19
|
+
},
|
|
19
20
|
},
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
enumerable: true,
|
|
24
|
-
configurable: true,
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
};
|
|
21
|
+
};
|
|
22
|
+
},
|
|
23
|
+
});
|
|
28
24
|
}
|
|
29
25
|
//# 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":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,MAAM,UAAU,IAAI;IAClB,OAAO,oBAAoB,CAAC;QAC1B,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,YAAY;YAC/B,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC;YACxC,OAAO;gBACL,UAAU,EAAE;oBACV,GAAG;wBACD,MAAM,UAAU,GAAG,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC;wBAC9C,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;4BAC7B,OAAO,OAAO,UAAU,KAAK,UAAU;gCACrC,CAAC,CAAE,UAA4B,EAAE;gCACjC,CAAC,CAAC,UAAU,CAAC;wBACjB,CAAC;wBACD,OAAO,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;oBAClC,CAAC;oBACD,GAAG,CAAC,KAAc;wBAChB,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;oBACnC,CAAC;iBACF;aACF,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type Resource as ResourceInstance, type ResourceOptions } from "@praxisjs/core/internal";
|
|
2
|
+
export type { ResourceInstance, ResourceOptions };
|
|
3
|
+
/**
|
|
4
|
+
* Binds an async resource to the field. The field holds a Resource<T> object
|
|
5
|
+
* with reactive data, pending, error, and status signals, plus refetch/cancel/mutate methods.
|
|
6
|
+
*
|
|
7
|
+
* class MyComponent extends StatefulComponent {
|
|
8
|
+
* @Resource(() => api.getUsers())
|
|
9
|
+
* users!: ResourceInstance<User[]>;
|
|
10
|
+
* // access: this.users.data(), this.users.pending(), this.users.refetch()
|
|
11
|
+
* }
|
|
12
|
+
*/
|
|
13
|
+
export declare function Resource<T>(fetcher: () => Promise<T>, options?: ResourceOptions<T>): (_value: undefined, context: ClassFieldDecoratorContext<import("@praxisjs/core").StatefulComponent>) => void;
|
|
14
|
+
//# sourceMappingURL=resource.d.ts.map
|
|
@@ -0,0 +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;AAIjC,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE,CAAC;AAElD;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,GAAE,eAAe,CAAC,CAAC,CAAM,gHAatF"}
|