@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.
Files changed (48) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/__tests__/component.test.d.ts +2 -0
  3. package/dist/__tests__/component.test.d.ts.map +1 -0
  4. package/dist/__tests__/component.test.js +137 -0
  5. package/dist/__tests__/component.test.js.map +1 -0
  6. package/dist/__tests__/events.test.d.ts +2 -0
  7. package/dist/__tests__/events.test.d.ts.map +1 -0
  8. package/dist/__tests__/events.test.js +190 -0
  9. package/dist/__tests__/events.test.js.map +1 -0
  10. package/dist/__tests__/functions.test.js +157 -0
  11. package/dist/__tests__/functions.test.js.map +1 -1
  12. package/dist/__tests__/lazy.test.d.ts +2 -0
  13. package/dist/__tests__/lazy.test.d.ts.map +1 -0
  14. package/dist/__tests__/lazy.test.js +165 -0
  15. package/dist/__tests__/lazy.test.js.map +1 -0
  16. package/dist/__tests__/memo.test.js +13 -0
  17. package/dist/__tests__/memo.test.js.map +1 -1
  18. package/dist/__tests__/properties.test.js +191 -1
  19. package/dist/__tests__/properties.test.js.map +1 -1
  20. package/dist/__tests__/slot.test.d.ts +2 -0
  21. package/dist/__tests__/slot.test.d.ts.map +1 -0
  22. package/dist/__tests__/slot.test.js +115 -0
  23. package/dist/__tests__/slot.test.js.map +1 -0
  24. package/dist/__tests__/virtual.test.d.ts +2 -0
  25. package/dist/__tests__/virtual.test.d.ts.map +1 -0
  26. package/dist/__tests__/virtual.test.js +201 -0
  27. package/dist/__tests__/virtual.test.js.map +1 -0
  28. package/dist/component/lazy.d.ts +1 -1
  29. package/dist/component/lazy.d.ts.map +1 -1
  30. package/dist/component/lazy.js +4 -1
  31. package/dist/component/lazy.js.map +1 -1
  32. package/dist/component/virtual.d.ts +1 -1
  33. package/dist/component/virtual.d.ts.map +1 -1
  34. package/dist/functions/watch.d.ts.map +1 -1
  35. package/dist/functions/watch.js +10 -2
  36. package/dist/functions/watch.js.map +1 -1
  37. package/package.json +2 -2
  38. package/src/__tests__/component.test.ts +156 -0
  39. package/src/__tests__/events.test.ts +236 -0
  40. package/src/__tests__/functions.test.ts +207 -0
  41. package/src/__tests__/lazy.test.ts +220 -0
  42. package/src/__tests__/memo.test.ts +16 -0
  43. package/src/__tests__/properties.test.ts +249 -1
  44. package/src/__tests__/slot.test.ts +141 -0
  45. package/src/__tests__/virtual.test.ts +241 -0
  46. package/src/component/lazy.ts +4 -2
  47. package/src/component/virtual.tsx +1 -1
  48. 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 {
@@ -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
  }