@esportsplus/reactivity 0.41.0 → 0.43.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/README.md +7 -5
- package/bench/compiler.bench.ts +24 -16
- package/bench/lib/reactive-adapter.ts +1 -1
- package/bench/ownership.bench.ts +9 -5
- package/bench/reactive/array.bench.ts +6 -2
- package/bench/system.bench.ts +9 -5
- package/build/compiler/array.d.ts +1 -1
- package/build/compiler/array.js +2 -2
- package/build/compiler/bindings.d.ts +9 -9
- package/build/compiler/bindings.js +59 -62
- package/build/compiler/index.d.ts +2 -2
- package/build/compiler/index.js +19 -13
- package/build/compiler/object.d.ts +1 -1
- package/build/compiler/object.js +19 -10
- package/build/compiler/plugins/vite.d.ts +18 -4
- package/build/compiler/primitives.d.ts +1 -1
- package/build/compiler/primitives.js +38 -20
- package/build/constants.d.ts +3 -1
- package/build/constants.js +3 -1
- package/build/reactive/array.js +89 -17
- package/build/system.d.ts +4 -3
- package/build/system.js +48 -16
- package/package.json +2 -2
- package/src/compiler/array.ts +2 -2
- package/src/compiler/bindings.ts +82 -86
- package/src/compiler/index.ts +25 -14
- package/src/compiler/object.ts +31 -17
- package/src/compiler/primitives.ts +61 -25
- package/src/constants.ts +6 -1
- package/src/reactive/array.ts +130 -23
- package/src/system.ts +66 -23
- package/test/async-hardening.test.ts +2 -2
- package/test/async-iterable.test.ts +3 -3
- package/test/compiler/compiler.test.ts +169 -156
- package/test/compiler/composition.test.ts +31 -27
- package/test/compiler/coverage.test.ts +12 -12
- package/test/compiler/origins.test.ts +18 -18
- package/test/compiler/output.test.ts +4 -4
- package/test/deep-graphs.test.ts +6 -6
- package/test/effects.test.ts +5 -5
- package/test/errors.test.ts +4 -4
- package/test/invalidate.test.ts +2 -2
- package/test/ownership.test.ts +30 -30
- package/test/pause.test.ts +267 -0
- package/test/reactive/array.test.ts +5 -5
- package/test/reactive/reactive.test.ts +3 -3
- package/test/signal-selector.test.ts +4 -4
- package/test/system.test.ts +10 -9
- package/test/untrack.test.ts +9 -9
|
@@ -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';
|
|
@@ -1235,7 +1235,7 @@ describe('ReactiveArray batch', () => {
|
|
|
1235
1235
|
b = signal(0),
|
|
1236
1236
|
c = signal(0);
|
|
1237
1237
|
|
|
1238
|
-
root(() => effect(() => read(a) + read(b) + read(c)))
|
|
1238
|
+
dispose(root(() => effect(() => read(a) + read(b) + read(c))));
|
|
1239
1239
|
};
|
|
1240
1240
|
|
|
1241
1241
|
it('delivers every mutation of a task once, in order, in the pass that follows', async () => {
|
|
@@ -1332,7 +1332,7 @@ describe('ReactiveArray batch', () => {
|
|
|
1332
1332
|
|
|
1333
1333
|
write(s, 5);
|
|
1334
1334
|
flush();
|
|
1335
|
-
stop
|
|
1335
|
+
dispose(stop);
|
|
1336
1336
|
|
|
1337
1337
|
expect(batches).toEqual([[{ items: [5], op: 'push' }]]);
|
|
1338
1338
|
});
|
|
@@ -1354,7 +1354,7 @@ describe('ReactiveArray batch', () => {
|
|
|
1354
1354
|
arr.on('batch', (ops) => batches.push(ops));
|
|
1355
1355
|
arr.push(2);
|
|
1356
1356
|
flush();
|
|
1357
|
-
stop
|
|
1357
|
+
dispose(stop);
|
|
1358
1358
|
|
|
1359
1359
|
expect(captured.map((e) => (e as Error).message)).toEqual(['reactivity: batch']);
|
|
1360
1360
|
expect(batches).toEqual([[{ items: [2], op: 'push' }]]);
|
|
@@ -1384,7 +1384,7 @@ describe('ReactiveArray batch', () => {
|
|
|
1384
1384
|
arr.on('batch', (ops) => batches.push(ops));
|
|
1385
1385
|
arr.push(3);
|
|
1386
1386
|
flush();
|
|
1387
|
-
stop
|
|
1387
|
+
dispose(stop);
|
|
1388
1388
|
|
|
1389
1389
|
expect(first).toEqual([[{ items: [1], op: 'push' }]]);
|
|
1390
1390
|
expect(batches).toEqual([[{ items: [3], op: 'push' }]]);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it, vi } 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
|
import { SIGNAL } from '~/constants';
|
|
4
4
|
import { isReactiveObject, ReactiveObject } from '~/reactive/object';
|
|
5
5
|
import reactive from '~/reactive/index';
|
|
@@ -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
|
});
|
|
@@ -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
|
|
package/test/system.test.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { describe, expect, it, vi } from 'vitest';
|
|
2
2
|
import { computed, dispose, effect, flush, isComputed, isSignal, onCleanup, peek, read, root, signal, write } from '~/system';
|
|
3
|
+
import type { Computed } from '~/system';
|
|
3
4
|
import { waitFor } from './lib/wait-for';
|
|
4
5
|
|
|
5
6
|
|
|
@@ -310,7 +311,7 @@ describe('effect', () => {
|
|
|
310
311
|
|
|
311
312
|
expect(calls).toBe(1);
|
|
312
313
|
|
|
313
|
-
stop
|
|
314
|
+
dispose(stop);
|
|
314
315
|
|
|
315
316
|
write(s, 1);
|
|
316
317
|
await Promise.resolve();
|
|
@@ -395,7 +396,7 @@ describe('onCleanup', () => {
|
|
|
395
396
|
|
|
396
397
|
expect(cleaned).toBe(false);
|
|
397
398
|
|
|
398
|
-
stop
|
|
399
|
+
dispose(stop);
|
|
399
400
|
|
|
400
401
|
expect(cleaned).toBe(true);
|
|
401
402
|
});
|
|
@@ -1061,7 +1062,7 @@ describe('edge cases', () => {
|
|
|
1061
1062
|
|
|
1062
1063
|
expect(innerDisposed).toBe(false);
|
|
1063
1064
|
|
|
1064
|
-
stop
|
|
1065
|
+
dispose(stop);
|
|
1065
1066
|
|
|
1066
1067
|
expect(innerDisposed).toBe(true);
|
|
1067
1068
|
});
|
|
@@ -1248,14 +1249,14 @@ describe('edge cases', () => {
|
|
|
1248
1249
|
|
|
1249
1250
|
it('system remains functional under high effect churn', async () => {
|
|
1250
1251
|
let s = signal(0),
|
|
1251
|
-
stops:
|
|
1252
|
+
stops: Computed<unknown>[] = [];
|
|
1252
1253
|
|
|
1253
1254
|
for (let i = 0; i < 200; i++) {
|
|
1254
1255
|
stops.push(effect(() => { read(s); }));
|
|
1255
1256
|
}
|
|
1256
1257
|
|
|
1257
1258
|
for (let i = 0, n = stops.length; i < n; i++) {
|
|
1258
|
-
stops[i]
|
|
1259
|
+
dispose(stops[i]);
|
|
1259
1260
|
}
|
|
1260
1261
|
|
|
1261
1262
|
stops.length = 0;
|
|
@@ -1276,7 +1277,7 @@ describe('edge cases', () => {
|
|
|
1276
1277
|
}
|
|
1277
1278
|
|
|
1278
1279
|
for (let i = 0, n = stops.length; i < n; i++) {
|
|
1279
|
-
stops[i]
|
|
1280
|
+
dispose(stops[i]);
|
|
1280
1281
|
}
|
|
1281
1282
|
|
|
1282
1283
|
write(s, 99);
|
|
@@ -1416,7 +1417,7 @@ describe('edge cases', () => {
|
|
|
1416
1417
|
|
|
1417
1418
|
it('link pool handles >1000 dependencies with disposal and reuse', async () => {
|
|
1418
1419
|
let signals: ReturnType<typeof signal<number>>[] = [],
|
|
1419
|
-
stops:
|
|
1420
|
+
stops: Computed<unknown>[] = [];
|
|
1420
1421
|
|
|
1421
1422
|
for (let i = 0; i < 1100; i++) {
|
|
1422
1423
|
signals.push(signal(i));
|
|
@@ -1430,7 +1431,7 @@ describe('edge cases', () => {
|
|
|
1430
1431
|
}));
|
|
1431
1432
|
|
|
1432
1433
|
// Dispose to return links to pool
|
|
1433
|
-
stops[0]
|
|
1434
|
+
dispose(stops[0]);
|
|
1434
1435
|
stops.length = 0;
|
|
1435
1436
|
|
|
1436
1437
|
// Create new effects reusing pooled links
|
|
@@ -1456,7 +1457,7 @@ describe('edge cases', () => {
|
|
|
1456
1457
|
expect(sum).toBe(1325);
|
|
1457
1458
|
|
|
1458
1459
|
for (let i = 0, n = stops.length; i < n; i++) {
|
|
1459
|
-
stops[i]
|
|
1460
|
+
dispose(stops[i]);
|
|
1460
1461
|
}
|
|
1461
1462
|
});
|
|
1462
1463
|
});
|
package/test/untrack.test.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { computed,
|
|
2
|
+
import { computed, dispose, effect, onCleanup, owner, peek, read, root, signal, untrack, write } from '~/system';
|
|
3
3
|
import type { Computed } from '~/system';
|
|
4
4
|
|
|
5
5
|
|
|
@@ -99,7 +99,7 @@ describe('untrack ownership', () => {
|
|
|
99
99
|
// Only generation 1's inner effect is alive; generation 0's was disposed by the re-run
|
|
100
100
|
expect(innerRuns).toEqual(['0:0', '1:0', '1:1']);
|
|
101
101
|
|
|
102
|
-
stop
|
|
102
|
+
dispose(stop);
|
|
103
103
|
write(inner, 2);
|
|
104
104
|
await Promise.resolve();
|
|
105
105
|
|
|
@@ -120,7 +120,7 @@ describe('untrack ownership', () => {
|
|
|
120
120
|
|
|
121
121
|
expect(log).toEqual([0]);
|
|
122
122
|
|
|
123
|
-
stop
|
|
123
|
+
dispose(stop);
|
|
124
124
|
|
|
125
125
|
expect(log).toEqual([0, 1]);
|
|
126
126
|
});
|
|
@@ -147,7 +147,7 @@ describe('untrack ownership', () => {
|
|
|
147
147
|
|
|
148
148
|
expect(log).toEqual(['a', 'b', 'c', 'd']);
|
|
149
149
|
|
|
150
|
-
stop
|
|
150
|
+
dispose(stop);
|
|
151
151
|
|
|
152
152
|
// dispose() drains owned children after the owner's own cleanups, exactly as for tracked children
|
|
153
153
|
expect(log.slice(4).sort()).toEqual(['a', 'b', 'c', 'd']);
|
|
@@ -186,7 +186,7 @@ describe('untrack ownership', () => {
|
|
|
186
186
|
|
|
187
187
|
expect(c.owner).toBe(null);
|
|
188
188
|
|
|
189
|
-
stop
|
|
189
|
+
dispose(stop);
|
|
190
190
|
|
|
191
191
|
expect(log).toEqual(['effect']);
|
|
192
192
|
});
|
|
@@ -218,7 +218,7 @@ describe('untrack ownership', () => {
|
|
|
218
218
|
|
|
219
219
|
write(s, 1);
|
|
220
220
|
await Promise.resolve();
|
|
221
|
-
stop
|
|
221
|
+
dispose(stop);
|
|
222
222
|
|
|
223
223
|
expect(log).toEqual([0, 1]);
|
|
224
224
|
});
|
|
@@ -239,7 +239,7 @@ describe('untrack ownership', () => {
|
|
|
239
239
|
|
|
240
240
|
write(s, 1);
|
|
241
241
|
await Promise.resolve();
|
|
242
|
-
stop
|
|
242
|
+
dispose(stop);
|
|
243
243
|
|
|
244
244
|
// Neither the root's cleanup (no owner) nor its effects are torn down by the outer effect
|
|
245
245
|
expect(log).toEqual([]);
|
|
@@ -264,7 +264,7 @@ describe('untrack ownership', () => {
|
|
|
264
264
|
read(a);
|
|
265
265
|
});
|
|
266
266
|
|
|
267
|
-
expect(untrack(() =>
|
|
267
|
+
expect(untrack(() => owner() !== null)).toBe(false);
|
|
268
268
|
|
|
269
269
|
write(a, 1);
|
|
270
270
|
await Promise.resolve();
|
|
@@ -289,7 +289,7 @@ describe('untrack ownership', () => {
|
|
|
289
289
|
|
|
290
290
|
expect(log).toEqual(['factory 0']);
|
|
291
291
|
|
|
292
|
-
stop
|
|
292
|
+
dispose(stop);
|
|
293
293
|
|
|
294
294
|
expect(log).toEqual(['factory 0', 'factory 1']);
|
|
295
295
|
});
|