@praxisjs/decorators 0.4.2 → 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 +43 -0
- package/dist/__tests__/component.test.d.ts +2 -0
- package/dist/__tests__/component.test.d.ts.map +1 -0
- package/dist/__tests__/component.test.js +146 -0
- package/dist/__tests__/component.test.js.map +1 -0
- 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.d.ts +2 -0
- package/dist/__tests__/events.test.d.ts.map +1 -0
- package/dist/__tests__/events.test.js +216 -0
- package/dist/__tests__/events.test.js.map +1 -0
- package/dist/__tests__/functions.test.js +283 -31
- package/dist/__tests__/functions.test.js.map +1 -1
- package/dist/__tests__/lazy.test.d.ts +2 -0
- package/dist/__tests__/lazy.test.d.ts.map +1 -0
- package/dist/__tests__/lazy.test.js +163 -0
- package/dist/__tests__/lazy.test.js.map +1 -0
- package/dist/__tests__/memo.test.js +71 -22
- package/dist/__tests__/memo.test.js.map +1 -1
- package/dist/__tests__/properties.test.js +191 -1
- package/dist/__tests__/properties.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.d.ts +2 -0
- package/dist/__tests__/slot.test.d.ts.map +1 -0
- package/dist/__tests__/slot.test.js +147 -0
- package/dist/__tests__/slot.test.js.map +1 -0
- package/dist/__tests__/virtual.test.d.ts +2 -0
- package/dist/__tests__/virtual.test.d.ts.map +1 -0
- package/dist/__tests__/virtual.test.js +242 -0
- package/dist/__tests__/virtual.test.js.map +1 -0
- 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 +1 -1
- package/dist/component/lazy.d.ts.map +1 -1
- package/dist/component/lazy.js +29 -27
- package/dist/component/lazy.js.map +1 -1
- package/dist/component/virtual.d.ts +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 -31
- 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 +166 -0
- package/src/__tests__/compose.test.ts +202 -0
- package/src/__tests__/events.test.ts +268 -0
- package/src/__tests__/functions.test.ts +368 -30
- package/src/__tests__/lazy.test.ts +218 -0
- package/src/__tests__/memo.test.ts +89 -22
- package/src/__tests__/properties.test.ts +249 -1
- package/src/__tests__/resource.test.ts +113 -0
- package/src/__tests__/slot.test.ts +179 -0
- package/src/__tests__/virtual.test.ts +260 -0
- package/src/component/component.ts +27 -12
- package/src/component/lazy.ts +33 -35
- 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 -34
- 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
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
import type { StatefulComponent } from "@praxisjs/core";
|
|
2
1
|
import { computed } from "@praxisjs/core/internal";
|
|
3
2
|
|
|
3
|
+
import { createGetterDecorator } from "../create-getter-decorator";
|
|
4
|
+
|
|
4
5
|
export function Computed() {
|
|
5
|
-
|
|
6
|
-
target: (this: This) => T,
|
|
7
|
-
_context: ClassGetterDecoratorContext<This, T>,
|
|
8
|
-
): (this: This) => T {
|
|
9
|
-
const computedMap = new WeakMap<object, () => T>();
|
|
6
|
+
const cache = new WeakMap<object, () => unknown>();
|
|
10
7
|
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
return createGetterDecorator({
|
|
9
|
+
wrap(original, instance) {
|
|
10
|
+
let c = cache.get(instance);
|
|
13
11
|
if (!c) {
|
|
14
|
-
c = computed(() =>
|
|
15
|
-
|
|
12
|
+
c = computed(() => original.call(instance));
|
|
13
|
+
cache.set(instance, c);
|
|
16
14
|
}
|
|
17
|
-
return c
|
|
18
|
-
}
|
|
19
|
-
};
|
|
15
|
+
return c;
|
|
16
|
+
},
|
|
17
|
+
});
|
|
20
18
|
}
|
|
@@ -2,52 +2,53 @@ import type { StatefulComponent } from "@praxisjs/core";
|
|
|
2
2
|
import { type HistoryElement, history } from "@praxisjs/core/internal";
|
|
3
3
|
import type { Signal } from "@praxisjs/shared";
|
|
4
4
|
|
|
5
|
+
import { createFieldDecorator } from "../create-field-decorator";
|
|
6
|
+
|
|
5
7
|
export type WithHistory<T, K extends keyof T> = Record<
|
|
6
8
|
`${string & K}History`,
|
|
7
9
|
HistoryElement<T[K]>
|
|
8
10
|
>;
|
|
9
11
|
|
|
10
12
|
export function History(limit = 50) {
|
|
11
|
-
return
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
13
|
+
return createFieldDecorator({
|
|
14
|
+
bind(instance: StatefulComponent, name: string, _initialValue: unknown) {
|
|
15
|
+
const historyKey = `${name}History`;
|
|
16
|
+
const inst = instance as unknown as Record<string, unknown>;
|
|
17
|
+
let h: HistoryElement<unknown> | undefined;
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
// descriptor omitted — @History does not replace the original field
|
|
21
|
+
additional: {
|
|
22
|
+
[historyKey]: {
|
|
23
|
+
get(): HistoryElement<unknown> {
|
|
24
|
+
if (!h) {
|
|
25
|
+
const source = () => inst[name];
|
|
26
|
+
const hInst = history(source as Signal<unknown>, limit);
|
|
27
|
+
|
|
28
|
+
const _undo = hInst.undo.bind(hInst);
|
|
29
|
+
const _redo = hInst.redo.bind(hInst);
|
|
30
|
+
|
|
31
|
+
hInst.undo = () => {
|
|
32
|
+
const prev = hInst.values()[hInst.values().length - 2];
|
|
33
|
+
if (prev === undefined) return;
|
|
34
|
+
_undo();
|
|
35
|
+
inst[name] = prev;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
hInst.redo = () => {
|
|
39
|
+
_redo();
|
|
40
|
+
inst[name] = hInst.current();
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
h = hInst;
|
|
44
|
+
}
|
|
45
|
+
return h;
|
|
46
|
+
},
|
|
47
|
+
enumerable: false,
|
|
48
|
+
configurable: true,
|
|
49
|
+
},
|
|
47
50
|
},
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
});
|
|
52
|
-
};
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
});
|
|
53
54
|
}
|
package/src/properties/index.ts
CHANGED
|
@@ -4,3 +4,5 @@ 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";
|
|
@@ -1,19 +1,9 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import {
|
|
3
|
-
persistedSignal,
|
|
4
|
-
type PersistedSignalOptions,
|
|
5
|
-
} from "@praxisjs/core/internal";
|
|
1
|
+
import { persistedSignal, type PersistedSignalOptions } from "@praxisjs/core/internal";
|
|
6
2
|
import type { Signal } from "@praxisjs/shared";
|
|
7
3
|
|
|
8
|
-
|
|
9
|
-
const initMap = new WeakMap<object, Set<string>>();
|
|
4
|
+
import { createFieldDecorator } from "../create-field-decorator";
|
|
10
5
|
|
|
11
|
-
|
|
12
|
-
if (!initMap.has(instance)) {
|
|
13
|
-
initMap.set(instance, new Set());
|
|
14
|
-
}
|
|
15
|
-
(initMap.get(instance) as Set<string>).add(propKey);
|
|
16
|
-
}
|
|
6
|
+
const signalMap = new WeakMap<object, Map<string, Signal<unknown>>>();
|
|
17
7
|
|
|
18
8
|
function getOrCreateSignal<T>(
|
|
19
9
|
instance: object,
|
|
@@ -21,18 +11,14 @@ function getOrCreateSignal<T>(
|
|
|
21
11
|
initialValue: T,
|
|
22
12
|
options: PersistedSignalOptions<T>,
|
|
23
13
|
): Signal<T> {
|
|
24
|
-
if (!signalMap.has(instance))
|
|
25
|
-
signalMap.set(instance, new Map());
|
|
26
|
-
}
|
|
14
|
+
if (!signalMap.has(instance)) signalMap.set(instance, new Map());
|
|
27
15
|
const map = signalMap.get(instance) as Map<string, Signal<unknown>>;
|
|
28
|
-
|
|
29
16
|
if (!map.has(storageKey)) {
|
|
30
17
|
map.set(
|
|
31
18
|
storageKey,
|
|
32
19
|
persistedSignal(storageKey, initialValue, options) as Signal<unknown>,
|
|
33
20
|
);
|
|
34
21
|
}
|
|
35
|
-
|
|
36
22
|
return map.get(storageKey) as Signal<T>;
|
|
37
23
|
}
|
|
38
24
|
|
|
@@ -40,45 +26,18 @@ export function Persisted<T>(
|
|
|
40
26
|
key?: string,
|
|
41
27
|
options: PersistedSignalOptions<T> = {},
|
|
42
28
|
) {
|
|
43
|
-
return
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
] as T;
|
|
54
|
-
|
|
55
|
-
Reflect.deleteProperty(instance, propertyKey);
|
|
56
|
-
|
|
57
|
-
markInitialized(instance, propertyKey);
|
|
58
|
-
getOrCreateSignal(instance, storageKey, initialValue, options);
|
|
59
|
-
|
|
60
|
-
Object.defineProperty(instance, propertyKey, {
|
|
61
|
-
get(): T {
|
|
62
|
-
return getOrCreateSignal<T>(
|
|
63
|
-
instance,
|
|
64
|
-
storageKey,
|
|
65
|
-
undefined as T,
|
|
66
|
-
options,
|
|
67
|
-
)();
|
|
29
|
+
return createFieldDecorator({
|
|
30
|
+
bind(instance, name, initialValue) {
|
|
31
|
+
const storageKey = key ?? name;
|
|
32
|
+
getOrCreateSignal(instance, storageKey, initialValue as T, options);
|
|
33
|
+
return {
|
|
34
|
+
descriptor: {
|
|
35
|
+
get: () =>
|
|
36
|
+
getOrCreateSignal<T>(instance, storageKey, undefined as T, options)(),
|
|
37
|
+
set: (value: T) =>
|
|
38
|
+
{ getOrCreateSignal<T>(instance, storageKey, undefined as T, options).set(value); },
|
|
68
39
|
},
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
instance,
|
|
73
|
-
storageKey,
|
|
74
|
-
undefined as T,
|
|
75
|
-
options,
|
|
76
|
-
).set(value);
|
|
77
|
-
},
|
|
78
|
-
|
|
79
|
-
enumerable: true,
|
|
80
|
-
configurable: true,
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
};
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
});
|
|
84
43
|
}
|
package/src/properties/prop.ts
CHANGED
|
@@ -1,35 +1,25 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { createFieldDecorator } from "../create-field-decorator";
|
|
2
2
|
|
|
3
3
|
export function Prop() {
|
|
4
|
-
return
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return typeof fromParent === "function"
|
|
22
|
-
? (fromParent as () => unknown)()
|
|
23
|
-
: fromParent;
|
|
24
|
-
}
|
|
25
|
-
return this._defaults[name];
|
|
26
|
-
},
|
|
27
|
-
set(this: StatefulComponent, value: unknown) {
|
|
28
|
-
this._defaults[name] = value;
|
|
4
|
+
return createFieldDecorator({
|
|
5
|
+
bind(instance, name, initialValue) {
|
|
6
|
+
instance._defaults[name] = initialValue;
|
|
7
|
+
return {
|
|
8
|
+
descriptor: {
|
|
9
|
+
get() {
|
|
10
|
+
const fromParent = (instance._rawProps)[name];
|
|
11
|
+
if (fromParent !== undefined) {
|
|
12
|
+
return typeof fromParent === "function"
|
|
13
|
+
? (fromParent as () => unknown)()
|
|
14
|
+
: fromParent;
|
|
15
|
+
}
|
|
16
|
+
return instance._defaults[name];
|
|
17
|
+
},
|
|
18
|
+
set(value: unknown) {
|
|
19
|
+
instance._defaults[name] = value;
|
|
20
|
+
},
|
|
29
21
|
},
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
});
|
|
34
|
-
};
|
|
22
|
+
};
|
|
23
|
+
},
|
|
24
|
+
});
|
|
35
25
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
resource,
|
|
3
|
+
type Resource as ResourceInstance,
|
|
4
|
+
type ResourceOptions,
|
|
5
|
+
} from "@praxisjs/core/internal";
|
|
6
|
+
|
|
7
|
+
import { createFieldDecorator, type FieldBinding } from "../create-field-decorator";
|
|
8
|
+
|
|
9
|
+
export type { ResourceInstance, ResourceOptions };
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Binds an async resource to the field. The field holds a Resource<T> object
|
|
13
|
+
* with reactive data, pending, error, and status signals, plus refetch/cancel/mutate methods.
|
|
14
|
+
*
|
|
15
|
+
* class MyComponent extends StatefulComponent {
|
|
16
|
+
* @Resource(() => api.getUsers())
|
|
17
|
+
* users!: ResourceInstance<User[]>;
|
|
18
|
+
* // access: this.users.data(), this.users.pending(), this.users.refetch()
|
|
19
|
+
* }
|
|
20
|
+
*/
|
|
21
|
+
export function Resource<T>(fetcher: () => Promise<T>, options: ResourceOptions<T> = {}) {
|
|
22
|
+
return createFieldDecorator({
|
|
23
|
+
bind(_instance, _name, _initialValue): FieldBinding {
|
|
24
|
+
const r = resource(fetcher, options);
|
|
25
|
+
return {
|
|
26
|
+
descriptor: {
|
|
27
|
+
get(): ResourceInstance<T> { return r; },
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
29
|
+
set(): void {},
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
}
|
package/src/properties/slot.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { createFieldDecorator } from "../create-field-decorator";
|
|
2
2
|
|
|
3
3
|
const slotsMap = new WeakMap<object, Map<string, unknown[]>>();
|
|
4
4
|
|
|
@@ -14,7 +14,6 @@ function resolveSlots(children: unknown): Map<string, unknown[]> {
|
|
|
14
14
|
: [children];
|
|
15
15
|
|
|
16
16
|
for (const child of arr) {
|
|
17
|
-
// Named slots via `slot` attribute on DOM elements
|
|
18
17
|
if (child instanceof Element) {
|
|
19
18
|
const slotName = child.getAttribute("slot");
|
|
20
19
|
if (slotName) {
|
|
@@ -39,33 +38,21 @@ export function getSlot(instance: object, name: string): unknown[] {
|
|
|
39
38
|
}
|
|
40
39
|
|
|
41
40
|
export function Slot(name?: string) {
|
|
42
|
-
return
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return getSlot(this, slotName);
|
|
41
|
+
return createFieldDecorator({
|
|
42
|
+
bind(instance, propName, _initialValue) {
|
|
43
|
+
const slotName = name ?? (propName === "default" ? "default" : propName);
|
|
44
|
+
return {
|
|
45
|
+
descriptor: {
|
|
46
|
+
get: () => getSlot(instance, slotName),
|
|
47
|
+
set: (_value: unknown) => {
|
|
48
|
+
if (process.env.NODE_ENV !== "production") {
|
|
49
|
+
console.warn(
|
|
50
|
+
`[Slot] "${propName}" is a slot and cannot be assigned directly. Slots are filled by the parent component.`,
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
},
|
|
56
54
|
},
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
console.warn(
|
|
61
|
-
`[Slot] "${propKey}" is a slot and cannot be assigned directly. Slots are filled by the parent component.`,
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
|
|
66
|
-
enumerable: true,
|
|
67
|
-
configurable: true,
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
};
|
|
55
|
+
};
|
|
56
|
+
},
|
|
57
|
+
});
|
|
71
58
|
}
|
package/src/properties/state.ts
CHANGED
|
@@ -1,30 +1,20 @@
|
|
|
1
|
-
import type { StatefulComponent } from "@praxisjs/core";
|
|
2
1
|
import { signal } from "@praxisjs/core/internal";
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
return function (
|
|
6
|
-
_value: undefined,
|
|
7
|
-
context: ClassFieldDecoratorContext<StatefulComponent>,
|
|
8
|
-
): void {
|
|
9
|
-
context.addInitializer(function (this: unknown) {
|
|
10
|
-
const instance = this as StatefulComponent & Record<string, unknown>;
|
|
11
|
-
const name = context.name as string;
|
|
12
|
-
const initialValue = instance[name];
|
|
13
|
-
Reflect.deleteProperty(instance, name);
|
|
3
|
+
import { createFieldDecorator } from "../create-field-decorator";
|
|
14
4
|
|
|
5
|
+
export function State() {
|
|
6
|
+
return createFieldDecorator({
|
|
7
|
+
bind(instance, _name, initialValue) {
|
|
15
8
|
const sig = signal(initialValue);
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
sig.set(value);
|
|
9
|
+
return {
|
|
10
|
+
descriptor: {
|
|
11
|
+
get: () => sig(),
|
|
12
|
+
set: (value: unknown) => {
|
|
13
|
+
instance._stateDirty = true;
|
|
14
|
+
sig.set(value);
|
|
15
|
+
},
|
|
24
16
|
},
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
});
|
|
29
|
-
};
|
|
17
|
+
};
|
|
18
|
+
},
|
|
19
|
+
});
|
|
30
20
|
}
|