@esportsplus/reactivity 0.40.0 → 0.42.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 (61) hide show
  1. package/README.md +16 -10
  2. package/bench/compiler.bench.ts +122 -0
  3. package/bench/kairo.bench.ts +1 -1
  4. package/bench/lib/reactive-adapter.ts +1 -1
  5. package/bench/ownership.bench.ts +9 -5
  6. package/bench/reactive/array.bench.ts +7 -2
  7. package/bench/reactive/reactive-object.bench.ts +3 -2
  8. package/bench/system.bench.ts +9 -5
  9. package/build/compiler/array.js +28 -25
  10. package/build/compiler/bindings.d.ts +3 -1
  11. package/build/compiler/bindings.js +36 -18
  12. package/build/compiler/index.d.ts +3 -2
  13. package/build/compiler/index.js +21 -13
  14. package/build/compiler/object.js +30 -21
  15. package/build/compiler/plugins/vite.d.ts +29 -6
  16. package/build/compiler/primitives.js +9 -9
  17. package/build/constants.d.ts +3 -1
  18. package/build/constants.js +3 -1
  19. package/build/reactive/array.js +89 -17
  20. package/build/reactive/index.d.ts +1 -1
  21. package/build/reactive/object.d.ts +3 -3
  22. package/build/reactive/object.js +1 -1
  23. package/build/system.d.ts +4 -3
  24. package/build/system.js +48 -16
  25. package/oxlintrc.json +3 -0
  26. package/package.json +15 -7
  27. package/pnpm-workspace.yaml +4 -7
  28. package/src/compiler/array.ts +30 -27
  29. package/src/compiler/bindings.ts +52 -23
  30. package/src/compiler/index.ts +37 -20
  31. package/src/compiler/object.ts +43 -30
  32. package/src/compiler/primitives.ts +13 -10
  33. package/src/constants.ts +6 -1
  34. package/src/reactive/array.ts +133 -24
  35. package/src/reactive/index.ts +3 -3
  36. package/src/reactive/object.ts +4 -4
  37. package/src/system.ts +68 -23
  38. package/test/async-hardening.test.ts +2 -2
  39. package/test/async-iterable.test.ts +3 -3
  40. package/test/compiler/__snapshots__/output.test.ts.snap +157 -0
  41. package/test/compiler/compiler.test.ts +51 -9
  42. package/test/compiler/composition.test.ts +110 -0
  43. package/test/compiler/coverage.test.ts +22 -22
  44. package/test/compiler/origins.test.ts +156 -0
  45. package/test/compiler/output.test.ts +116 -0
  46. package/test/deep-graphs.test.ts +6 -6
  47. package/test/effects.test.ts +5 -5
  48. package/test/errors.test.ts +4 -4
  49. package/test/invalidate.test.ts +2 -2
  50. package/test/ownership.test.ts +30 -30
  51. package/test/pause.test.ts +267 -0
  52. package/test/reactive/array.test.ts +13 -12
  53. package/test/reactive/reactive.test.ts +6 -6
  54. package/test/signal-selector.test.ts +4 -4
  55. package/test/system.test.ts +13 -13
  56. package/test/untrack.test.ts +10 -10
  57. package/tsconfig.build.json +3 -0
  58. package/tsconfig.json +2 -2
  59. package/vitest.config.ts +2 -2
  60. package/bench/tsconfig.json +0 -16
  61. package/test/tsconfig.json +0 -16
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, it } from 'vitest';
2
- import { computed, effect, read, signal, write } from '~/system';
2
+ import { computed, dispose, effect, read, signal, write } from '~/system';
3
3
  import { tick } from './lib/wait-for';
4
4
 
5
5
 
@@ -146,7 +146,7 @@ describe('effect error contract', () => {
146
146
  expect(captured.length).toBe(1);
147
147
  expect((captured[0] as Error).message).toBe('effect boom');
148
148
 
149
- stop();
149
+ dispose(stop);
150
150
  });
151
151
 
