@praxisjs/decorators 0.4.2 → 0.4.3
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 +18 -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 +137 -0
- package/dist/__tests__/component.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 +190 -0
- package/dist/__tests__/events.test.js.map +1 -0
- package/dist/__tests__/functions.test.js +157 -0
- 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 +165 -0
- package/dist/__tests__/lazy.test.js.map +1 -0
- package/dist/__tests__/memo.test.js +13 -0
- 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__/slot.test.d.ts +2 -0
- package/dist/__tests__/slot.test.d.ts.map +1 -0
- package/dist/__tests__/slot.test.js +115 -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 +201 -0
- package/dist/__tests__/virtual.test.js.map +1 -0
- package/dist/component/lazy.d.ts +1 -1
- package/dist/component/lazy.d.ts.map +1 -1
- package/dist/component/lazy.js +4 -1
- 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/functions/watch.d.ts.map +1 -1
- package/dist/functions/watch.js +10 -2
- package/dist/functions/watch.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/component.test.ts +156 -0
- package/src/__tests__/events.test.ts +236 -0
- package/src/__tests__/functions.test.ts +207 -0
- package/src/__tests__/lazy.test.ts +220 -0
- package/src/__tests__/memo.test.ts +16 -0
- package/src/__tests__/properties.test.ts +249 -1
- package/src/__tests__/slot.test.ts +141 -0
- package/src/__tests__/virtual.test.ts +241 -0
- package/src/component/lazy.ts +4 -2
- package/src/component/virtual.tsx +1 -1
- package/src/functions/watch.ts +11 -2
|
@@ -8,7 +8,7 @@ interface VirtualHost {
|
|
|
8
8
|
|
|
9
9
|
export function Virtual(itemHeight: number, buffer = 3) {
|
|
10
10
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
11
|
-
return function <T extends new (...args: any[]) => RootComponent
|
|
11
|
+
return function <T extends new (...args: any[]) => RootComponent<Record<string, any>>>(
|
|
12
12
|
constructor: T,
|
|
13
13
|
_context: ClassDecoratorContext,
|
|
14
14
|
): T {
|
package/src/functions/watch.ts
CHANGED
|
@@ -64,13 +64,16 @@ export function Watch<
|
|
|
64
64
|
const instance = this as T & Record<string, unknown>;
|
|
65
65
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
66
66
|
const originalOnMount = instance.onMount;
|
|
67
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
68
|
+
const originalOnUnmount = instance.onUnmount;
|
|
69
|
+
let stopEffect: (() => void) | undefined;
|
|
67
70
|
|
|
68
71
|
instance.onMount = function (this: T & Record<string, unknown>) {
|
|
69
72
|
originalOnMount?.call(this);
|
|
70
73
|
|
|
71
74
|
if (props.length === 1) {
|
|
72
75
|
let oldVal = readValue(this, props[0]);
|
|
73
|
-
effect(() => {
|
|
76
|
+
stopEffect = effect(() => {
|
|
74
77
|
const newVal = readValue(this, props[0]);
|
|
75
78
|
if (!Object.is(newVal, oldVal)) {
|
|
76
79
|
value.call(this as T, newVal, oldVal);
|
|
@@ -81,7 +84,7 @@ export function Watch<
|
|
|
81
84
|
const read = () =>
|
|
82
85
|
Object.fromEntries(props.map((p) => [p, readValue(this, p)]));
|
|
83
86
|
let oldVals = read();
|
|
84
|
-
effect(() => {
|
|
87
|
+
stopEffect = effect(() => {
|
|
85
88
|
const newVals = read();
|
|
86
89
|
if (props.some((p) => !Object.is(newVals[p], oldVals[p]))) {
|
|
87
90
|
value.call(this as T, newVals, oldVals);
|
|
@@ -90,6 +93,12 @@ export function Watch<
|
|
|
90
93
|
});
|
|
91
94
|
}
|
|
92
95
|
};
|
|
96
|
+
|
|
97
|
+
instance.onUnmount = function (this: T) {
|
|
98
|
+
originalOnUnmount?.call(this);
|
|
99
|
+
stopEffect?.();
|
|
100
|
+
stopEffect = undefined;
|
|
101
|
+
};
|
|
93
102
|
});
|
|
94
103
|
};
|
|
95
104
|
}
|