@solidjs/signals 0.0.4 → 0.0.5
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/dist/dev.js +92 -19
- package/dist/node.cjs +221 -145
- package/dist/prod.js +218 -145
- package/dist/types/core/index.d.ts +1 -0
- package/dist/types/core/scheduler.d.ts +1 -0
- package/dist/types/core/suspense.d.ts +1 -1
- package/dist/types/core/utils.d.ts +5 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/signals.d.ts +8 -3
- package/package.json +1 -1
- package/dist/types/utils.d.ts +0 -1
package/dist/node.cjs
CHANGED
|
@@ -5,9 +5,7 @@ var NotReadyError = class extends Error {
|
|
|
5
5
|
};
|
|
6
6
|
var NoOwnerError = class extends Error {
|
|
7
7
|
constructor() {
|
|
8
|
-
super(
|
|
9
|
-
""
|
|
10
|
-
);
|
|
8
|
+
super("");
|
|
11
9
|
}
|
|
12
10
|
};
|
|
13
11
|
var ContextNotFoundError = class extends Error {
|
|
@@ -18,11 +16,6 @@ var ContextNotFoundError = class extends Error {
|
|
|
18
16
|
}
|
|
19
17
|
};
|
|
20
18
|
|
|
21
|
-
// src/utils.ts
|
|
22
|
-
function isUndefined(value) {
|
|
23
|
-
return typeof value === "undefined";
|
|
24
|
-
}
|
|
25
|
-
|
|
26
19
|
// src/core/constants.ts
|
|
27
20
|
var STATE_CLEAN = 0;
|
|
28
21
|
var STATE_CHECK = 1;
|
|
@@ -34,6 +27,65 @@ var EFFECT_RENDER = 1;
|
|
|
34
27
|
var EFFECT_USER = 2;
|
|
35
28
|
var SUPPORTS_PROXY = typeof Proxy === "function";
|
|
36
29
|
|
|
30
|
+
// src/core/utils.ts
|
|
31
|
+
function isUndefined(value) {
|
|
32
|
+
return typeof value === "undefined";
|
|
33
|
+
}
|
|
34
|
+
function flatten(children, options) {
|
|
35
|
+
if (typeof children === "function" && !children.length) {
|
|
36
|
+
if (options == null ? void 0 : options.doNotUnwrap)
|
|
37
|
+
return children;
|
|
38
|
+
do {
|
|
39
|
+
children = children();
|
|
40
|
+
} while (typeof children === "function" && !children.length);
|
|
41
|
+
}
|
|
42
|
+
if ((options == null ? void 0 : options.skipNonRendered) && (children == null || children === true || children === false || children === ""))
|
|
43
|
+
return;
|
|
44
|
+
if (Array.isArray(children)) {
|
|
45
|
+
let results = [];
|
|
46
|
+
if (flattenArray(children, results, options)) {
|
|
47
|
+
return () => {
|
|
48
|
+
let nested = [];
|
|
49
|
+
flattenArray(results, nested, { ...options, doNotUnwrap: false });
|
|
50
|
+
return nested;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
return results;
|
|
54
|
+
}
|
|
55
|
+
return children;
|
|
56
|
+
}
|
|
57
|
+
function flattenArray(children, results = [], options) {
|
|
58
|
+
let notReady = null;
|
|
59
|
+
let needsUnwrap = false;
|
|
60
|
+
for (let i = 0; i < children.length; i++) {
|
|
61
|
+
try {
|
|
62
|
+
let child = children[i];
|
|
63
|
+
if (typeof child === "function" && !child.length) {
|
|
64
|
+
if (options == null ? void 0 : options.doNotUnwrap) {
|
|
65
|
+
results.push(child);
|
|
66
|
+
needsUnwrap = true;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
do {
|
|
70
|
+
child = child();
|
|
71
|
+
} while (typeof child === "function" && !child.length);
|
|
72
|
+
}
|
|
73
|
+
if (Array.isArray(child)) {
|
|
74
|
+
needsUnwrap = flattenArray(child, results, options);
|
|
75
|
+
} else if ((options == null ? void 0 : options.skipNonRendered) && (child == null || child === true || child === false || child === "")) {
|
|
76
|
+
} else
|
|
77
|
+
results.push(child);
|
|
78
|
+
} catch (e) {
|
|
79
|
+
if (!(e instanceof NotReadyError))
|
|
80
|
+
throw e;
|
|
81
|
+
notReady = e;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (notReady)
|
|
85
|
+
throw notReady;
|
|
86
|
+
return needsUnwrap;
|
|
87
|
+
}
|
|
88
|
+
|
|
37
89
|
// src/core/owner.ts
|
|
38
90
|
var currentOwner = null;
|
|
39
91
|
var defaultContext = {};
|
|
@@ -53,9 +105,9 @@ var Owner = class {
|
|
|
53
105
|
m = null;
|
|
54
106
|
p = null;
|
|
55
107
|
a = STATE_CLEAN;
|
|
56
|
-
h = null;
|
|
57
|
-
n = defaultContext;
|
|
58
108
|
i = null;
|
|
109
|
+
n = defaultContext;
|
|
110
|
+
j = null;
|
|
59
111
|
e = null;
|
|
60
112
|
constructor(signal = false) {
|
|
61
113
|
if (currentOwner && !signal)
|
|
@@ -71,8 +123,8 @@ var Owner = class {
|
|
|
71
123
|
if (child.n !== this.n) {
|
|
72
124
|
child.n = { ...this.n, ...child.n };
|
|
73
125
|
}
|
|
74
|
-
if (this.
|
|
75
|
-
child.
|
|
126
|
+
if (this.j) {
|
|
127
|
+
child.j = !child.j ? this.j : [...child.j, ...this.j];
|
|
76
128
|
}
|
|
77
129
|
if (this.e)
|
|
78
130
|
child.e = this.e;
|
|
@@ -101,30 +153,30 @@ var Owner = class {
|
|
|
101
153
|
this.o = null;
|
|
102
154
|
this.p = null;
|
|
103
155
|
this.n = defaultContext;
|
|
104
|
-
this.
|
|
156
|
+
this.j = null;
|
|
105
157
|
this.a = STATE_DISPOSED;
|
|
106
158
|
this.emptyDisposal();
|
|
107
159
|
}
|
|
108
160
|
emptyDisposal() {
|
|
109
|
-
if (!this.
|
|
161
|
+
if (!this.i)
|
|
110
162
|
return;
|
|
111
|
-
if (Array.isArray(this.
|
|
112
|
-
for (let i = 0; i < this.
|
|
113
|
-
const callable = this.
|
|
163
|
+
if (Array.isArray(this.i)) {
|
|
164
|
+
for (let i = 0; i < this.i.length; i++) {
|
|
165
|
+
const callable = this.i[i];
|
|
114
166
|
callable.call(callable);
|
|
115
167
|
}
|
|
116
168
|
} else {
|
|
117
|
-
this.
|
|
169
|
+
this.i.call(this.i);
|
|
118
170
|
}
|
|
119
|
-
this.
|
|
171
|
+
this.i = null;
|
|
120
172
|
}
|
|
121
173
|
handleError(error) {
|
|
122
|
-
if (!this.
|
|
174
|
+
if (!this.j)
|
|
123
175
|
throw error;
|
|
124
|
-
let i = 0, len = this.
|
|
176
|
+
let i = 0, len = this.j.length;
|
|
125
177
|
for (i = 0; i < len; i++) {
|
|
126
178
|
try {
|
|
127
|
-
this.
|
|
179
|
+
this.j[i](error);
|
|
128
180
|
break;
|
|
129
181
|
} catch (e) {
|
|
130
182
|
error = e;
|
|
@@ -163,12 +215,12 @@ function onCleanup(fn) {
|
|
|
163
215
|
if (!currentOwner)
|
|
164
216
|
return fn;
|
|
165
217
|
const node = currentOwner;
|
|
166
|
-
if (!node.
|
|
167
|
-
node.
|
|
168
|
-
} else if (Array.isArray(node.
|
|
169
|
-
node.
|
|
218
|
+
if (!node.i) {
|
|
219
|
+
node.i = fn;
|
|
220
|
+
} else if (Array.isArray(node.i)) {
|
|
221
|
+
node.i.push(fn);
|
|
170
222
|
} else {
|
|
171
|
-
node.
|
|
223
|
+
node.i = [node.i, fn];
|
|
172
224
|
}
|
|
173
225
|
return fn;
|
|
174
226
|
}
|
|
@@ -197,10 +249,10 @@ function incrementClock() {
|
|
|
197
249
|
}
|
|
198
250
|
var UNCHANGED = Symbol(0);
|
|
199
251
|
var Computation = class extends Owner {
|
|
200
|
-
b = null;
|
|
201
252
|
c = null;
|
|
253
|
+
b = null;
|
|
202
254
|
d;
|
|
203
|
-
|
|
255
|
+
B;
|
|
204
256
|
// Used in __DEV__ mode, hopefully removed in production
|
|
205
257
|
V;
|
|
206
258
|
// Using false is an optimization as an alternative to _equals: () => false
|
|
@@ -208,15 +260,15 @@ var Computation = class extends Owner {
|
|
|
208
260
|
F = isEqual;
|
|
209
261
|
N;
|
|
210
262
|
/** Whether the computation is an error or has ancestors that are unresolved */
|
|
211
|
-
|
|
263
|
+
f = 0;
|
|
212
264
|
/** Which flags raised by sources are handled, vs. being passed through. */
|
|
213
|
-
|
|
265
|
+
C = DEFAULT_FLAGS;
|
|
214
266
|
G = null;
|
|
215
267
|
H = null;
|
|
216
268
|
I = -1;
|
|
217
269
|
constructor(initialValue, compute2, options) {
|
|
218
270
|
super(compute2 === null);
|
|
219
|
-
this.
|
|
271
|
+
this.B = compute2;
|
|
220
272
|
this.a = compute2 ? STATE_UNINITIALIZED : STATE_CLEAN;
|
|
221
273
|
this.d = initialValue;
|
|
222
274
|
if ((options == null ? void 0 : options.equals) !== void 0)
|
|
@@ -225,12 +277,13 @@ var Computation = class extends Owner {
|
|
|
225
277
|
this.N = options == null ? void 0 : options.unobserved;
|
|
226
278
|
}
|
|
227
279
|
O() {
|
|
228
|
-
|
|
280
|
+
var _a;
|
|
281
|
+
if (this.B)
|
|
229
282
|
this.s();
|
|
230
|
-
if (!this.
|
|
283
|
+
if (!this.B || ((_a = this.c) == null ? void 0 : _a.length))
|
|
231
284
|
track(this);
|
|
232
|
-
newFlags |= this.
|
|
233
|
-
if (this.
|
|
285
|
+
newFlags |= this.f & ~currentMask;
|
|
286
|
+
if (this.f & ERROR_BIT) {
|
|
234
287
|
throw this.d;
|
|
235
288
|
} else {
|
|
236
289
|
return this.d;
|
|
@@ -285,15 +338,15 @@ var Computation = class extends Owner {
|
|
|
285
338
|
const valueChanged = newValue !== UNCHANGED && (!!(flags & ERROR_BIT) || this.a === STATE_UNINITIALIZED || this.F === false || !this.F(this.d, newValue));
|
|
286
339
|
if (valueChanged)
|
|
287
340
|
this.d = newValue;
|
|
288
|
-
const changedFlagsMask = this.
|
|
289
|
-
this.
|
|
341
|
+
const changedFlagsMask = this.f ^ flags, changedFlags = changedFlagsMask & flags;
|
|
342
|
+
this.f = flags;
|
|
290
343
|
this.I = clock + 1;
|
|
291
|
-
if (this.
|
|
292
|
-
for (let i = 0; i < this.
|
|
344
|
+
if (this.b) {
|
|
345
|
+
for (let i = 0; i < this.b.length; i++) {
|
|
293
346
|
if (valueChanged) {
|
|
294
|
-
this.
|
|
347
|
+
this.b[i].t(STATE_DIRTY);
|
|
295
348
|
} else if (changedFlagsMask) {
|
|
296
|
-
this.
|
|
349
|
+
this.b[i].P(changedFlagsMask, changedFlags);
|
|
297
350
|
}
|
|
298
351
|
}
|
|
299
352
|
}
|
|
@@ -306,9 +359,9 @@ var Computation = class extends Owner {
|
|
|
306
359
|
if (this.a >= state)
|
|
307
360
|
return;
|
|
308
361
|
this.a = state;
|
|
309
|
-
if (this.
|
|
310
|
-
for (let i = 0; i < this.
|
|
311
|
-
this.
|
|
362
|
+
if (this.b) {
|
|
363
|
+
for (let i = 0; i < this.b.length; i++) {
|
|
364
|
+
this.b[i].t(STATE_CHECK);
|
|
312
365
|
}
|
|
313
366
|
}
|
|
314
367
|
}
|
|
@@ -321,27 +374,27 @@ var Computation = class extends Owner {
|
|
|
321
374
|
P(mask, newFlags2) {
|
|
322
375
|
if (this.a >= STATE_DIRTY)
|
|
323
376
|
return;
|
|
324
|
-
if (mask & this.
|
|
377
|
+
if (mask & this.C) {
|
|
325
378
|
this.t(STATE_DIRTY);
|
|
326
379
|
return;
|
|
327
380
|
}
|
|
328
381
|
if (this.a >= STATE_CHECK)
|
|
329
382
|
return;
|
|
330
|
-
const prevFlags = this.
|
|
383
|
+
const prevFlags = this.f & mask;
|
|
331
384
|
const deltaFlags = prevFlags ^ newFlags2;
|
|
332
385
|
if (newFlags2 === prevFlags) ; else if (deltaFlags & prevFlags & mask) {
|
|
333
386
|
this.t(STATE_CHECK);
|
|
334
387
|
} else {
|
|
335
|
-
this.
|
|
336
|
-
if (this.
|
|
337
|
-
for (let i = 0; i < this.
|
|
338
|
-
this.
|
|
388
|
+
this.f ^= deltaFlags;
|
|
389
|
+
if (this.b) {
|
|
390
|
+
for (let i = 0; i < this.b.length; i++) {
|
|
391
|
+
this.b[i].P(mask, newFlags2);
|
|
339
392
|
}
|
|
340
393
|
}
|
|
341
394
|
}
|
|
342
395
|
}
|
|
343
396
|
Q(error) {
|
|
344
|
-
this.write(error, this.
|
|
397
|
+
this.write(error, this.f | ERROR_BIT);
|
|
345
398
|
}
|
|
346
399
|
/**
|
|
347
400
|
* This is the core part of the reactivity system, which makes sure that the values are updated
|
|
@@ -359,9 +412,9 @@ var Computation = class extends Owner {
|
|
|
359
412
|
}
|
|
360
413
|
let observerFlags = 0;
|
|
361
414
|
if (this.a === STATE_CHECK) {
|
|
362
|
-
for (let i = 0; i < this.
|
|
363
|
-
this.
|
|
364
|
-
observerFlags |= this.
|
|
415
|
+
for (let i = 0; i < this.c.length; i++) {
|
|
416
|
+
this.c[i].s();
|
|
417
|
+
observerFlags |= this.c[i].f;
|
|
365
418
|
if (this.a === STATE_DIRTY) {
|
|
366
419
|
break;
|
|
367
420
|
}
|
|
@@ -380,7 +433,7 @@ var Computation = class extends Owner {
|
|
|
380
433
|
x() {
|
|
381
434
|
if (this.a === STATE_DISPOSED)
|
|
382
435
|
return;
|
|
383
|
-
if (this.
|
|
436
|
+
if (this.c)
|
|
384
437
|
removeSourceObservers(this, 0);
|
|
385
438
|
super.x();
|
|
386
439
|
}
|
|
@@ -393,11 +446,11 @@ function loadingState(node) {
|
|
|
393
446
|
() => {
|
|
394
447
|
track(node);
|
|
395
448
|
node.s();
|
|
396
|
-
return !!(node.
|
|
449
|
+
return !!(node.f & LOADING_BIT);
|
|
397
450
|
},
|
|
398
451
|
options
|
|
399
452
|
);
|
|
400
|
-
computation.
|
|
453
|
+
computation.C = ERROR_BIT | LOADING_BIT;
|
|
401
454
|
setOwner(prevOwner);
|
|
402
455
|
return computation;
|
|
403
456
|
}
|
|
@@ -409,17 +462,17 @@ function errorState(node) {
|
|
|
409
462
|
() => {
|
|
410
463
|
track(node);
|
|
411
464
|
node.s();
|
|
412
|
-
return !!(node.
|
|
465
|
+
return !!(node.f & ERROR_BIT);
|
|
413
466
|
},
|
|
414
467
|
options
|
|
415
468
|
);
|
|
416
|
-
computation.
|
|
469
|
+
computation.C = ERROR_BIT;
|
|
417
470
|
setOwner(prevOwner);
|
|
418
471
|
return computation;
|
|
419
472
|
}
|
|
420
473
|
function track(computation) {
|
|
421
474
|
if (currentObserver) {
|
|
422
|
-
if (!newSources && currentObserver.
|
|
475
|
+
if (!newSources && currentObserver.c && currentObserver.c[newSourcesIndex] === computation) {
|
|
423
476
|
newSourcesIndex++;
|
|
424
477
|
} else if (!newSources)
|
|
425
478
|
newSources = [computation];
|
|
@@ -439,7 +492,7 @@ function update(node) {
|
|
|
439
492
|
try {
|
|
440
493
|
node.dispose(false);
|
|
441
494
|
node.emptyDisposal();
|
|
442
|
-
const result = compute(node, node.
|
|
495
|
+
const result = compute(node, node.B, node);
|
|
443
496
|
node.write(result, newFlags, true);
|
|
444
497
|
} catch (error) {
|
|
445
498
|
if (error instanceof NotReadyError) {
|
|
@@ -449,27 +502,27 @@ function update(node) {
|
|
|
449
502
|
}
|
|
450
503
|
} finally {
|
|
451
504
|
if (newSources) {
|
|
452
|
-
if (node.
|
|
505
|
+
if (node.c)
|
|
453
506
|
removeSourceObservers(node, newSourcesIndex);
|
|
454
|
-
if (node.
|
|
455
|
-
node.
|
|
507
|
+
if (node.c && newSourcesIndex > 0) {
|
|
508
|
+
node.c.length = newSourcesIndex + newSources.length;
|
|
456
509
|
for (let i = 0; i < newSources.length; i++) {
|
|
457
|
-
node.
|
|
510
|
+
node.c[newSourcesIndex + i] = newSources[i];
|
|
458
511
|
}
|
|
459
512
|
} else {
|
|
460
|
-
node.
|
|
513
|
+
node.c = newSources;
|
|
461
514
|
}
|
|
462
515
|
let source;
|
|
463
|
-
for (let i = newSourcesIndex; i < node.
|
|
464
|
-
source = node.
|
|
465
|
-
if (!source.
|
|
466
|
-
source.
|
|
516
|
+
for (let i = newSourcesIndex; i < node.c.length; i++) {
|
|
517
|
+
source = node.c[i];
|
|
518
|
+
if (!source.b)
|
|
519
|
+
source.b = [node];
|
|
467
520
|
else
|
|
468
|
-
source.
|
|
521
|
+
source.b.push(node);
|
|
469
522
|
}
|
|
470
|
-
} else if (node.
|
|
523
|
+
} else if (node.c && newSourcesIndex < node.c.length) {
|
|
471
524
|
removeSourceObservers(node, newSourcesIndex);
|
|
472
|
-
node.
|
|
525
|
+
node.c.length = newSourcesIndex;
|
|
473
526
|
}
|
|
474
527
|
newSources = prevSources;
|
|
475
528
|
newSourcesIndex = prevSourcesIndex;
|
|
@@ -481,13 +534,13 @@ function removeSourceObservers(node, index) {
|
|
|
481
534
|
var _a;
|
|
482
535
|
let source;
|
|
483
536
|
let swap;
|
|
484
|
-
for (let i = index; i < node.
|
|
485
|
-
source = node.
|
|
486
|
-
if (source.
|
|
487
|
-
swap = source.
|
|
488
|
-
source.
|
|
489
|
-
source.
|
|
490
|
-
if (!source.
|
|
537
|
+
for (let i = index; i < node.c.length; i++) {
|
|
538
|
+
source = node.c[i];
|
|
539
|
+
if (source.b) {
|
|
540
|
+
swap = source.b.indexOf(node);
|
|
541
|
+
source.b[swap] = source.b[source.b.length - 1];
|
|
542
|
+
source.b.pop();
|
|
543
|
+
if (!source.b.length)
|
|
491
544
|
(_a = source.N) == null ? void 0 : _a.call(source);
|
|
492
545
|
}
|
|
493
546
|
}
|
|
@@ -532,7 +585,7 @@ function latest(fn) {
|
|
|
532
585
|
function compute(owner, compute2, observer) {
|
|
533
586
|
const prevOwner = setOwner(owner), prevObserver = currentObserver, prevMask = currentMask;
|
|
534
587
|
currentObserver = observer;
|
|
535
|
-
currentMask = (observer == null ? void 0 : observer.
|
|
588
|
+
currentMask = (observer == null ? void 0 : observer.C) ?? DEFAULT_FLAGS;
|
|
536
589
|
try {
|
|
537
590
|
return compute2(observer ? observer.d : void 0);
|
|
538
591
|
} finally {
|
|
@@ -548,11 +601,11 @@ function schedule() {
|
|
|
548
601
|
if (scheduled)
|
|
549
602
|
return;
|
|
550
603
|
scheduled = true;
|
|
551
|
-
if (!globalQueue.
|
|
604
|
+
if (!globalQueue.D)
|
|
552
605
|
queueMicrotask(flushSync);
|
|
553
606
|
}
|
|
554
607
|
var Queue = class {
|
|
555
|
-
|
|
608
|
+
D = false;
|
|
556
609
|
u = [[], [], []];
|
|
557
610
|
z = [];
|
|
558
611
|
enqueue(type, node) {
|
|
@@ -577,9 +630,9 @@ var Queue = class {
|
|
|
577
630
|
}
|
|
578
631
|
}
|
|
579
632
|
flush() {
|
|
580
|
-
if (this.
|
|
633
|
+
if (this.D)
|
|
581
634
|
return;
|
|
582
|
-
this.
|
|
635
|
+
this.D = true;
|
|
583
636
|
try {
|
|
584
637
|
this.run(EFFECT_PURE);
|
|
585
638
|
incrementClock();
|
|
@@ -587,7 +640,7 @@ var Queue = class {
|
|
|
587
640
|
this.run(EFFECT_RENDER);
|
|
588
641
|
this.run(EFFECT_USER);
|
|
589
642
|
} finally {
|
|
590
|
-
this.
|
|
643
|
+
this.D = false;
|
|
591
644
|
}
|
|
592
645
|
}
|
|
593
646
|
addChild(child) {
|
|
@@ -600,11 +653,19 @@ var Queue = class {
|
|
|
600
653
|
}
|
|
601
654
|
};
|
|
602
655
|
var globalQueue = new Queue();
|
|
656
|
+
var globalTasks = [];
|
|
603
657
|
function flushSync() {
|
|
604
658
|
while (scheduled) {
|
|
605
659
|
globalQueue.flush();
|
|
660
|
+
for (let i = 0; i < globalTasks.length; i++)
|
|
661
|
+
globalTasks[i]();
|
|
662
|
+
globalTasks.length = 0;
|
|
606
663
|
}
|
|
607
664
|
}
|
|
665
|
+
function queueTask(fn) {
|
|
666
|
+
globalTasks.push(fn);
|
|
667
|
+
schedule();
|
|
668
|
+
}
|
|
608
669
|
function createBoundary(fn, queue) {
|
|
609
670
|
const owner = new Owner();
|
|
610
671
|
const parentQueue = owner.e || globalQueue;
|
|
@@ -639,25 +700,25 @@ function runEffectQueue(queue) {
|
|
|
639
700
|
var Effect = class extends Computation {
|
|
640
701
|
J;
|
|
641
702
|
K = false;
|
|
642
|
-
|
|
643
|
-
|
|
703
|
+
E;
|
|
704
|
+
A;
|
|
644
705
|
e;
|
|
645
706
|
constructor(initialValue, compute2, effect, options) {
|
|
646
707
|
var _a;
|
|
647
708
|
super(initialValue, compute2, options);
|
|
648
709
|
this.J = effect;
|
|
649
|
-
this.
|
|
650
|
-
this.
|
|
710
|
+
this.E = initialValue;
|
|
711
|
+
this.A = (options == null ? void 0 : options.render) ? EFFECT_RENDER : EFFECT_USER;
|
|
651
712
|
this.e = ((_a = getOwner()) == null ? void 0 : _a.e) || globalQueue;
|
|
652
713
|
this.s();
|
|
653
|
-
this.
|
|
714
|
+
this.A === EFFECT_USER ? this.e.enqueue(this.A, this) : this.R();
|
|
654
715
|
}
|
|
655
716
|
write(value, flags = 0) {
|
|
656
717
|
var _a, _b;
|
|
657
|
-
const currentFlags = this.
|
|
658
|
-
this.
|
|
659
|
-
if ((flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
|
|
660
|
-
(_b = (_a = this.e).
|
|
718
|
+
const currentFlags = this.f;
|
|
719
|
+
this.f = flags;
|
|
720
|
+
if (this.A === EFFECT_RENDER && (flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
|
|
721
|
+
(_b = (_a = this.e).S) == null ? void 0 : _b.call(_a, this);
|
|
661
722
|
}
|
|
662
723
|
if (value === UNCHANGED)
|
|
663
724
|
return this.d;
|
|
@@ -669,7 +730,7 @@ var Effect = class extends Computation {
|
|
|
669
730
|
if (this.a >= state)
|
|
670
731
|
return;
|
|
671
732
|
if (this.a === STATE_CLEAN)
|
|
672
|
-
this.e.enqueue(this.
|
|
733
|
+
this.e.enqueue(this.A, this);
|
|
673
734
|
this.a = state;
|
|
674
735
|
}
|
|
675
736
|
Q(error) {
|
|
@@ -677,13 +738,13 @@ var Effect = class extends Computation {
|
|
|
677
738
|
}
|
|
678
739
|
x() {
|
|
679
740
|
this.J = void 0;
|
|
680
|
-
this.
|
|
741
|
+
this.E = void 0;
|
|
681
742
|
super.x();
|
|
682
743
|
}
|
|
683
744
|
R() {
|
|
684
745
|
if (this.K && this.a !== STATE_DISPOSED) {
|
|
685
|
-
this.J(this.d, this.
|
|
686
|
-
this.
|
|
746
|
+
this.J(this.d, this.E);
|
|
747
|
+
this.E = this.d;
|
|
687
748
|
this.K = false;
|
|
688
749
|
}
|
|
689
750
|
}
|
|
@@ -707,7 +768,7 @@ var EagerComputation = class extends Computation {
|
|
|
707
768
|
|
|
708
769
|
// src/core/suspense.ts
|
|
709
770
|
var SuspenseQueue = class extends Queue {
|
|
710
|
-
|
|
771
|
+
g = /* @__PURE__ */ new Set();
|
|
711
772
|
q = false;
|
|
712
773
|
L = new Computation(false, null);
|
|
713
774
|
run(type) {
|
|
@@ -715,27 +776,41 @@ var SuspenseQueue = class extends Queue {
|
|
|
715
776
|
return;
|
|
716
777
|
super.run(type);
|
|
717
778
|
}
|
|
718
|
-
|
|
719
|
-
if (node.
|
|
720
|
-
this.
|
|
779
|
+
S(node) {
|
|
780
|
+
if (node.f & LOADING_BIT) {
|
|
781
|
+
this.g.add(node);
|
|
721
782
|
if (!this.q) {
|
|
722
783
|
this.q = true;
|
|
723
|
-
|
|
784
|
+
queueTask(() => this.L.write(true));
|
|
724
785
|
}
|
|
725
786
|
} else {
|
|
726
|
-
this.
|
|
727
|
-
if (this.
|
|
787
|
+
this.g.delete(node);
|
|
788
|
+
if (this.g.size === 0) {
|
|
728
789
|
this.q = false;
|
|
729
|
-
|
|
790
|
+
queueTask(() => this.L.write(false));
|
|
730
791
|
}
|
|
731
792
|
}
|
|
732
793
|
}
|
|
733
794
|
};
|
|
795
|
+
var LiveComputation = class extends EagerComputation {
|
|
796
|
+
write(value, flags = 0) {
|
|
797
|
+
var _a, _b;
|
|
798
|
+
const currentFlags = this.f;
|
|
799
|
+
super.write(value, flags);
|
|
800
|
+
if ((flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
|
|
801
|
+
(_b = (_a = this.e).S) == null ? void 0 : _b.call(_a, this);
|
|
802
|
+
}
|
|
803
|
+
return this.d;
|
|
804
|
+
}
|
|
805
|
+
};
|
|
734
806
|
function createSuspense(fn, fallbackFn) {
|
|
735
807
|
const queue = new SuspenseQueue();
|
|
736
|
-
const tree = createBoundary(
|
|
808
|
+
const tree = createBoundary(() => {
|
|
809
|
+
const child = new Computation(null, fn);
|
|
810
|
+
return new LiveComputation(null, () => flatten(child.wait()));
|
|
811
|
+
}, queue);
|
|
737
812
|
const equality = new Computation(null, () => queue.L.read() || queue.q);
|
|
738
|
-
const comp = new Computation(null, () => equality.read() ? untrack(fallbackFn) : tree);
|
|
813
|
+
const comp = new Computation(null, () => equality.read() ? untrack(fallbackFn) : tree.read());
|
|
739
814
|
return comp.read.bind(comp);
|
|
740
815
|
}
|
|
741
816
|
|
|
@@ -763,13 +838,13 @@ function createMemo(compute2, value, options) {
|
|
|
763
838
|
);
|
|
764
839
|
let resolvedValue;
|
|
765
840
|
return () => {
|
|
766
|
-
var _a, _b;
|
|
841
|
+
var _a, _b, _c;
|
|
767
842
|
if (node) {
|
|
768
843
|
resolvedValue = node.wait();
|
|
769
|
-
if (!((_a = node.
|
|
844
|
+
if (!((_a = node.c) == null ? void 0 : _a.length) && ((_b = node.m) == null ? void 0 : _b.o) !== node) {
|
|
770
845
|
node.dispose();
|
|
771
846
|
node = void 0;
|
|
772
|
-
} else if (!node.o && !((
|
|
847
|
+
} else if (!node.o && !((_c = node.b) == null ? void 0 : _c.length)) {
|
|
773
848
|
node.dispose();
|
|
774
849
|
node.a = STATE_UNINITIALIZED;
|
|
775
850
|
}
|
|
@@ -800,7 +875,7 @@ function createAsync(compute2, value, options) {
|
|
|
800
875
|
if (isPromise) {
|
|
801
876
|
source.then(
|
|
802
877
|
(value3) => {
|
|
803
|
-
signal.write(value3, 0);
|
|
878
|
+
signal.write(value3, 0, true);
|
|
804
879
|
},
|
|
805
880
|
(error) => {
|
|
806
881
|
signal.write(error, ERROR_BIT);
|
|
@@ -814,7 +889,7 @@ function createAsync(compute2, value, options) {
|
|
|
814
889
|
for await (let value3 of source) {
|
|
815
890
|
if (abort)
|
|
816
891
|
return;
|
|
817
|
-
signal.write(value3, 0);
|
|
892
|
+
signal.write(value3, 0, true);
|
|
818
893
|
}
|
|
819
894
|
} catch (error) {
|
|
820
895
|
signal.write(error, ERROR_BIT);
|
|
@@ -854,9 +929,9 @@ function runWithOwner(owner, run) {
|
|
|
854
929
|
}
|
|
855
930
|
function catchError(fn, handler) {
|
|
856
931
|
const owner = new Owner();
|
|
857
|
-
owner.
|
|
932
|
+
owner.j = owner.j ? [handler, ...owner.j] : [handler];
|
|
858
933
|
try {
|
|
859
|
-
compute(owner, fn, null);
|
|
934
|
+
return compute(owner, fn, null);
|
|
860
935
|
} catch (error) {
|
|
861
936
|
owner.handleError(error);
|
|
862
937
|
}
|
|
@@ -1323,15 +1398,15 @@ function omit(props, ...keys) {
|
|
|
1323
1398
|
function mapArray(list, map, options) {
|
|
1324
1399
|
const keyFn = typeof (options == null ? void 0 : options.keyed) === "function" ? options.keyed : void 0;
|
|
1325
1400
|
return updateKeyedMap.bind({
|
|
1326
|
-
|
|
1401
|
+
T: new Owner(),
|
|
1327
1402
|
w: 0,
|
|
1328
1403
|
U: list,
|
|
1329
1404
|
r: [],
|
|
1330
1405
|
M: map,
|
|
1331
1406
|
k: [],
|
|
1332
|
-
|
|
1407
|
+
g: [],
|
|
1333
1408
|
y: keyFn,
|
|
1334
|
-
|
|
1409
|
+
h: keyFn || (options == null ? void 0 : options.keyed) === false ? [] : void 0,
|
|
1335
1410
|
l: map.length > 1 ? [] : void 0,
|
|
1336
1411
|
q: options == null ? void 0 : options.fallback
|
|
1337
1412
|
});
|
|
@@ -1339,12 +1414,12 @@ function mapArray(list, map, options) {
|
|
|
1339
1414
|
function updateKeyedMap() {
|
|
1340
1415
|
const newItems = this.U() || [], newLen = newItems.length;
|
|
1341
1416
|
newItems[$TRACK];
|
|
1342
|
-
runWithOwner(this.
|
|
1343
|
-
let i, j, mapper = this.
|
|
1344
|
-
this.
|
|
1417
|
+
runWithOwner(this.T, () => {
|
|
1418
|
+
let i, j, mapper = this.h ? () => {
|
|
1419
|
+
this.h[j] = new Computation(newItems[j], null);
|
|
1345
1420
|
this.l[j] = new Computation(j, null);
|
|
1346
1421
|
return this.M(
|
|
1347
|
-
Computation.prototype.read.bind(this.
|
|
1422
|
+
Computation.prototype.read.bind(this.h[j]),
|
|
1348
1423
|
Computation.prototype.read.bind(this.l[j])
|
|
1349
1424
|
);
|
|
1350
1425
|
} : this.l ? () => {
|
|
@@ -1357,40 +1432,40 @@ function updateKeyedMap() {
|
|
|
1357
1432
|
};
|
|
1358
1433
|
if (newLen === 0) {
|
|
1359
1434
|
if (this.w !== 0) {
|
|
1360
|
-
this.
|
|
1361
|
-
this.
|
|
1435
|
+
this.T.dispose(false);
|
|
1436
|
+
this.g = [];
|
|
1362
1437
|
this.r = [];
|
|
1363
1438
|
this.k = [];
|
|
1364
1439
|
this.w = 0;
|
|
1365
|
-
this.
|
|
1440
|
+
this.h && (this.h = []);
|
|
1366
1441
|
this.l && (this.l = []);
|
|
1367
1442
|
}
|
|
1368
1443
|
if (this.q && !this.k[0]) {
|
|
1369
1444
|
this.k[0] = compute(
|
|
1370
|
-
this.
|
|
1445
|
+
this.g[0] = new Owner(),
|
|
1371
1446
|
this.q,
|
|
1372
1447
|
null
|
|
1373
1448
|
);
|
|
1374
1449
|
}
|
|
1375
1450
|
} else if (this.w === 0) {
|
|
1376
|
-
if (this.
|
|
1377
|
-
this.
|
|
1451
|
+
if (this.g[0])
|
|
1452
|
+
this.g[0].dispose();
|
|
1378
1453
|
this.k = new Array(newLen);
|
|
1379
1454
|
for (j = 0; j < newLen; j++) {
|
|
1380
1455
|
this.r[j] = newItems[j];
|
|
1381
|
-
this.k[j] = compute(this.
|
|
1456
|
+
this.k[j] = compute(this.g[j] = new Owner(), mapper, null);
|
|
1382
1457
|
}
|
|
1383
1458
|
this.w = newLen;
|
|
1384
1459
|
} else {
|
|
1385
|
-
let start, end, newEnd, item, key, newIndices, newIndicesNext, temp = new Array(newLen), tempNodes = new Array(newLen), tempRows = this.
|
|
1386
|
-
for (start = 0, end = Math.min(this.w, newLen); start < end && (this.r[start] === newItems[start] || this.
|
|
1387
|
-
if (this.
|
|
1388
|
-
this.
|
|
1460
|
+
let start, end, newEnd, item, key, newIndices, newIndicesNext, temp = new Array(newLen), tempNodes = new Array(newLen), tempRows = this.h ? new Array(newLen) : void 0, tempIndexes = this.l ? new Array(newLen) : void 0;
|
|
1461
|
+
for (start = 0, end = Math.min(this.w, newLen); start < end && (this.r[start] === newItems[start] || this.h && compare(this.y, this.r[start], newItems[start])); start++) {
|
|
1462
|
+
if (this.h)
|
|
1463
|
+
this.h[start].write(newItems[start]);
|
|
1389
1464
|
}
|
|
1390
|
-
for (end = this.w - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.r[end] === newItems[newEnd] || this.
|
|
1465
|
+
for (end = this.w - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.r[end] === newItems[newEnd] || this.h && compare(this.y, this.r[end], newItems[newEnd])); end--, newEnd--) {
|
|
1391
1466
|
temp[newEnd] = this.k[end];
|
|
1392
|
-
tempNodes[newEnd] = this.
|
|
1393
|
-
tempRows && (tempRows[newEnd] = this.
|
|
1467
|
+
tempNodes[newEnd] = this.g[end];
|
|
1468
|
+
tempRows && (tempRows[newEnd] = this.h[end]);
|
|
1394
1469
|
tempIndexes && (tempIndexes[newEnd] = this.l[end]);
|
|
1395
1470
|
}
|
|
1396
1471
|
newIndices = /* @__PURE__ */ new Map();
|
|
@@ -1408,28 +1483,28 @@ function updateKeyedMap() {
|
|
|
1408
1483
|
j = newIndices.get(key);
|
|
1409
1484
|
if (j !== void 0 && j !== -1) {
|
|
1410
1485
|
temp[j] = this.k[i];
|
|
1411
|
-
tempNodes[j] = this.
|
|
1412
|
-
tempRows && (tempRows[j] = this.
|
|
1486
|
+
tempNodes[j] = this.g[i];
|
|
1487
|
+
tempRows && (tempRows[j] = this.h[i]);
|
|
1413
1488
|
tempIndexes && (tempIndexes[j] = this.l[i]);
|
|
1414
1489
|
j = newIndicesNext[j];
|
|
1415
1490
|
newIndices.set(key, j);
|
|
1416
1491
|
} else
|
|
1417
|
-
this.
|
|
1492
|
+
this.g[i].dispose();
|
|
1418
1493
|
}
|
|
1419
1494
|
for (j = start; j < newLen; j++) {
|
|
1420
1495
|
if (j in temp) {
|
|
1421
1496
|
this.k[j] = temp[j];
|
|
1422
|
-
this.
|
|
1497
|
+
this.g[j] = tempNodes[j];
|
|
1423
1498
|
if (tempRows) {
|
|
1424
|
-
this.
|
|
1425
|
-
this.
|
|
1499
|
+
this.h[j] = tempRows[j];
|
|
1500
|
+
this.h[j].write(newItems[j]);
|
|
1426
1501
|
}
|
|
1427
1502
|
if (tempIndexes) {
|
|
1428
1503
|
this.l[j] = tempIndexes[j];
|
|
1429
1504
|
this.l[j].write(j);
|
|
1430
1505
|
}
|
|
1431
1506
|
} else {
|
|
1432
|
-
this.k[j] = compute(this.
|
|
1507
|
+
this.k[j] = compute(this.g[j] = new Owner(), mapper, null);
|
|
1433
1508
|
}
|
|
1434
1509
|
}
|
|
1435
1510
|
this.k = this.k.slice(0, this.w = newLen);
|
|
@@ -1465,6 +1540,7 @@ exports.createRoot = createRoot;
|
|
|
1465
1540
|
exports.createSignal = createSignal;
|
|
1466
1541
|
exports.createStore = createStore;
|
|
1467
1542
|
exports.createSuspense = createSuspense;
|
|
1543
|
+
exports.flatten = flatten;
|
|
1468
1544
|
exports.flushSync = flushSync;
|
|
1469
1545
|
exports.getContext = getContext;
|
|
1470
1546
|
exports.getObserver = getObserver;
|