@solidjs/signals 0.4.0 → 0.4.1
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 +12 -9
- package/dist/node.cjs +149 -146
- package/dist/prod.js +149 -146
- package/dist/types/core/effect.d.ts +3 -1
- package/package.json +1 -1
package/dist/prod.js
CHANGED
|
@@ -37,20 +37,20 @@ function schedule() {
|
|
|
37
37
|
if (scheduled)
|
|
38
38
|
return;
|
|
39
39
|
scheduled = true;
|
|
40
|
-
if (!globalQueue.
|
|
40
|
+
if (!globalQueue.K)
|
|
41
41
|
queueMicrotask(flush);
|
|
42
42
|
}
|
|
43
43
|
var pureQueue = [];
|
|
44
44
|
var Queue = class {
|
|
45
45
|
o = null;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
K = false;
|
|
47
|
+
L = [[], []];
|
|
48
|
+
F = [];
|
|
49
49
|
created = clock;
|
|
50
50
|
enqueue(type, fn) {
|
|
51
51
|
pureQueue.push(fn);
|
|
52
52
|
if (type)
|
|
53
|
-
this.
|
|
53
|
+
this.L[type - 1].push(fn);
|
|
54
54
|
schedule();
|
|
55
55
|
}
|
|
56
56
|
run(type) {
|
|
@@ -58,19 +58,19 @@ var Queue = class {
|
|
|
58
58
|
pureQueue.length && runQueue(pureQueue, type);
|
|
59
59
|
pureQueue = [];
|
|
60
60
|
return;
|
|
61
|
-
} else if (this.
|
|
62
|
-
const effects = this.
|
|
63
|
-
this.
|
|
61
|
+
} else if (this.L[type - 1].length) {
|
|
62
|
+
const effects = this.L[type - 1];
|
|
63
|
+
this.L[type - 1] = [];
|
|
64
64
|
runQueue(effects, type);
|
|
65
65
|
}
|
|
66
|
-
for (let i = 0; i < this.
|
|
67
|
-
this.
|
|
66
|
+
for (let i = 0; i < this.F.length; i++) {
|
|
67
|
+
this.F[i].run(type);
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
flush() {
|
|
71
|
-
if (this.
|
|
71
|
+
if (this.K)
|
|
72
72
|
return;
|
|
73
|
-
this.
|
|
73
|
+
this.K = true;
|
|
74
74
|
try {
|
|
75
75
|
this.run(EFFECT_PURE);
|
|
76
76
|
incrementClock();
|
|
@@ -78,17 +78,17 @@ var Queue = class {
|
|
|
78
78
|
this.run(EFFECT_RENDER);
|
|
79
79
|
this.run(EFFECT_USER);
|
|
80
80
|
} finally {
|
|
81
|
-
this.
|
|
81
|
+
this.K = false;
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
addChild(child) {
|
|
85
|
-
this.
|
|
85
|
+
this.F.push(child);
|
|
86
86
|
child.o = this;
|
|
87
87
|
}
|
|
88
88
|
removeChild(child) {
|
|
89
|
-
const index = this.
|
|
89
|
+
const index = this.F.indexOf(child);
|
|
90
90
|
if (index >= 0)
|
|
91
|
-
this.
|
|
91
|
+
this.F.splice(index, 1);
|
|
92
92
|
}
|
|
93
93
|
notify(...args) {
|
|
94
94
|
if (this.o)
|
|
@@ -158,20 +158,20 @@ var Owner = class {
|
|
|
158
158
|
let head = self ? this.t || this.o : this, current = this.m, next = null;
|
|
159
159
|
while (current && current.o === this) {
|
|
160
160
|
current.dispose(true);
|
|
161
|
-
current.
|
|
161
|
+
current.z();
|
|
162
162
|
next = current.m;
|
|
163
163
|
current.m = null;
|
|
164
164
|
current = next;
|
|
165
165
|
}
|
|
166
166
|
this.W = 0;
|
|
167
167
|
if (self)
|
|
168
|
-
this.
|
|
168
|
+
this.z();
|
|
169
169
|
if (current)
|
|
170
170
|
current.t = !self ? this : this.t;
|
|
171
171
|
if (head)
|
|
172
172
|
head.m = current;
|
|
173
173
|
}
|
|
174
|
-
|
|
174
|
+
z() {
|
|
175
175
|
if (this.t)
|
|
176
176
|
this.t.m = null;
|
|
177
177
|
this.o = null;
|
|
@@ -272,45 +272,45 @@ var Computation = class extends Owner {
|
|
|
272
272
|
c = null;
|
|
273
273
|
d = null;
|
|
274
274
|
g;
|
|
275
|
-
|
|
276
|
-
|
|
275
|
+
G;
|
|
276
|
+
A;
|
|
277
277
|
// Used in __DEV__ mode, hopefully removed in production
|
|
278
278
|
ca;
|
|
279
279
|
// Using false is an optimization as an alternative to _equals: () => false
|
|
280
280
|
// which could enable more efficient DIRTY notification
|
|
281
|
-
|
|
281
|
+
S = isEqual;
|
|
282
282
|
X;
|
|
283
283
|
_ = false;
|
|
284
284
|
/** Whether the computation is an error or has ancestors that are unresolved */
|
|
285
285
|
f = 0;
|
|
286
286
|
/** Which flags raised by sources are handled, vs. being passed through. */
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
287
|
+
T = DEFAULT_FLAGS;
|
|
288
|
+
B = -1;
|
|
289
|
+
x = false;
|
|
290
290
|
constructor(initialValue, compute2, options) {
|
|
291
291
|
super(options?.id, compute2 === null);
|
|
292
|
-
this.
|
|
292
|
+
this.A = compute2;
|
|
293
293
|
this.a = compute2 ? STATE_DIRTY : STATE_CLEAN;
|
|
294
294
|
this.f = compute2 && initialValue === void 0 ? UNINITIALIZED_BIT : 0;
|
|
295
295
|
this.g = initialValue;
|
|
296
296
|
if (options?.equals !== void 0)
|
|
297
|
-
this.
|
|
297
|
+
this.S = options.equals;
|
|
298
298
|
if (options?.pureWrite)
|
|
299
299
|
this._ = true;
|
|
300
300
|
if (options?.unobserved)
|
|
301
301
|
this.X = options?.unobserved;
|
|
302
302
|
}
|
|
303
303
|
Y() {
|
|
304
|
-
if (this.
|
|
305
|
-
if (this.f & ERROR_BIT && this.
|
|
304
|
+
if (this.A) {
|
|
305
|
+
if (this.f & ERROR_BIT && this.B <= getClock())
|
|
306
306
|
update(this);
|
|
307
307
|
else
|
|
308
|
-
this.
|
|
308
|
+
this.y();
|
|
309
309
|
}
|
|
310
310
|
track(this);
|
|
311
311
|
newFlags |= this.f & ~currentMask;
|
|
312
312
|
if (this.f & ERROR_BIT) {
|
|
313
|
-
throw this.
|
|
313
|
+
throw this.G;
|
|
314
314
|
} else {
|
|
315
315
|
return this.g;
|
|
316
316
|
}
|
|
@@ -330,10 +330,10 @@ var Computation = class extends Owner {
|
|
|
330
330
|
* before continuing
|
|
331
331
|
*/
|
|
332
332
|
wait() {
|
|
333
|
-
if (this.
|
|
333
|
+
if (this.A && this.f & ERROR_BIT && this.B <= getClock()) {
|
|
334
334
|
update(this);
|
|
335
335
|
} else {
|
|
336
|
-
this.
|
|
336
|
+
this.y();
|
|
337
337
|
}
|
|
338
338
|
track(this);
|
|
339
339
|
if ((notStale || this.f & UNINITIALIZED_BIT) && this.f & LOADING_BIT) {
|
|
@@ -348,14 +348,14 @@ var Computation = class extends Owner {
|
|
|
348
348
|
write(value, flags = 0, raw = false) {
|
|
349
349
|
const newValue = !raw && typeof value === "function" ? value(this.g) : value;
|
|
350
350
|
const valueChanged = newValue !== UNCHANGED && (!!(this.f & UNINITIALIZED_BIT) || // this._stateFlags & LOADING_BIT & ~flags ||
|
|
351
|
-
this.
|
|
351
|
+
this.S === false || !this.S(this.g, newValue));
|
|
352
352
|
if (valueChanged) {
|
|
353
353
|
this.g = newValue;
|
|
354
|
-
this.
|
|
354
|
+
this.G = void 0;
|
|
355
355
|
}
|
|
356
356
|
const changedFlagsMask = this.f ^ flags, changedFlags = changedFlagsMask & flags;
|
|
357
357
|
this.f = flags;
|
|
358
|
-
this.
|
|
358
|
+
this.B = getClock() + 1;
|
|
359
359
|
if (this.d) {
|
|
360
360
|
for (let i = 0; i < this.d.length; i++) {
|
|
361
361
|
if (valueChanged) {
|
|
@@ -371,9 +371,9 @@ var Computation = class extends Owner {
|
|
|
371
371
|
* Set the current node's state, and recursively mark all of this node's observers as STATE_CHECK
|
|
372
372
|
*/
|
|
373
373
|
r(state, skipQueue) {
|
|
374
|
-
if (this.a >= state && !this.
|
|
374
|
+
if (this.a >= state && !this.x)
|
|
375
375
|
return;
|
|
376
|
-
this.
|
|
376
|
+
this.x = !!skipQueue;
|
|
377
377
|
this.a = state;
|
|
378
378
|
if (this.d) {
|
|
379
379
|
for (let i = 0; i < this.d.length; i++) {
|
|
@@ -390,7 +390,7 @@ var Computation = class extends Owner {
|
|
|
390
390
|
Z(mask, newFlags2) {
|
|
391
391
|
if (this.a >= STATE_DIRTY)
|
|
392
392
|
return;
|
|
393
|
-
if (mask & this.
|
|
393
|
+
if (mask & this.T) {
|
|
394
394
|
this.r(STATE_DIRTY);
|
|
395
395
|
return;
|
|
396
396
|
}
|
|
@@ -409,8 +409,8 @@ var Computation = class extends Owner {
|
|
|
409
409
|
}
|
|
410
410
|
}
|
|
411
411
|
}
|
|
412
|
-
|
|
413
|
-
this.
|
|
412
|
+
M(error) {
|
|
413
|
+
this.G = error;
|
|
414
414
|
this.write(UNCHANGED, this.f & ~LOADING_BIT | ERROR_BIT | UNINITIALIZED_BIT);
|
|
415
415
|
}
|
|
416
416
|
/**
|
|
@@ -420,8 +420,8 @@ var Computation = class extends Owner {
|
|
|
420
420
|
*
|
|
421
421
|
* This function will ensure that the value and states we read from the computation are up to date
|
|
422
422
|
*/
|
|
423
|
-
|
|
424
|
-
if (!this.
|
|
423
|
+
y() {
|
|
424
|
+
if (!this.A) {
|
|
425
425
|
return;
|
|
426
426
|
}
|
|
427
427
|
if (this.a === STATE_DISPOSED) {
|
|
@@ -433,7 +433,7 @@ var Computation = class extends Owner {
|
|
|
433
433
|
let observerFlags = 0;
|
|
434
434
|
if (this.a === STATE_CHECK) {
|
|
435
435
|
for (let i = 0; i < this.c.length; i++) {
|
|
436
|
-
this.c[i].
|
|
436
|
+
this.c[i].y();
|
|
437
437
|
observerFlags |= this.c[i].f;
|
|
438
438
|
if (this.a === STATE_DIRTY) {
|
|
439
439
|
break;
|
|
@@ -450,12 +450,12 @@ var Computation = class extends Owner {
|
|
|
450
450
|
/**
|
|
451
451
|
* Remove ourselves from the owner graph and the computation graph
|
|
452
452
|
*/
|
|
453
|
-
|
|
453
|
+
z() {
|
|
454
454
|
if (this.a === STATE_DISPOSED)
|
|
455
455
|
return;
|
|
456
456
|
if (this.c)
|
|
457
457
|
removeSourceObservers(this, 0);
|
|
458
|
-
super.
|
|
458
|
+
super.z();
|
|
459
459
|
}
|
|
460
460
|
};
|
|
461
461
|
function track(computation) {
|
|
@@ -468,7 +468,7 @@ function track(computation) {
|
|
|
468
468
|
newSources.push(computation);
|
|
469
469
|
}
|
|
470
470
|
if (updateCheck) {
|
|
471
|
-
updateCheck.g = computation.
|
|
471
|
+
updateCheck.g = computation.B > currentObserver.B;
|
|
472
472
|
}
|
|
473
473
|
}
|
|
474
474
|
}
|
|
@@ -480,13 +480,13 @@ function update(node) {
|
|
|
480
480
|
try {
|
|
481
481
|
node.dispose(false);
|
|
482
482
|
node.emptyDisposal();
|
|
483
|
-
const result = compute(node, node.
|
|
483
|
+
const result = compute(node, node.A, node);
|
|
484
484
|
node.write(result, newFlags, true);
|
|
485
485
|
} catch (error) {
|
|
486
486
|
if (error instanceof NotReadyError) {
|
|
487
487
|
node.write(UNCHANGED, newFlags | LOADING_BIT | node.f & UNINITIALIZED_BIT);
|
|
488
488
|
} else {
|
|
489
|
-
node.
|
|
489
|
+
node.M(error);
|
|
490
490
|
}
|
|
491
491
|
} finally {
|
|
492
492
|
if (newSources) {
|
|
@@ -516,7 +516,7 @@ function update(node) {
|
|
|
516
516
|
newSources = prevSources;
|
|
517
517
|
newSourcesIndex = prevSourcesIndex;
|
|
518
518
|
newFlags = prevFlags;
|
|
519
|
-
node.
|
|
519
|
+
node.B = getClock() + 1;
|
|
520
520
|
node.a = STATE_CLEAN;
|
|
521
521
|
}
|
|
522
522
|
}
|
|
@@ -580,7 +580,7 @@ function isPending(fn, loadingValue) {
|
|
|
580
580
|
if (!currentObserver)
|
|
581
581
|
return pendingCheck(fn, loadingValue);
|
|
582
582
|
const c = new Computation(void 0, () => pendingCheck(fn, loadingValue));
|
|
583
|
-
c.
|
|
583
|
+
c.T |= LOADING_BIT;
|
|
584
584
|
return c.read();
|
|
585
585
|
}
|
|
586
586
|
function latest(fn, fallback) {
|
|
@@ -613,7 +613,7 @@ function runWithObserver(observer, run) {
|
|
|
613
613
|
newFlags | LOADING_BIT | observer.f & UNINITIALIZED_BIT
|
|
614
614
|
);
|
|
615
615
|
} else {
|
|
616
|
-
observer.
|
|
616
|
+
observer.M(error);
|
|
617
617
|
}
|
|
618
618
|
} finally {
|
|
619
619
|
if (newSources) {
|
|
@@ -642,7 +642,7 @@ function runWithObserver(observer, run) {
|
|
|
642
642
|
function compute(owner, fn, observer) {
|
|
643
643
|
const prevOwner = setOwner(owner), prevObserver = currentObserver, prevMask = currentMask, prevNotStale = notStale;
|
|
644
644
|
currentObserver = observer;
|
|
645
|
-
currentMask = observer?.
|
|
645
|
+
currentMask = observer?.T ?? DEFAULT_FLAGS;
|
|
646
646
|
notStale = true;
|
|
647
647
|
try {
|
|
648
648
|
return fn(observer ? observer.g : void 0);
|
|
@@ -656,23 +656,23 @@ function compute(owner, fn, observer) {
|
|
|
656
656
|
|
|
657
657
|
// src/core/effect.ts
|
|
658
658
|
var Effect = class extends Computation {
|
|
659
|
-
|
|
660
|
-
M;
|
|
661
|
-
B;
|
|
662
|
-
U = false;
|
|
659
|
+
U;
|
|
663
660
|
N;
|
|
661
|
+
C;
|
|
662
|
+
V = false;
|
|
663
|
+
O;
|
|
664
664
|
s;
|
|
665
665
|
constructor(initialValue, compute2, effect, error, options) {
|
|
666
666
|
super(initialValue, compute2, options);
|
|
667
|
-
this.
|
|
668
|
-
this.
|
|
669
|
-
this.
|
|
667
|
+
this.U = effect;
|
|
668
|
+
this.N = error;
|
|
669
|
+
this.O = initialValue;
|
|
670
670
|
this.s = options?.render ? EFFECT_RENDER : EFFECT_USER;
|
|
671
671
|
if (this.s === EFFECT_RENDER) {
|
|
672
|
-
this.
|
|
672
|
+
this.A = (p) => getClock() > this.h.created && !(this.f & ERROR_BIT) ? latest(() => compute2(p)) : compute2(p);
|
|
673
673
|
}
|
|
674
|
-
this.
|
|
675
|
-
!options?.defer && (this.s === EFFECT_USER ? this.h.enqueue(this.s, this.
|
|
674
|
+
this.y();
|
|
675
|
+
!options?.defer && (this.s === EFFECT_USER ? this.h.enqueue(this.s, this.u.bind(this)) : this.u(this.s));
|
|
676
676
|
}
|
|
677
677
|
write(value, flags = 0) {
|
|
678
678
|
if (this.a == STATE_DIRTY) {
|
|
@@ -685,25 +685,25 @@ var Effect = class extends Computation {
|
|
|
685
685
|
if (value === UNCHANGED)
|
|
686
686
|
return this.g;
|
|
687
687
|
this.g = value;
|
|
688
|
-
this.
|
|
688
|
+
this.V = true;
|
|
689
689
|
return value;
|
|
690
690
|
}
|
|
691
691
|
r(state, skipQueue) {
|
|
692
692
|
if (this.a >= state || skipQueue)
|
|
693
693
|
return;
|
|
694
694
|
if (this.a === STATE_CLEAN)
|
|
695
|
-
this.h.enqueue(this.s, this.
|
|
695
|
+
this.h.enqueue(this.s, this.u.bind(this));
|
|
696
696
|
this.a = state;
|
|
697
697
|
}
|
|
698
|
-
|
|
699
|
-
this.
|
|
698
|
+
M(error) {
|
|
699
|
+
this.G = error;
|
|
700
700
|
this.h.notify(this, LOADING_BIT, 0);
|
|
701
701
|
this.f = ERROR_BIT;
|
|
702
702
|
if (this.s === EFFECT_USER) {
|
|
703
703
|
try {
|
|
704
|
-
return this.
|
|
705
|
-
this.
|
|
706
|
-
this.
|
|
704
|
+
return this.N ? this.N(error, () => {
|
|
705
|
+
this.C?.();
|
|
706
|
+
this.C = void 0;
|
|
707
707
|
}) : console.error(error);
|
|
708
708
|
} catch (e) {
|
|
709
709
|
error = e;
|
|
@@ -712,49 +712,49 @@ var Effect = class extends Computation {
|
|
|
712
712
|
if (!this.h.notify(this, ERROR_BIT, ERROR_BIT))
|
|
713
713
|
throw error;
|
|
714
714
|
}
|
|
715
|
-
|
|
715
|
+
z() {
|
|
716
716
|
if (this.a === STATE_DISPOSED)
|
|
717
717
|
return;
|
|
718
|
-
this.
|
|
718
|
+
this.U = void 0;
|
|
719
|
+
this.O = void 0;
|
|
719
720
|
this.N = void 0;
|
|
720
|
-
this.
|
|
721
|
-
this.
|
|
722
|
-
|
|
723
|
-
super.y();
|
|
721
|
+
this.C?.();
|
|
722
|
+
this.C = void 0;
|
|
723
|
+
super.z();
|
|
724
724
|
}
|
|
725
|
-
|
|
725
|
+
u(type) {
|
|
726
726
|
if (type) {
|
|
727
|
-
if (this.
|
|
728
|
-
this.
|
|
727
|
+
if (this.V && this.a !== STATE_DISPOSED) {
|
|
728
|
+
this.C?.();
|
|
729
729
|
try {
|
|
730
|
-
this.
|
|
730
|
+
this.C = this.U(this.g, this.O);
|
|
731
731
|
} catch (e) {
|
|
732
732
|
if (!this.h.notify(this, ERROR_BIT, ERROR_BIT))
|
|
733
733
|
throw e;
|
|
734
734
|
} finally {
|
|
735
|
-
this.
|
|
736
|
-
this.
|
|
735
|
+
this.O = this.g;
|
|
736
|
+
this.V = false;
|
|
737
737
|
}
|
|
738
738
|
}
|
|
739
739
|
} else
|
|
740
740
|
this.a !== STATE_CLEAN && runTop(this);
|
|
741
741
|
}
|
|
742
742
|
};
|
|
743
|
-
function runComputation() {
|
|
744
|
-
this.a !== STATE_CLEAN && runTop(this);
|
|
745
|
-
}
|
|
746
743
|
var EagerComputation = class extends Computation {
|
|
747
744
|
constructor(initialValue, compute2, options) {
|
|
748
745
|
super(initialValue, compute2, options);
|
|
749
|
-
!options?.defer && this.
|
|
746
|
+
!options?.defer && this.y();
|
|
750
747
|
}
|
|
751
748
|
r(state, skipQueue) {
|
|
752
|
-
if (this.a >= state && !this.
|
|
749
|
+
if (this.a >= state && !this.x)
|
|
753
750
|
return;
|
|
754
|
-
if (!skipQueue && (this.a === STATE_CLEAN || this.a === STATE_CHECK && this.
|
|
755
|
-
this.h.enqueue(EFFECT_PURE,
|
|
751
|
+
if (!skipQueue && (this.a === STATE_CLEAN || this.a === STATE_CHECK && this.x))
|
|
752
|
+
this.h.enqueue(EFFECT_PURE, this.u.bind(this));
|
|
756
753
|
super.r(state, skipQueue);
|
|
757
754
|
}
|
|
755
|
+
u() {
|
|
756
|
+
this.a !== STATE_CLEAN && runTop(this);
|
|
757
|
+
}
|
|
758
758
|
};
|
|
759
759
|
var FirewallComputation = class extends Computation {
|
|
760
760
|
firewall = true;
|
|
@@ -762,12 +762,15 @@ var FirewallComputation = class extends Computation {
|
|
|
762
762
|
super(void 0, compute2);
|
|
763
763
|
}
|
|
764
764
|
r(state, skipQueue) {
|
|
765
|
-
if (this.a >= state && !this.
|
|
765
|
+
if (this.a >= state && !this.x)
|
|
766
766
|
return;
|
|
767
|
-
if (!skipQueue && (this.a === STATE_CLEAN || this.a === STATE_CHECK && this.
|
|
768
|
-
this.h.enqueue(EFFECT_PURE,
|
|
767
|
+
if (!skipQueue && (this.a === STATE_CLEAN || this.a === STATE_CHECK && this.x))
|
|
768
|
+
this.h.enqueue(EFFECT_PURE, this.u.bind(this));
|
|
769
769
|
super.r(state, true);
|
|
770
|
-
this.
|
|
770
|
+
this.x = !!skipQueue;
|
|
771
|
+
}
|
|
772
|
+
u() {
|
|
773
|
+
this.a !== STATE_CLEAN && runTop(this);
|
|
771
774
|
}
|
|
772
775
|
};
|
|
773
776
|
function runTop(node) {
|
|
@@ -779,7 +782,7 @@ function runTop(node) {
|
|
|
779
782
|
}
|
|
780
783
|
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
781
784
|
if (ancestors[i].a !== STATE_DISPOSED)
|
|
782
|
-
ancestors[i].
|
|
785
|
+
ancestors[i].y();
|
|
783
786
|
}
|
|
784
787
|
}
|
|
785
788
|
|
|
@@ -851,7 +854,7 @@ function createAsync(compute2, value, options) {
|
|
|
851
854
|
(error) => {
|
|
852
855
|
if (abort)
|
|
853
856
|
return;
|
|
854
|
-
node.
|
|
857
|
+
node.M(error);
|
|
855
858
|
}
|
|
856
859
|
);
|
|
857
860
|
} else {
|
|
@@ -877,7 +880,7 @@ function createAsync(compute2, value, options) {
|
|
|
877
880
|
read.refresh = () => {
|
|
878
881
|
node.a = STATE_DIRTY;
|
|
879
882
|
refreshing = true;
|
|
880
|
-
node.
|
|
883
|
+
node.y();
|
|
881
884
|
};
|
|
882
885
|
return read;
|
|
883
886
|
}
|
|
@@ -1578,53 +1581,53 @@ function omit(props, ...keys) {
|
|
|
1578
1581
|
function mapArray(list, map, options) {
|
|
1579
1582
|
const keyFn = typeof options?.keyed === "function" ? options.keyed : void 0;
|
|
1580
1583
|
return updateKeyedMap.bind({
|
|
1581
|
-
|
|
1584
|
+
H: new Owner(),
|
|
1582
1585
|
i: 0,
|
|
1583
1586
|
$: list,
|
|
1584
|
-
|
|
1585
|
-
|
|
1587
|
+
w: [],
|
|
1588
|
+
D: map,
|
|
1586
1589
|
e: [],
|
|
1587
1590
|
b: [],
|
|
1588
|
-
|
|
1591
|
+
E: keyFn,
|
|
1589
1592
|
j: keyFn || options?.keyed === false ? [] : void 0,
|
|
1590
1593
|
k: map.length > 1 ? [] : void 0,
|
|
1591
|
-
|
|
1594
|
+
I: options?.fallback
|
|
1592
1595
|
});
|
|
1593
1596
|
}
|
|
1594
1597
|
var pureOptions = { pureWrite: true };
|
|
1595
1598
|
function updateKeyedMap() {
|
|
1596
1599
|
const newItems = this.$() || [], newLen = newItems.length;
|
|
1597
1600
|
newItems[$TRACK];
|
|
1598
|
-
runWithOwner(this.
|
|
1601
|
+
runWithOwner(this.H, () => {
|
|
1599
1602
|
let i, j, mapper = this.j ? () => {
|
|
1600
1603
|
this.j[j] = new Computation(newItems[j], null, pureOptions);
|
|
1601
1604
|
this.k && (this.k[j] = new Computation(j, null, pureOptions));
|
|
1602
|
-
return this.
|
|
1605
|
+
return this.D(
|
|
1603
1606
|
Computation.prototype.read.bind(this.j[j]),
|
|
1604
1607
|
this.k ? Computation.prototype.read.bind(this.k[j]) : void 0
|
|
1605
1608
|
);
|
|
1606
1609
|
} : this.k ? () => {
|
|
1607
1610
|
const item = newItems[j];
|
|
1608
1611
|
this.k[j] = new Computation(j, null, pureOptions);
|
|
1609
|
-
return this.
|
|
1612
|
+
return this.D(() => item, Computation.prototype.read.bind(this.k[j]));
|
|
1610
1613
|
} : () => {
|
|
1611
1614
|
const item = newItems[j];
|
|
1612
|
-
return this.
|
|
1615
|
+
return this.D(() => item);
|
|
1613
1616
|
};
|
|
1614
1617
|
if (newLen === 0) {
|
|
1615
1618
|
if (this.i !== 0) {
|
|
1616
|
-
this.
|
|
1619
|
+
this.H.dispose(false);
|
|
1617
1620
|
this.b = [];
|
|
1618
|
-
this.
|
|
1621
|
+
this.w = [];
|
|
1619
1622
|
this.e = [];
|
|
1620
1623
|
this.i = 0;
|
|
1621
1624
|
this.j && (this.j = []);
|
|
1622
1625
|
this.k && (this.k = []);
|
|
1623
1626
|
}
|
|
1624
|
-
if (this.
|
|
1627
|
+
if (this.I && !this.e[0]) {
|
|
1625
1628
|
this.e[0] = compute(
|
|
1626
1629
|
this.b[0] = new Owner(),
|
|
1627
|
-
this.
|
|
1630
|
+
this.I,
|
|
1628
1631
|
null
|
|
1629
1632
|
);
|
|
1630
1633
|
}
|
|
@@ -1633,17 +1636,17 @@ function updateKeyedMap() {
|
|
|
1633
1636
|
this.b[0].dispose();
|
|
1634
1637
|
this.e = new Array(newLen);
|
|
1635
1638
|
for (j = 0; j < newLen; j++) {
|
|
1636
|
-
this.
|
|
1639
|
+
this.w[j] = newItems[j];
|
|
1637
1640
|
this.e[j] = compute(this.b[j] = new Owner(), mapper, null);
|
|
1638
1641
|
}
|
|
1639
1642
|
this.i = newLen;
|
|
1640
1643
|
} else {
|
|
1641
1644
|
let start, end, newEnd, item, key, newIndices, newIndicesNext, temp = new Array(newLen), tempNodes = new Array(newLen), tempRows = this.j ? new Array(newLen) : void 0, tempIndexes = this.k ? new Array(newLen) : void 0;
|
|
1642
|
-
for (start = 0, end = Math.min(this.i, newLen); start < end && (this.
|
|
1645
|
+
for (start = 0, end = Math.min(this.i, newLen); start < end && (this.w[start] === newItems[start] || this.j && compare(this.E, this.w[start], newItems[start])); start++) {
|
|
1643
1646
|
if (this.j)
|
|
1644
1647
|
this.j[start].write(newItems[start]);
|
|
1645
1648
|
}
|
|
1646
|
-
for (end = this.i - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.
|
|
1649
|
+
for (end = this.i - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.w[end] === newItems[newEnd] || this.j && compare(this.E, this.w[end], newItems[newEnd])); end--, newEnd--) {
|
|
1647
1650
|
temp[newEnd] = this.e[end];
|
|
1648
1651
|
tempNodes[newEnd] = this.b[end];
|
|
1649
1652
|
tempRows && (tempRows[newEnd] = this.j[end]);
|
|
@@ -1653,14 +1656,14 @@ function updateKeyedMap() {
|
|
|
1653
1656
|
newIndicesNext = new Array(newEnd + 1);
|
|
1654
1657
|
for (j = newEnd; j >= start; j--) {
|
|
1655
1658
|
item = newItems[j];
|
|
1656
|
-
key = this.
|
|
1659
|
+
key = this.E ? this.E(item) : item;
|
|
1657
1660
|
i = newIndices.get(key);
|
|
1658
1661
|
newIndicesNext[j] = i === void 0 ? -1 : i;
|
|
1659
1662
|
newIndices.set(key, j);
|
|
1660
1663
|
}
|
|
1661
1664
|
for (i = start; i <= end; i++) {
|
|
1662
|
-
item = this.
|
|
1663
|
-
key = this.
|
|
1665
|
+
item = this.w[i];
|
|
1666
|
+
key = this.E ? this.E(item) : item;
|
|
1664
1667
|
j = newIndices.get(key);
|
|
1665
1668
|
if (j !== void 0 && j !== -1) {
|
|
1666
1669
|
temp[j] = this.e[i];
|
|
@@ -1689,39 +1692,39 @@ function updateKeyedMap() {
|
|
|
1689
1692
|
}
|
|
1690
1693
|
}
|
|
1691
1694
|
this.e = this.e.slice(0, this.i = newLen);
|
|
1692
|
-
this.
|
|
1695
|
+
this.w = newItems.slice(0);
|
|
1693
1696
|
}
|
|
1694
1697
|
});
|
|
1695
1698
|
return this.e;
|
|
1696
1699
|
}
|
|
1697
1700
|
function repeat(count, map, options) {
|
|
1698
1701
|
return updateRepeat.bind({
|
|
1699
|
-
|
|
1702
|
+
H: new Owner(),
|
|
1700
1703
|
i: 0,
|
|
1701
1704
|
q: 0,
|
|
1702
1705
|
aa: count,
|
|
1703
|
-
|
|
1706
|
+
D: map,
|
|
1704
1707
|
b: [],
|
|
1705
1708
|
e: [],
|
|
1706
1709
|
ba: options?.from,
|
|
1707
|
-
|
|
1710
|
+
I: options?.fallback
|
|
1708
1711
|
});
|
|
1709
1712
|
}
|
|
1710
1713
|
function updateRepeat() {
|
|
1711
1714
|
const newLen = this.aa();
|
|
1712
1715
|
const from = this.ba?.() || 0;
|
|
1713
|
-
runWithOwner(this.
|
|
1716
|
+
runWithOwner(this.H, () => {
|
|
1714
1717
|
if (newLen === 0) {
|
|
1715
1718
|
if (this.i !== 0) {
|
|
1716
|
-
this.
|
|
1719
|
+
this.H.dispose(false);
|
|
1717
1720
|
this.b = [];
|
|
1718
1721
|
this.e = [];
|
|
1719
1722
|
this.i = 0;
|
|
1720
1723
|
}
|
|
1721
|
-
if (this.
|
|
1724
|
+
if (this.I && !this.e[0]) {
|
|
1722
1725
|
this.e[0] = compute(
|
|
1723
1726
|
this.b[0] = new Owner(),
|
|
1724
|
-
this.
|
|
1727
|
+
this.I,
|
|
1725
1728
|
null
|
|
1726
1729
|
);
|
|
1727
1730
|
}
|
|
@@ -1751,7 +1754,7 @@ function updateRepeat() {
|
|
|
1751
1754
|
for (let i2 = 0; i2 < difference; i2++) {
|
|
1752
1755
|
this.e[i2] = compute(
|
|
1753
1756
|
this.b[i2] = new Owner(),
|
|
1754
|
-
() => this.
|
|
1757
|
+
() => this.D(i2 + from),
|
|
1755
1758
|
null
|
|
1756
1759
|
);
|
|
1757
1760
|
}
|
|
@@ -1759,7 +1762,7 @@ function updateRepeat() {
|
|
|
1759
1762
|
for (let i = prevTo; i < to; i++) {
|
|
1760
1763
|
this.e[i - from] = compute(
|
|
1761
1764
|
this.b[i - from] = new Owner(),
|
|
1762
|
-
() => this.
|
|
1765
|
+
() => this.D(i),
|
|
1763
1766
|
null
|
|
1764
1767
|
);
|
|
1765
1768
|
}
|
|
@@ -1775,17 +1778,17 @@ function compare(key, a, b) {
|
|
|
1775
1778
|
|
|
1776
1779
|
// src/boundaries.ts
|
|
1777
1780
|
var BoundaryComputation = class extends EagerComputation {
|
|
1778
|
-
|
|
1781
|
+
J;
|
|
1779
1782
|
constructor(compute2, propagationMask) {
|
|
1780
1783
|
super(void 0, compute2, { defer: true });
|
|
1781
|
-
this.
|
|
1784
|
+
this.J = propagationMask;
|
|
1782
1785
|
}
|
|
1783
1786
|
write(value, flags) {
|
|
1784
|
-
super.write(value, flags & ~this.
|
|
1785
|
-
if (this.
|
|
1787
|
+
super.write(value, flags & ~this.J);
|
|
1788
|
+
if (this.J & LOADING_BIT && !(this.f & UNINITIALIZED_BIT)) {
|
|
1786
1789
|
flags &= ~LOADING_BIT;
|
|
1787
1790
|
}
|
|
1788
|
-
this.h.notify(this, this.
|
|
1791
|
+
this.h.notify(this, this.J, flags);
|
|
1789
1792
|
return this.g;
|
|
1790
1793
|
}
|
|
1791
1794
|
};
|
|
@@ -1804,8 +1807,8 @@ function createBoundChildren(owner, fn, queue, mask) {
|
|
|
1804
1807
|
}
|
|
1805
1808
|
var ConditionalQueue = class extends Queue {
|
|
1806
1809
|
n;
|
|
1807
|
-
O = /* @__PURE__ */ new Set();
|
|
1808
1810
|
P = /* @__PURE__ */ new Set();
|
|
1811
|
+
Q = /* @__PURE__ */ new Set();
|
|
1809
1812
|
constructor(disabled) {
|
|
1810
1813
|
super();
|
|
1811
1814
|
this.n = disabled;
|
|
@@ -1819,16 +1822,16 @@ var ConditionalQueue = class extends Queue {
|
|
|
1819
1822
|
if (this.n.read()) {
|
|
1820
1823
|
if (type & LOADING_BIT) {
|
|
1821
1824
|
if (flags & LOADING_BIT) {
|
|
1822
|
-
this.
|
|
1825
|
+
this.Q.add(node);
|
|
1823
1826
|
type &= ~LOADING_BIT;
|
|
1824
|
-
} else if (this.
|
|
1827
|
+
} else if (this.Q.delete(node))
|
|
1825
1828
|
type &= ~LOADING_BIT;
|
|
1826
1829
|
}
|
|
1827
1830
|
if (type & ERROR_BIT) {
|
|
1828
1831
|
if (flags & ERROR_BIT) {
|
|
1829
|
-
this.
|
|
1832
|
+
this.P.add(node);
|
|
1830
1833
|
type &= ~ERROR_BIT;
|
|
1831
|
-
} else if (this.
|
|
1834
|
+
} else if (this.P.delete(node))
|
|
1832
1835
|
type &= ~ERROR_BIT;
|
|
1833
1836
|
}
|
|
1834
1837
|
}
|
|
@@ -1836,12 +1839,12 @@ var ConditionalQueue = class extends Queue {
|
|
|
1836
1839
|
}
|
|
1837
1840
|
};
|
|
1838
1841
|
var CollectionQueue = class extends Queue {
|
|
1839
|
-
|
|
1842
|
+
R;
|
|
1840
1843
|
b = /* @__PURE__ */ new Set();
|
|
1841
1844
|
n = new Computation(false, null, { pureWrite: true });
|
|
1842
1845
|
constructor(type) {
|
|
1843
1846
|
super();
|
|
1844
|
-
this.
|
|
1847
|
+
this.R = type;
|
|
1845
1848
|
}
|
|
1846
1849
|
run(type) {
|
|
1847
1850
|
if (!type || this.n.read())
|
|
@@ -1849,9 +1852,9 @@ var CollectionQueue = class extends Queue {
|
|
|
1849
1852
|
return super.run(type);
|
|
1850
1853
|
}
|
|
1851
1854
|
notify(node, type, flags) {
|
|
1852
|
-
if (!(type & this.
|
|
1855
|
+
if (!(type & this.R))
|
|
1853
1856
|
return super.notify(node, type, flags);
|
|
1854
|
-
if (flags & this.
|
|
1857
|
+
if (flags & this.R) {
|
|
1855
1858
|
this.b.add(node);
|
|
1856
1859
|
if (this.b.size === 1)
|
|
1857
1860
|
this.n.write(true);
|
|
@@ -1860,7 +1863,7 @@ var CollectionQueue = class extends Queue {
|
|
|
1860
1863
|
if (this.b.size === 0)
|
|
1861
1864
|
this.n.write(false);
|
|
1862
1865
|
}
|
|
1863
|
-
type &= ~this.
|
|
1866
|
+
type &= ~this.R;
|
|
1864
1867
|
return type ? super.notify(node, type, flags) : true;
|
|
1865
1868
|
}
|
|
1866
1869
|
};
|
|
@@ -1872,12 +1875,12 @@ function createBoundary(fn, condition) {
|
|
|
1872
1875
|
const tree = createBoundChildren(owner, fn, queue, 0);
|
|
1873
1876
|
new EagerComputation(void 0, () => {
|
|
1874
1877
|
const disabled = queue.n.read();
|
|
1875
|
-
tree.
|
|
1878
|
+
tree.J = disabled ? ERROR_BIT | LOADING_BIT : 0;
|
|
1876
1879
|
if (!disabled) {
|
|
1877
|
-
queue.
|
|
1878
|
-
queue.
|
|
1880
|
+
queue.Q.forEach((node) => queue.notify(node, LOADING_BIT, LOADING_BIT));
|
|
1881
|
+
queue.P.forEach((node) => queue.notify(node, ERROR_BIT, ERROR_BIT));
|
|
1882
|
+
queue.Q.clear();
|
|
1879
1883
|
queue.P.clear();
|
|
1880
|
-
queue.O.clear();
|
|
1881
1884
|
}
|
|
1882
1885
|
});
|
|
1883
1886
|
return () => queue.n.read() ? void 0 : tree.read();
|
|
@@ -1903,11 +1906,11 @@ function createErrorBoundary(fn, fallback) {
|
|
|
1903
1906
|
return createCollectionBoundary(
|
|
1904
1907
|
ERROR_BIT,
|
|
1905
1908
|
fn,
|
|
1906
|
-
(queue) => fallback(queue.b.values().next().value.
|
|
1909
|
+
(queue) => fallback(queue.b.values().next().value.G, () => {
|
|
1907
1910
|
incrementClock();
|
|
1908
1911
|
for (let node of queue.b) {
|
|
1909
1912
|
node.a = STATE_DIRTY;
|
|
1910
|
-
node.h?.enqueue(node.s, node);
|
|
1913
|
+
node.h?.enqueue(node.s, node.u.bind(node));
|
|
1911
1914
|
}
|
|
1912
1915
|
})
|
|
1913
1916
|
);
|