152
152
  it('effect rethrows on every failure, not just the first', async () => {
@@ -171,7 +171,7 @@ describe('effect error contract', () => {
171
171
  expect((captured[0] as Error).message).toBe('boom 1');
172
172
  expect((captured[1] as Error).message).toBe('boom 3');
173
173
 
174
- stop();
174
+ dispose(stop);
175
175
  });
176
176
 
177
177
  it('effect catching its own error internally rethrows nothing', async () => {
@@ -196,6 +196,6 @@ describe('effect error contract', () => {
196
196
  expect(errors.length).toBe(1);
197
197
  expect((errors[0] as Error).message).toBe('handled');
198
198
 
199
- stop();
199
+ dispose(stop);
200
200
  });
201
201
  });
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, it } from 'vitest';
2
- import { computed, effect, flush, peek, read, signal, write } from '~/system';
2
+ import { computed, dispose, effect, flush, peek, read, signal, write } from '~/system';
3
3
  import { waitFor } from './lib/wait-for';
4
4
 
5
5
 
@@ -85,7 +85,7 @@ describe('invalidate()', () => {
85
85
  expect(fetches).toBe(2);
86
86
  expect(read(node)).toBe(2);
87
87
 
88
- stop();
88
+ dispose(stop);
89
89
  });
90
90
 
91
91
  it('forces a side-effecting computed (the public effect encoding) to re-run without propagating', () => {
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, it } from 'vitest';
2
- import { computed, dispose, effect, flush, hasOwner, onCleanup, owner as current, read, root, signal, untrack, write } from '~/system';
2
+ import { computed, owner as current, dispose, effect, flush, onCleanup, read, root, signal, untrack, write } from '~/system';
3
3
  import type { Computed } from '~/system';
4
4
  import { captureUncaught } from './lib/uncaught';
5
5
 
@@ -74,7 +74,7 @@ describe('ownership unlink', () => {
74
74
 
75
75
  it('child effect disposed early unlinks from its owner', () => {
76
76
  let runs = 0,
77
- stops: VoidFunction[] = [],
77
+ stops: Computed<unknown>[] = [],
78
78
  parent = owner(() => {
79
79
  for (let i = 0; i < 3; i++) {
80
80
  stops.push(effect(() => {
@@ -85,12 +85,12 @@ describe('ownership unlink', () => {
85
85
 
86
86
  expect(registrations(parent)).toBe(3);
87
87
 
88
- stops[0]();
88
+ dispose(stops[0]);
89
89
  expect(registrations(parent)).toBe(2);
90
90
  expect(parent.owned!.owner).toBe(parent);
91
91
 
92
- stops[2]();
93
- stops[1]();
92
+ dispose(stops[2]);
93
+ dispose(stops[1]);
94
94
  expect(registrations(parent)).toBe(0);
95
95
 
96
96
  dispose(parent);
@@ -155,9 +155,9 @@ describe('ownership churn', () => {
155
155
  it('10k child effects created + disposed leave no registrations behind', () => {
156
156
  let parent = owner(() => {
157
157
  for (let i = 0; i < 10000; i++) {
158
- effect(() => {
158
+ dispose(effect(() => {
159
159
  onCleanup(() => {});
160
- })();
160
+ }));
161
161
  }
162
162
  });
163
163
 
@@ -266,7 +266,7 @@ describe('ownership ordering', () => {
266
266
  it('an early-disposed child leaves the remaining order intact', () => {
267
267
  let log: string[] = [],
268
268
  s = signal(0),
269
- stop: VoidFunction | null = null;
269
+ stop: Computed<unknown> | null = null;
270
270
 
271
271
  effect(() => {
272
272
  if (read(s) === 0) {
@@ -285,7 +285,7 @@ describe('ownership ordering', () => {
285
285
  });
286
286
 
287
287
  flush();
288
- stop!();
288
+ dispose(stop!);
289
289
  expect(log).toEqual(['y']);
290
290
 
291
291
  write(s, 1);
@@ -322,7 +322,7 @@ describe('ownership ordering', () => {
322
322
  describe('ownership double dispose', () => {
323
323
  it('disposing a child twice is a no-op and leaves siblings registered', () => {
324
324
  let runs = 0,
325
- stop: VoidFunction | null = null,
325
+ stop: Computed<unknown> | null = null,
326
326
  parent = owner(() => {
327
327
  effect(() => {});
328
328
  stop = effect(() => {
@@ -331,8 +331,8 @@ describe('ownership double dispose', () => {
331
331
  effect(() => {});
332
332
  });
333
333
 
334
- stop!();
335
- stop!();
334
+ dispose(stop!);
335
+ dispose(stop!);
336
336
 
337
337
  expect(runs).toBe(1);
338
338
  expect(registrations(parent)).toBe(2);
@@ -364,7 +364,7 @@ describe('ownership double dispose', () => {
364
364
  describe('ownership dispose mid-drain', () => {
365
365
  it('a child cleanup disposing its parent and a sibling runs every cleanup once', () => {
366
366
  let counts = { a: 0, b: 0, c: 0, parent: 0 },
367
- stopB: VoidFunction | null = null,
367
+ stopB: Computed<unknown> | null = null,
368
368
  stopParent: VoidFunction | null = null;
369
369
 
370
370
  root((d) => {
@@ -373,7 +373,7 @@ describe('ownership dispose mid-drain', () => {
373
373
  effect(() => {
374
374
  onCleanup(() => {
375
375
  counts.a++;
376
- stopB!();
376
+ dispose(stopB!);
377
377
  stopParent!();
378
378
  });
379
379
  });
@@ -393,7 +393,7 @@ describe('ownership dispose mid-drain', () => {
393
393
  it('a child disposing its parent from its own cleanup unlinks first', () => {
394
394
  let counts = { child: 0, parent: 0, sibling: 0 },
395
395
  parent: Computed<unknown> | null = null,
396
- stop: VoidFunction | null = null;
396
+ stop: Computed<unknown> | null = null;
397
397
 
398
398
  parent = owner(() => {
399
399
  onCleanup(() => { counts.parent++; });
@@ -408,7 +408,7 @@ describe('ownership dispose mid-drain', () => {
408
408
  });
409
409
  });
410
410
 
411
- stop!();
411
+ dispose(stop!);
412
412
 
413
413
  expect(counts).toEqual({ child: 1, parent: 1, sibling: 1 });
414
414
  expect(registrations(parent)).toBe(0);
@@ -417,14 +417,14 @@ describe('ownership dispose mid-drain', () => {
417
417
  it('a re-run where one child disposes a later sibling skips it', () => {
418
418
  let log: string[] = [],
419
419
  s = signal(0),
420
- stopY: VoidFunction | null = null;
420
+ stopY: Computed<unknown> | null = null;
421
421
 
422
422
  effect(() => {
423
423
  if (read(s) === 0) {
424
424
  effect(() => {
425
425
  onCleanup(() => {
426
426
  log.push('x');
427
- stopY!();
427
+ dispose(stopY!);
428
428
  });
429
429
  });
430
430
  stopY = effect(() => {
@@ -550,20 +550,20 @@ describe('ownership throwing cleanup', () => {
550
550
  });
551
551
 
552
552
 
553
- describe('hasOwner', () => {
553
+ describe('owner() as an ownership probe', () => {
554
554
  it('is true inside a tracking root or a run (also untracked), false outside and in a detached root', () => {
555
555
  let seen: boolean[] = [],
556
556
  stop = effect(() => {
557
- seen.push(hasOwner());
558
- seen.push(untrack(() => hasOwner()));
559
- seen.push(untrack(() => root(() => hasOwner())));
557
+ seen.push(current() !== null);
558
+ seen.push(untrack(() => current() !== null));
559
+ seen.push(untrack(() => root(() => current() !== null)));
560
560
  });
561
561
 
562
- seen.push(hasOwner());
563
- seen.push(untrack(() => hasOwner()));
564
- root((d) => { seen.push(hasOwner()); d(); });
565
- root(() => { seen.push(hasOwner()); });
566
- stop();
562
+ seen.push(current() !== null);
563
+ seen.push(untrack(() => current() !== null));
564
+ root((d) => { seen.push(current() !== null); d(); });
565
+ root(() => { seen.push(current() !== null); });
566
+ dispose(stop);
567
567
 
568
568
  expect(seen).toEqual([true, true, false, false, false, true, false]);
569
569
  });
@@ -573,12 +573,12 @@ describe('hasOwner', () => {
573
573
  seen: boolean[] = [],
574
574
  stop = effect(() => {
575
575
  read(s);
576
- seen.push(untrack(() => hasOwner()));
576
+ seen.push(untrack(() => current() !== null));
577
577
  });
578
578
 
579
579
  write(s, 1);
580
580
  await Promise.resolve();
581
- stop();
581
+ dispose(stop);
582
582
 
583
583
  expect(seen).toEqual([true, true]);
584
584
  });
@@ -635,7 +635,7 @@ describe('root with an owner', () => {
635
635
  effect(() => { read(s); });
636
636
  }, node);
637
637
 
638
- expect(hasOwner()).toBe(false);
638
+ expect(current() !== null).toBe(false);
639
639
  expect(registrations(node!)).toBe(2);
640
640
 
641
641
  write(s, 1);
@@ -0,0 +1,267 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { computed, dispose, effect, flush, owner, pause, read, resume, root, signal, write } from '~/system';
3
+ import type { Computed } from '~/system';
4
+
5
+
6
+ function counter(s: ReturnType<typeof signal<number>>) {
7
+ let state = { node: null as unknown as Computed<unknown>, runs: 0 };
8
+
9
+ state.node = effect(() => {
10
+ read(s);
11
+ state.runs++;
12
+ });
13
+
14
+ return state;
15
+ }
16
+
17
+
18
+ describe('pause / resume', () => {
19
+ it('a paused effect does not run on write', () => {
20
+ let s = signal(0),
21
+ c = counter(s);
22
+
23
+ pause(c.node);
24
+ write(s, 1);
25
+ flush();
26
+ write(s, 2);
27
+ flush();
28
+
29
+ expect(c.runs).toBe(1);
30
+ dispose(c.node);
31
+ });
32
+
33
+ it('resuming after writes runs it exactly once', () => {
34
+ let s = signal(0),
35
+ c = counter(s);
36
+
37
+ pause(c.node);
38
+ write(s, 1);
39
+ flush();
40
+ write(s, 2);
41
+ flush();
42
+ resume(c.node);
43
+ flush();
44
+
45
+ expect(c.runs).toBe(2);
46
+
47
+ flush();
48
+ expect(c.runs).toBe(2);
49
+
50
+ write(s, 3);
51
+ flush();
52
+ expect(c.runs).toBe(3);
53
+ dispose(c.node);
54
+ });
55
+
56
+ it('resume schedules the replay without a flush', async () => {
57
+ let s = signal(0),
58
+ c = counter(s);
59
+
60
+ pause(c.node);
61
+ write(s, 1);
62
+ await Promise.resolve();
63
+ resume(c.node);
64
+
65
+ expect(c.runs).toBe(1);
66
+
67
+ await Promise.resolve();
68
+ expect(c.runs).toBe(2);
69
+ dispose(c.node);
70
+ });
71
+
72
+ it('resuming without a write runs nothing', () => {
73
+ let other = signal(0),
74
+ s = signal(0),
75
+ c = counter(s),
76
+ o = counter(other);
77
+
78
+ pause(c.node);
79
+ flush();
80
+ resume(c.node);
81
+ flush();
82
+ write(other, 1);
83
+ flush();
84
+
85
+ expect(c.runs).toBe(1);
86
+ expect(o.runs).toBe(2);
87
+ dispose(c.node);
88
+ dispose(o.node);
89
+ });
90
+
91
+ it('pause and resume are idempotent', () => {
92
+ let s = signal(0),
93
+ c = counter(s);
94
+
95
+ pause(c.node);
96
+ pause(c.node);
97
+ write(s, 1);
98
+ flush();
99
+ resume(c.node);
100
+ resume(c.node);
101
+ flush();
102
+
103
+ expect(c.runs).toBe(2);
104
+ dispose(c.node);
105
+ });
106
+
107
+ it('a paused effect that is disposed never runs again', () => {
108
+ let other = signal(0),
109
+ s = signal(0),
110
+ c = counter(s),
111
+ o = counter(other);
112
+
113
+ pause(c.node);
114
+ write(s, 1);
115
+ flush();
116
+ dispose(c.node);
117
+ resume(c.node);
118
+ flush();
119
+ write(s, 2);
120
+ write(other, 1);
121
+ flush();
122
+
123
+ expect(c.runs).toBe(1);
124
+ expect(o.runs).toBe(2);
125
+ dispose(o.node);
126
+ });
127
+
128
+ it('pause and resume on a disposed effect are no-ops', () => {
129
+ let s = signal(0),
130
+ c = counter(s);
131
+
132
+ dispose(c.node);
133
+
134
+ expect(() => pause(c.node)).not.toThrow();
135
+ expect(() => resume(c.node)).not.toThrow();
136
+
137
+ write(s, 1);
138
+ flush();
139
+ expect(c.runs).toBe(1);
140
+ });
141
+
142
+ it('disposing the owner while a child is paused disposes the child for good', () => {
143
+ let child = null as unknown as Computed<unknown>,
144
+ childRuns = 0,
145
+ s = signal(0),
146
+ stop = root((d) => {
147
+ effect(() => {
148
+ child = effect(() => {
149
+ read(s);
150
+ childRuns++;
151
+ });
152
+ });
153
+
154
+ return d;
155
+ });
156
+
157
+ pause(child);
158
+ write(s, 1);
159
+ flush();
160
+ expect(childRuns).toBe(1);
161
+
162
+ stop();
163
+ resume(child);
164
+ flush();
165
+ write(s, 2);
166
+ flush();
167
+
168
+ expect(childRuns).toBe(1);
169
+ });
170
+
171
+ it('pausing from inside a re-run sticks', () => {
172
+ let runs = 0,
173
+ s = signal(0),
174
+ node = effect(() => {
175
+ read(s);
176
+ runs++;
177
+
178
+ if (runs === 2) {
179
+ pause(owner()!);
180
+ }
181
+ });
182
+
183
+ write(s, 1);
184
+ flush();
185
+ write(s, 2);
186
+ flush();
187
+
188
+ expect(runs).toBe(2);
189
+
190
+ resume(node);
191
+ flush();
192
+ expect(runs).toBe(3);
193
+
194
+ write(s, 3);
195
+ flush();
196
+ expect(runs).toBe(4);
197
+ dispose(node);
198
+ });
199
+
200
+ it('an effect that pauses itself before reading keeps its dependencies and replays on resume', () => {
201
+ let live = true,
202
+ runs = 0,
203
+ s = signal(0),
204
+ node = effect(() => {
205
+ runs++;
206
+
207
+ if (!live) {
208
+ pause(owner()!);
209
+ return;
210
+ }
211
+
212
+ read(s);
213
+ });
214
+
215
+ live = false;
216
+ write(s, 1);
217
+ flush();
218
+ expect(runs).toBe(2);
219
+
220
+ write(s, 2);
221
+ flush();
222
+ expect(runs).toBe(2);
223
+
224
+ live = true;
225
+ resume(node);
226
+ flush();
227
+ expect(runs).toBe(3);
228
+
229
+ write(s, 3);
230
+ flush();
231
+ expect(runs).toBe(4);
232
+ dispose(node);
233
+ });
234
+
235
+ it('an effect that pauses itself after reading everything does not replay unless dirtied', () => {
236
+ let runs = 0,
237
+ s = signal(0),
238
+ node = effect(() => {
239
+ read(s);
240
+ runs++;
241
+
242
+ if (runs === 2) {
243
+ pause(owner()!);
244
+ }
245
+ });
246
+
247
+ write(s, 1);
248
+ flush();
249
+ resume(node);
250
+ flush();
251
+
252
+ expect(runs).toBe(2);
253
+
254
+ write(s, 2);
255
+ flush();
256
+ expect(runs).toBe(3);
257
+ dispose(node);
258
+ });
259
+
260
+ it('rejects computeds', () => {
261
+ let c = computed(() => 1);
262
+
263
+ expect(() => pause(c)).toThrow('@esportsplus/reactivity: pause() expects an effect');
264
+ expect(() => resume(c)).toThrow('@esportsplus/reactivity: resume() expects an effect');
265
+ dispose(c);
266
+ });
267
+ });
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, it, vi } from 'vitest';
2
- import { effect, flush, owner, read, root, signal, write } from '~/system';
2
+ import { dispose, effect, flush, owner, read, root, signal, write } from '~/system';
3
3
  import { ReactiveArray } from '~/reactive/array';
4
4
  import { ReactiveObject } from '~/reactive/object';
5
5
  import reactive from '~/reactive/index';
@@ -54,7 +54,7 @@ describe('ReactiveArray', () => {
54
54
  });
55
55
 
56
56
  it('does not overflow the stack for a large array', () => {
57
- let arr = new ReactiveArray(new Array(500000).fill(0));
57
+ let arr = new ReactiveArray(Array.from({ length: 500000 }, () => 0));
58
58
 
59
59
  expect(arr.length).toBe(500000);
60
60
  expect(arr.$length).toBe(500000);
@@ -463,7 +463,7 @@ describe('ReactiveArray', () => {
463
463
  arr.on('splice', (e) => { events.push(e); });
464
464
  arr.splice(1, 1, 20, 30);
465
465
 
466
- expect(events).toEqual([{ start: 1, deleteCount: 1, items: [20, 30] }]);
466
+ expect(events).toEqual([{ deleteCount: 1, items: [20, 30], start: 1 }]);
467
467
  });
468
468
 
469
469
  it('no event when nothing changes', () => {
@@ -499,7 +499,7 @@ describe('ReactiveArray', () => {
499
499
 
500
500
  expect([...removed]).toEqual([4]);
501
501
  expect([...arr]).toEqual([1, 2, 3, 5]);
502
- expect(events).toEqual([{ start: 3, deleteCount: 1, items: [] }]);
502
+ expect(events).toEqual([{ deleteCount: 1, items: [], start: 3 }]);
503
503
  });
504
504
 
505
505
  it('splice dispatches the count actually removed, not the requested count', () => {
@@ -510,7 +510,7 @@ describe('ReactiveArray', () => {
510
510
  arr.splice(1, 100);
511
511
 
512
512
  expect([...arr]).toEqual([1]);
513
- expect(events).toEqual([{ start: 1, deleteCount: 2, items: [] }]);
513
+ expect(events).toEqual([{ deleteCount: 2, items: [], start: 1 }]);
514
514
  });
515
515
 
516
516
  it('splice clamps an out-of-range or fractional start the way Array.prototype.splice does', () => {
@@ -524,9 +524,9 @@ describe('ReactiveArray', () => {
524
524
 
525
525
  expect([...arr]).toEqual([0, 9, 1, 2, 3, 4]);
526
526
  expect(events).toEqual([
527
- { start: 3, deleteCount: 0, items: [4] },
528
- { start: 0, deleteCount: 0, items: [0] },
529
- { start: 1, deleteCount: 0, items: [9] }
527
+ { deleteCount: 0, items: [4], start: 3 },
528
+ { deleteCount: 0, items: [0], start: 0 },
529
+ { deleteCount: 0, items: [9], start: 1 }
530
530
  ]);
531
531
  });
532
532
  });
@@ -652,6 +652,7 @@ describe('ReactiveArray', () => {
652
652
  arr.sort((a, b) => a - b);
653
653
 
654
654
  expect([...arr]).toEqual([1, 2, 2]);
655
+ expect(order).toEqual([1, 0, 2]);
655
656
  });
656
657
 
657
658
  it('order maps duplicate values stably (first stays first)', () => {
@@ -1234,7 +1235,7 @@ describe('ReactiveArray batch', () => {
1234
1235
  b = signal(0),
1235
1236
  c = signal(0);
1236
1237
 
1237
- root(() => effect(() => read(a) + read(b) + read(c)))();
1238
+ dispose(root(() => effect(() => read(a) + read(b) + read(c))));
1238
1239
  };
1239
1240
 
1240
1241
  it('delivers every mutation of a task once, in order, in the pass that follows', async () => {
@@ -1331,7 +1332,7 @@ describe('ReactiveArray batch', () => {
1331
1332
 
1332
1333
  write(s, 5);
1333
1334
  flush();
1334
- stop();
1335
+ dispose(stop);
1335
1336
 
1336
1337
  expect(batches).toEqual([[{ items: [5], op: 'push' }]]);
1337
1338
  });
@@ -1353,7 +1354,7 @@ describe('ReactiveArray batch', () => {
1353
1354
  arr.on('batch', (ops) => batches.push(ops));
1354
1355
  arr.push(2);
1355
1356
  flush();
1356
- stop();
1357
+ dispose(stop);
1357
1358
 
1358
1359
  expect(captured.map((e) => (e as Error).message)).toEqual(['reactivity: batch']);
1359
1360
  expect(batches).toEqual([[{ items: [2], op: 'push' }]]);
@@ -1383,7 +1384,7 @@ describe('ReactiveArray batch', () => {
1383
1384
  arr.on('batch', (ops) => batches.push(ops));
1384
1385
  arr.push(3);
1385
1386
  flush();
1386
- stop();
1387
+ dispose(stop);
1387
1388
 
1388
1389
  expect(first).toEqual([[{ items: [1], op: 'push' }]]);
1389
1390
  expect(batches).toEqual([[{ items: [3], op: 'push' }]]);
@@ -1,7 +1,7 @@
1
1
  import { describe, expect, it, vi } from 'vitest';
2
- import { computed, effect, onCleanup, read, root, signal, write } from '~/system';
2
+ import { computed, dispose, effect, onCleanup, read, signal, write } from '~/system';
3
3
  import { SIGNAL } from '~/constants';
4
- import { ReactiveObject, isReactiveObject } from '~/reactive/object';
4
+ import { isReactiveObject, ReactiveObject } from '~/reactive/object';
5
5
  import reactive from '~/reactive/index';
6
6
  import { ReactiveArray } from '~/reactive/array';
7
7
  import { tick, waitFor } from '../lib/wait-for';
@@ -348,7 +348,7 @@ describe('isReactiveObject', () => {
348
348
  describe('reactive()', () => {
349
349
  describe('objects', () => {
350
350
  it('creates reactive object', () => {
351
- let obj = reactive({ name: 'John', age: 25 });
351
+ let obj = reactive({ age: 25, name: 'John' });
352
352
 
353
353
  expect((obj as any).name).toBe('John');
354
354
  expect((obj as any).age).toBe(25);
@@ -408,7 +408,7 @@ describe('reactive()', () => {
408
408
 
409
409
  expect(runs).toBe(1);
410
410
 
411
- stop();
411
+ dispose(stop);
412
412
 
413
413
  write(s, 2);
414
414
  await Promise.resolve();
@@ -423,7 +423,7 @@ describe('reactive()', () => {
423
423
  reactive([inner]);
424
424
  });
425
425
 
426
- stop();
426
+ dispose(stop);
427
427
 
428
428
  expect(spy).toHaveBeenCalledTimes(1);
429
429
  });
@@ -515,7 +515,7 @@ describe('integration', () => {
515
515
 
516
516
  it('large dependency chain', async () => {
517
517
  let s = signal(0),
518
- chain: ReturnType<typeof computed>[] = [computed(() => read(s))];
518
+ chain: ReturnType<typeof computed<number>>[] = [computed(() => read(s))];
519
519
 
520
520
  for (let i = 1; i < 50; i++) {
521
521
  let prev = chain[i - 1];
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, it } from 'vitest';
2
- import { computed, effect, onCleanup, read, signal, write } from '~/system';
2
+ import { computed, dispose, effect, onCleanup, read, signal, write } from '~/system';
3
3
 
4
4
  // signal.selector(node, key) rides a Map for entry lookup — SameValueZero semantics: NaN keys match
5
5
  // themselves and ±0 collapse, slightly wider than the settled === for those two cases. Object keys
@@ -81,10 +81,10 @@ describe('signal.selector per-key selector', () => {
81
81
 
82
82
  expect(s.keys!.size).toBe(2);
83
83
 
84
- stop1();
84
+ dispose(stop1);
85
85
  expect(s.keys!.size).toBe(1);
86
86
 
87
- stop2();
87
+ dispose(stop2);
88
88
  expect(s.keys).toBe(null);
89
89
  });
90
90
 
@@ -107,7 +107,7 @@ describe('signal.selector per-key selector', () => {
107
107
  expect(cleaned).toBe(0);
108
108
 
109
109
  // Disposing the effect unlinks c's last subscriber → c still auto-disposes and its cleanup fires.
110
- stop();
110
+ dispose(stop);
111
111
  expect(cleaned).toBe(1);
112
112
  });
113
113