@esportsplus/reactivity 0.33.0 → 0.36.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.
Files changed (45) hide show
  1. package/README.md +9 -7
  2. package/bench/reactive/array.bench.ts +17 -17
  3. package/build/compiler/array.d.ts +2 -2
  4. package/build/compiler/array.js +12 -54
  5. package/build/compiler/constants.d.ts +4 -4
  6. package/build/compiler/constants.js +20 -4
  7. package/build/compiler/index.js +25 -38
  8. package/build/compiler/object.d.ts +2 -2
  9. package/build/compiler/object.js +10 -21
  10. package/build/compiler/plugins/vite.d.ts +4 -2
  11. package/build/compiler/primitives.d.ts +6 -2
  12. package/build/compiler/primitives.js +35 -42
  13. package/build/compiler/types.d.ts +3 -1
  14. package/build/constants.d.ts +2 -2
  15. package/build/constants.js +2 -2
  16. package/build/reactive/array.d.ts +1 -1
  17. package/build/reactive/array.js +26 -15
  18. package/build/reactive/index.js +5 -14
  19. package/build/reactive/object.js +1 -1
  20. package/build/system.d.ts +10 -13
  21. package/build/system.js +105 -83
  22. package/build/types.d.ts +2 -7
  23. package/package.json +5 -5
  24. package/pnpm-workspace.yaml +3 -0
  25. package/src/compiler/array.ts +14 -64
  26. package/src/compiler/constants.ts +21 -5
  27. package/src/compiler/index.ts +39 -70
  28. package/src/compiler/object.ts +12 -29
  29. package/src/compiler/primitives.ts +55 -53
  30. package/src/compiler/types.ts +4 -1
  31. package/src/constants.ts +4 -4
  32. package/src/reactive/array.ts +33 -17
  33. package/src/reactive/index.ts +5 -17
  34. package/src/reactive/object.ts +1 -1
  35. package/src/system.ts +138 -101
  36. package/src/types.ts +2 -9
  37. package/test/async-computed.test.ts +2 -2
  38. package/test/compiler/compiler.test.ts +40 -23
  39. package/test/effects.test.ts +37 -1
  40. package/test/lib/uncaught.ts +26 -0
  41. package/test/reactive/array.test.ts +169 -99
  42. package/test/reactive/nested.test.ts +14 -14
  43. package/test/reactive/objects.test.ts +1 -1
  44. package/test/reactive/reactive.test.ts +49 -0
  45. package/test/system.test.ts +130 -22
@@ -182,7 +182,7 @@ describe('effect patterns', () => {
182
182
 
183
183
  describe('effect with reactive array', () => {
184
184
  it('effect tracks array length changes', async () => {
185
- let arr = new ReactiveArray(1, 2, 3),
185
+ let arr = new ReactiveArray([1, 2, 3]),
186
186
  runs = 0,
187
187
  lengths: number[] = [];
188
188
 
@@ -331,3 +331,39 @@ describe('effect apply phase', () => {
331
331
  expect(applied).toEqual([101, 202]);
332
332
  });
333
333
  });
334
+
335
+
336
+ describe('scheduling from a top-level creation run', () => {
337
+ it('a write issued by a top-level effect creation propagates', async () => {
338
+ let runs = 0,
339
+ s = signal(0);
340
+
341
+ effect(() => {
342
+ read(s);
343
+ runs++;
344
+ });
345
+
346
+ effect(() => {
347
+ write(s, 5);
348
+ });
349
+
350
+ await waitFor(() => runs === 2, 'the reader re-runs');
351
+
352
+ expect(read(s)).toBe(5);
353
+ });
354
+
355
+ it('a deferred inner effect created by a top-level effect creation runs', async () => {
356
+ let inner = 0,
357
+ s = signal(0);
358
+
359
+ effect(() => {
360
+ read(s);
361
+
362
+ effect(() => {
363
+ inner++;
364
+ });
365
+ });
366
+
367
+ await waitFor(() => inner === 1, 'the inner effect runs');
368
+ });
369
+ });
@@ -0,0 +1,26 @@
1
+ const captureUncaught = async (fn: () => void): Promise<unknown[]> => {
2
+ let captured: unknown[] = [],
3
+ previous = process.listeners('uncaughtException');
4
+
5
+ process.removeAllListeners('uncaughtException');
6
+ process.on('uncaughtException', (e) => { captured.push(e); });
7
+
8
+ try {
9
+ fn();
10
+
11
+ await Promise.resolve();
12
+ await Promise.resolve();
13
+ }
14
+ finally {
15
+ process.removeAllListeners('uncaughtException');
16
+
17
+ for (let i = 0, n = previous.length; i < n; i++) {
18
+ process.on('uncaughtException', previous[i]);
19
+ }
20
+ }
21
+
22
+ return captured;
23
+ };
24
+
25
+
26
+ export { captureUncaught };