@solidjs/signals 0.1.0 → 0.2.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/dist/dev.js +43 -28
- package/dist/node.cjs +204 -189
- package/dist/prod.js +204 -189
- package/dist/types/core/core.d.ts +7 -1
- package/dist/types/core/index.d.ts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/signals.d.ts +5 -18
- package/package.json +1 -1
package/dist/node.cjs
CHANGED
|
@@ -45,11 +45,11 @@ function schedule() {
|
|
|
45
45
|
if (scheduled)
|
|
46
46
|
return;
|
|
47
47
|
scheduled = true;
|
|
48
|
-
if (!globalQueue.
|
|
48
|
+
if (!globalQueue.I)
|
|
49
49
|
queueMicrotask(flushSync);
|
|
50
50
|
}
|
|
51
51
|
var Queue = class {
|
|
52
|
-
|
|
52
|
+
I = false;
|
|
53
53
|
r = [[], [], []];
|
|
54
54
|
D = [];
|
|
55
55
|
created = clock;
|
|
@@ -78,9 +78,9 @@ var Queue = class {
|
|
|
78
78
|
return true;
|
|
79
79
|
}
|
|
80
80
|
flush() {
|
|
81
|
-
if (this.
|
|
81
|
+
if (this.I)
|
|
82
82
|
return;
|
|
83
|
-
this.
|
|
83
|
+
this.I = true;
|
|
84
84
|
try {
|
|
85
85
|
while (this.run(EFFECT_PURE)) {
|
|
86
86
|
}
|
|
@@ -89,7 +89,7 @@ var Queue = class {
|
|
|
89
89
|
this.run(EFFECT_RENDER);
|
|
90
90
|
this.run(EFFECT_USER);
|
|
91
91
|
} finally {
|
|
92
|
-
this.
|
|
92
|
+
this.I = false;
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
addChild(child) {
|
|
@@ -238,19 +238,19 @@ var Owner = class {
|
|
|
238
238
|
let head = self ? this.t || this.s : this, current = this.n, next = null;
|
|
239
239
|
while (current && current.s === this) {
|
|
240
240
|
current.dispose(true);
|
|
241
|
-
current.
|
|
241
|
+
current.z();
|
|
242
242
|
next = current.n;
|
|
243
243
|
current.n = null;
|
|
244
244
|
current = next;
|
|
245
245
|
}
|
|
246
246
|
if (self)
|
|
247
|
-
this.
|
|
247
|
+
this.z();
|
|
248
248
|
if (current)
|
|
249
249
|
current.t = !self ? this : this.t;
|
|
250
250
|
if (head)
|
|
251
251
|
head.n = current;
|
|
252
252
|
}
|
|
253
|
-
|
|
253
|
+
z() {
|
|
254
254
|
if (this.t)
|
|
255
255
|
this.t.n = null;
|
|
256
256
|
this.s = null;
|
|
@@ -351,11 +351,11 @@ function getObserver() {
|
|
|
351
351
|
}
|
|
352
352
|
var UNCHANGED = Symbol(0);
|
|
353
353
|
var Computation = class extends Owner {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
354
|
+
b = null;
|
|
355
|
+
c = null;
|
|
356
|
+
e;
|
|
357
357
|
E;
|
|
358
|
-
|
|
358
|
+
A;
|
|
359
359
|
// Used in __DEV__ mode, hopefully removed in production
|
|
360
360
|
Z;
|
|
361
361
|
// Using false is an optimization as an alternative to _equals: () => false
|
|
@@ -363,18 +363,18 @@ var Computation = class extends Owner {
|
|
|
363
363
|
N = isEqual;
|
|
364
364
|
U;
|
|
365
365
|
/** Whether the computation is an error or has ancestors that are unresolved */
|
|
366
|
-
|
|
366
|
+
d = 0;
|
|
367
367
|
/** Which flags raised by sources are handled, vs. being passed through. */
|
|
368
368
|
O = DEFAULT_FLAGS;
|
|
369
369
|
P = null;
|
|
370
|
-
|
|
371
|
-
|
|
370
|
+
x = -1;
|
|
371
|
+
J = false;
|
|
372
372
|
constructor(initialValue, compute2, options) {
|
|
373
373
|
super(compute2 === null);
|
|
374
|
-
this.
|
|
374
|
+
this.A = compute2;
|
|
375
375
|
this.a = compute2 ? STATE_DIRTY : STATE_CLEAN;
|
|
376
|
-
this.
|
|
377
|
-
this.
|
|
376
|
+
this.d = compute2 && initialValue === void 0 ? UNINITIALIZED_BIT : 0;
|
|
377
|
+
this.e = initialValue;
|
|
378
378
|
if ((options == null ? void 0 : options.equals) !== void 0)
|
|
379
379
|
this.N = options.equals;
|
|
380
380
|
if (options == null ? void 0 : options.unobserved)
|
|
@@ -382,19 +382,19 @@ var Computation = class extends Owner {
|
|
|
382
382
|
}
|
|
383
383
|
V() {
|
|
384
384
|
var _a;
|
|
385
|
-
if (this.
|
|
386
|
-
if (this.
|
|
385
|
+
if (this.A) {
|
|
386
|
+
if (this.d & ERROR_BIT && this.x <= getClock())
|
|
387
387
|
update(this);
|
|
388
388
|
else
|
|
389
389
|
this.y();
|
|
390
390
|
}
|
|
391
|
-
if (!this.
|
|
391
|
+
if (!this.A || ((_a = this.b) == null ? void 0 : _a.length))
|
|
392
392
|
track(this);
|
|
393
|
-
newFlags |= this.
|
|
394
|
-
if (this.
|
|
393
|
+
newFlags |= this.d & ~currentMask;
|
|
394
|
+
if (this.d & ERROR_BIT) {
|
|
395
395
|
throw this.E;
|
|
396
396
|
} else {
|
|
397
|
-
return this.
|
|
397
|
+
return this.e;
|
|
398
398
|
}
|
|
399
399
|
}
|
|
400
400
|
/**
|
|
@@ -412,14 +412,14 @@ var Computation = class extends Owner {
|
|
|
412
412
|
* before continuing
|
|
413
413
|
*/
|
|
414
414
|
wait() {
|
|
415
|
-
if (this.
|
|
415
|
+
if (this.A && this.d & ERROR_BIT && this.x <= getClock()) {
|
|
416
416
|
update(this);
|
|
417
417
|
}
|
|
418
|
-
if ((notStale || this.
|
|
418
|
+
if ((notStale || this.d & UNINITIALIZED_BIT) && this.loading()) {
|
|
419
419
|
throw new NotReadyError();
|
|
420
420
|
}
|
|
421
421
|
if (staleCheck && this.loading())
|
|
422
|
-
staleCheck.
|
|
422
|
+
staleCheck.e = true;
|
|
423
423
|
return this.V();
|
|
424
424
|
}
|
|
425
425
|
/**
|
|
@@ -437,37 +437,37 @@ var Computation = class extends Owner {
|
|
|
437
437
|
}
|
|
438
438
|
/** Update the computation with a new value. */
|
|
439
439
|
write(value, flags = 0, raw = false) {
|
|
440
|
-
const newValue = !raw && typeof value === "function" ? value(this.
|
|
441
|
-
const valueChanged = newValue !== UNCHANGED && (!!(this.
|
|
440
|
+
const newValue = !raw && typeof value === "function" ? value(this.e) : value;
|
|
441
|
+
const valueChanged = newValue !== UNCHANGED && (!!(this.d & UNINITIALIZED_BIT) || this.N === false || !this.N(this.e, newValue));
|
|
442
442
|
if (valueChanged) {
|
|
443
|
-
this.
|
|
443
|
+
this.e = newValue;
|
|
444
444
|
this.E = void 0;
|
|
445
445
|
}
|
|
446
|
-
const changedFlagsMask = this.
|
|
447
|
-
this.
|
|
448
|
-
this.
|
|
449
|
-
if (this.
|
|
450
|
-
for (let i = 0; i < this.
|
|
446
|
+
const changedFlagsMask = this.d ^ flags, changedFlags = changedFlagsMask & flags;
|
|
447
|
+
this.d = flags;
|
|
448
|
+
this.x = getClock() + 1;
|
|
449
|
+
if (this.c) {
|
|
450
|
+
for (let i = 0; i < this.c.length; i++) {
|
|
451
451
|
if (valueChanged) {
|
|
452
|
-
this.
|
|
452
|
+
this.c[i].q(STATE_DIRTY);
|
|
453
453
|
} else if (changedFlagsMask) {
|
|
454
|
-
this.
|
|
454
|
+
this.c[i].W(changedFlagsMask, changedFlags);
|
|
455
455
|
}
|
|
456
456
|
}
|
|
457
457
|
}
|
|
458
|
-
return this.
|
|
458
|
+
return this.e;
|
|
459
459
|
}
|
|
460
460
|
/**
|
|
461
461
|
* Set the current node's state, and recursively mark all of this node's observers as STATE_CHECK
|
|
462
462
|
*/
|
|
463
463
|
q(state, skipQueue) {
|
|
464
|
-
if (this.a >= state && !this.
|
|
464
|
+
if (this.a >= state && !this.J)
|
|
465
465
|
return;
|
|
466
|
-
this.
|
|
466
|
+
this.J = !!skipQueue;
|
|
467
467
|
this.a = state;
|
|
468
|
-
if (this.
|
|
469
|
-
for (let i = 0; i < this.
|
|
470
|
-
this.
|
|
468
|
+
if (this.c) {
|
|
469
|
+
for (let i = 0; i < this.c.length; i++) {
|
|
470
|
+
this.c[i].q(STATE_CHECK, skipQueue);
|
|
471
471
|
}
|
|
472
472
|
}
|
|
473
473
|
}
|
|
@@ -486,22 +486,22 @@ var Computation = class extends Owner {
|
|
|
486
486
|
}
|
|
487
487
|
if (this.a >= STATE_CHECK)
|
|
488
488
|
return;
|
|
489
|
-
const prevFlags = this.
|
|
489
|
+
const prevFlags = this.d & mask;
|
|
490
490
|
const deltaFlags = prevFlags ^ newFlags2;
|
|
491
491
|
if (newFlags2 === prevFlags) ; else if (deltaFlags & prevFlags & mask) {
|
|
492
492
|
this.q(STATE_CHECK);
|
|
493
493
|
} else {
|
|
494
|
-
this.
|
|
495
|
-
if (this.
|
|
496
|
-
for (let i = 0; i < this.
|
|
497
|
-
this.
|
|
494
|
+
this.d ^= deltaFlags;
|
|
495
|
+
if (this.c) {
|
|
496
|
+
for (let i = 0; i < this.c.length; i++) {
|
|
497
|
+
this.c[i].W(mask, newFlags2);
|
|
498
498
|
}
|
|
499
499
|
}
|
|
500
500
|
}
|
|
501
501
|
}
|
|
502
|
-
|
|
502
|
+
F(error) {
|
|
503
503
|
this.E = error;
|
|
504
|
-
this.write(UNCHANGED, this.
|
|
504
|
+
this.write(UNCHANGED, this.d & ~LOADING_BIT | ERROR_BIT | UNINITIALIZED_BIT);
|
|
505
505
|
}
|
|
506
506
|
/**
|
|
507
507
|
* This is the core part of the reactivity system, which makes sure that the values are updated
|
|
@@ -519,9 +519,9 @@ var Computation = class extends Owner {
|
|
|
519
519
|
}
|
|
520
520
|
let observerFlags = 0;
|
|
521
521
|
if (this.a === STATE_CHECK) {
|
|
522
|
-
for (let i = 0; i < this.
|
|
523
|
-
this.
|
|
524
|
-
observerFlags |= this.
|
|
522
|
+
for (let i = 0; i < this.b.length; i++) {
|
|
523
|
+
this.b[i].y();
|
|
524
|
+
observerFlags |= this.b[i].d;
|
|
525
525
|
if (this.a === STATE_DIRTY) {
|
|
526
526
|
break;
|
|
527
527
|
}
|
|
@@ -537,12 +537,12 @@ var Computation = class extends Owner {
|
|
|
537
537
|
/**
|
|
538
538
|
* Remove ourselves from the owner graph and the computation graph
|
|
539
539
|
*/
|
|
540
|
-
|
|
540
|
+
z() {
|
|
541
541
|
if (this.a === STATE_DISPOSED)
|
|
542
542
|
return;
|
|
543
|
-
if (this.
|
|
543
|
+
if (this.b)
|
|
544
544
|
removeSourceObservers(this, 0);
|
|
545
|
-
super.
|
|
545
|
+
super.z();
|
|
546
546
|
}
|
|
547
547
|
};
|
|
548
548
|
function loadingState(node) {
|
|
@@ -553,7 +553,7 @@ function loadingState(node) {
|
|
|
553
553
|
() => {
|
|
554
554
|
track(node);
|
|
555
555
|
node.y();
|
|
556
|
-
return !!(node.
|
|
556
|
+
return !!(node.d & LOADING_BIT);
|
|
557
557
|
},
|
|
558
558
|
options
|
|
559
559
|
);
|
|
@@ -563,7 +563,7 @@ function loadingState(node) {
|
|
|
563
563
|
}
|
|
564
564
|
function track(computation) {
|
|
565
565
|
if (currentObserver) {
|
|
566
|
-
if (!newSources && currentObserver.
|
|
566
|
+
if (!newSources && currentObserver.b && currentObserver.b[newSourcesIndex] === computation) {
|
|
567
567
|
newSourcesIndex++;
|
|
568
568
|
} else if (!newSources)
|
|
569
569
|
newSources = [computation];
|
|
@@ -571,7 +571,7 @@ function track(computation) {
|
|
|
571
571
|
newSources.push(computation);
|
|
572
572
|
}
|
|
573
573
|
if (updateCheck) {
|
|
574
|
-
updateCheck.
|
|
574
|
+
updateCheck.e = computation.x > currentObserver.x;
|
|
575
575
|
}
|
|
576
576
|
}
|
|
577
577
|
}
|
|
@@ -583,42 +583,42 @@ function update(node) {
|
|
|
583
583
|
try {
|
|
584
584
|
node.dispose(false);
|
|
585
585
|
node.emptyDisposal();
|
|
586
|
-
const result = compute(node, node.
|
|
586
|
+
const result = compute(node, node.A, node);
|
|
587
587
|
node.write(result, newFlags, true);
|
|
588
588
|
} catch (error) {
|
|
589
589
|
if (error instanceof NotReadyError) {
|
|
590
|
-
node.write(UNCHANGED, newFlags | LOADING_BIT | node.
|
|
590
|
+
node.write(UNCHANGED, newFlags | LOADING_BIT | node.d & UNINITIALIZED_BIT);
|
|
591
591
|
} else {
|
|
592
|
-
node.
|
|
592
|
+
node.F(error);
|
|
593
593
|
}
|
|
594
594
|
} finally {
|
|
595
595
|
if (newSources) {
|
|
596
|
-
if (node.
|
|
596
|
+
if (node.b)
|
|
597
597
|
removeSourceObservers(node, newSourcesIndex);
|
|
598
|
-
if (node.
|
|
599
|
-
node.
|
|
598
|
+
if (node.b && newSourcesIndex > 0) {
|
|
599
|
+
node.b.length = newSourcesIndex + newSources.length;
|
|
600
600
|
for (let i = 0; i < newSources.length; i++) {
|
|
601
|
-
node.
|
|
601
|
+
node.b[newSourcesIndex + i] = newSources[i];
|
|
602
602
|
}
|
|
603
603
|
} else {
|
|
604
|
-
node.
|
|
604
|
+
node.b = newSources;
|
|
605
605
|
}
|
|
606
606
|
let source;
|
|
607
|
-
for (let i = newSourcesIndex; i < node.
|
|
608
|
-
source = node.
|
|
609
|
-
if (!source.
|
|
610
|
-
source.
|
|
607
|
+
for (let i = newSourcesIndex; i < node.b.length; i++) {
|
|
608
|
+
source = node.b[i];
|
|
609
|
+
if (!source.c)
|
|
610
|
+
source.c = [node];
|
|
611
611
|
else
|
|
612
|
-
source.
|
|
612
|
+
source.c.push(node);
|
|
613
613
|
}
|
|
614
|
-
} else if (node.
|
|
614
|
+
} else if (node.b && newSourcesIndex < node.b.length) {
|
|
615
615
|
removeSourceObservers(node, newSourcesIndex);
|
|
616
|
-
node.
|
|
616
|
+
node.b.length = newSourcesIndex;
|
|
617
617
|
}
|
|
618
618
|
newSources = prevSources;
|
|
619
619
|
newSourcesIndex = prevSourcesIndex;
|
|
620
620
|
newFlags = prevFlags;
|
|
621
|
-
node.
|
|
621
|
+
node.x = getClock() + 1;
|
|
622
622
|
node.a = STATE_CLEAN;
|
|
623
623
|
}
|
|
624
624
|
}
|
|
@@ -626,13 +626,13 @@ function removeSourceObservers(node, index) {
|
|
|
626
626
|
var _a;
|
|
627
627
|
let source;
|
|
628
628
|
let swap;
|
|
629
|
-
for (let i = index; i < node.
|
|
630
|
-
source = node.
|
|
631
|
-
if (source.
|
|
632
|
-
swap = source.
|
|
633
|
-
source.
|
|
634
|
-
source.
|
|
635
|
-
if (!source.
|
|
629
|
+
for (let i = index; i < node.b.length; i++) {
|
|
630
|
+
source = node.b[i];
|
|
631
|
+
if (source.c) {
|
|
632
|
+
swap = source.c.indexOf(node);
|
|
633
|
+
source.c[swap] = source.c[source.c.length - 1];
|
|
634
|
+
source.c.pop();
|
|
635
|
+
if (!source.c.length)
|
|
636
636
|
(_a = source.U) == null ? void 0 : _a.call(source);
|
|
637
637
|
}
|
|
638
638
|
}
|
|
@@ -647,25 +647,23 @@ function untrack(fn) {
|
|
|
647
647
|
}
|
|
648
648
|
function hasUpdated(fn) {
|
|
649
649
|
const current = updateCheck;
|
|
650
|
-
updateCheck = {
|
|
650
|
+
updateCheck = { e: false };
|
|
651
651
|
try {
|
|
652
652
|
fn();
|
|
653
|
-
return updateCheck.
|
|
653
|
+
return updateCheck.e;
|
|
654
654
|
} finally {
|
|
655
655
|
updateCheck = current;
|
|
656
656
|
}
|
|
657
657
|
}
|
|
658
658
|
function isStale(fn) {
|
|
659
659
|
const current = staleCheck;
|
|
660
|
-
staleCheck = {
|
|
660
|
+
staleCheck = { e: false };
|
|
661
661
|
try {
|
|
662
662
|
latest(fn);
|
|
663
|
-
return staleCheck.
|
|
664
|
-
} catch {
|
|
663
|
+
return staleCheck.e;
|
|
665
664
|
} finally {
|
|
666
665
|
staleCheck = current;
|
|
667
666
|
}
|
|
668
|
-
return false;
|
|
669
667
|
}
|
|
670
668
|
function latest(fn) {
|
|
671
669
|
const prevFlags = newFlags;
|
|
@@ -687,13 +685,50 @@ function catchError(fn) {
|
|
|
687
685
|
return e;
|
|
688
686
|
}
|
|
689
687
|
}
|
|
688
|
+
function runWithObserver(observer, run) {
|
|
689
|
+
const prevSources = newSources, prevSourcesIndex = newSourcesIndex, prevFlags = newFlags;
|
|
690
|
+
newSources = null;
|
|
691
|
+
newSourcesIndex = observer.b ? observer.b.length : 0;
|
|
692
|
+
newFlags = 0;
|
|
693
|
+
try {
|
|
694
|
+
return compute(observer, run, observer);
|
|
695
|
+
} catch (error) {
|
|
696
|
+
if (error instanceof NotReadyError) {
|
|
697
|
+
observer.write(UNCHANGED, newFlags | LOADING_BIT | observer.d & UNINITIALIZED_BIT);
|
|
698
|
+
} else {
|
|
699
|
+
observer.F(error);
|
|
700
|
+
}
|
|
701
|
+
} finally {
|
|
702
|
+
if (newSources) {
|
|
703
|
+
if (newSourcesIndex > 0) {
|
|
704
|
+
observer.b.length = newSourcesIndex + newSources.length;
|
|
705
|
+
for (let i = 0; i < newSources.length; i++) {
|
|
706
|
+
observer.b[newSourcesIndex + i] = newSources[i];
|
|
707
|
+
}
|
|
708
|
+
} else {
|
|
709
|
+
observer.b = newSources;
|
|
710
|
+
}
|
|
711
|
+
let source;
|
|
712
|
+
for (let i = newSourcesIndex; i < observer.b.length; i++) {
|
|
713
|
+
source = observer.b[i];
|
|
714
|
+
if (!source.c)
|
|
715
|
+
source.c = [observer];
|
|
716
|
+
else
|
|
717
|
+
source.c.push(observer);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
newSources = prevSources;
|
|
721
|
+
newSourcesIndex = prevSourcesIndex;
|
|
722
|
+
newFlags = prevFlags;
|
|
723
|
+
}
|
|
724
|
+
}
|
|
690
725
|
function compute(owner, fn, observer) {
|
|
691
726
|
const prevOwner = setOwner(owner), prevObserver = currentObserver, prevMask = currentMask, prevNotStale = notStale;
|
|
692
727
|
currentObserver = observer;
|
|
693
728
|
currentMask = (observer == null ? void 0 : observer.O) ?? DEFAULT_FLAGS;
|
|
694
729
|
notStale = true;
|
|
695
730
|
try {
|
|
696
|
-
return fn(observer ? observer.
|
|
731
|
+
return fn(observer ? observer.e : void 0);
|
|
697
732
|
} finally {
|
|
698
733
|
setOwner(prevOwner);
|
|
699
734
|
currentObserver = prevObserver;
|
|
@@ -716,33 +751,31 @@ var Effect = class extends Computation {
|
|
|
716
751
|
B;
|
|
717
752
|
Q = false;
|
|
718
753
|
M;
|
|
719
|
-
|
|
754
|
+
u;
|
|
720
755
|
constructor(initialValue, compute2, effect, error, options) {
|
|
721
756
|
super(initialValue, compute2, options);
|
|
722
757
|
this.K = effect;
|
|
723
758
|
this.L = error;
|
|
724
759
|
this.M = initialValue;
|
|
725
|
-
this.
|
|
726
|
-
if (this.
|
|
727
|
-
this.
|
|
728
|
-
}
|
|
729
|
-
if (!(options == null ? void 0 : options.defer)) {
|
|
730
|
-
this.y();
|
|
731
|
-
this.w === EFFECT_USER ? this.h.enqueue(this.w, this) : this.T();
|
|
760
|
+
this.u = (options == null ? void 0 : options.render) ? EFFECT_RENDER : EFFECT_USER;
|
|
761
|
+
if (this.u === EFFECT_RENDER) {
|
|
762
|
+
this.A = (p) => getClock() > this.h.created ? latest(() => compute2(p)) : compute2(p);
|
|
732
763
|
}
|
|
764
|
+
this.y();
|
|
765
|
+
!(options == null ? void 0 : options.defer) && (this.u === EFFECT_USER ? this.h.enqueue(this.u, this) : this.T());
|
|
733
766
|
}
|
|
734
767
|
write(value, flags = 0) {
|
|
735
768
|
var _a, _b;
|
|
736
769
|
if (this.a == STATE_DIRTY) {
|
|
737
|
-
const currentFlags = this.
|
|
738
|
-
this.
|
|
739
|
-
if (this.
|
|
770
|
+
const currentFlags = this.d;
|
|
771
|
+
this.d = flags;
|
|
772
|
+
if (this.u === EFFECT_RENDER && (flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
|
|
740
773
|
(_b = (_a = this.h).R) == null ? void 0 : _b.call(_a, this);
|
|
741
774
|
}
|
|
742
775
|
}
|
|
743
776
|
if (value === UNCHANGED)
|
|
744
|
-
return this.
|
|
745
|
-
this.
|
|
777
|
+
return this.e;
|
|
778
|
+
this.e = value;
|
|
746
779
|
this.Q = true;
|
|
747
780
|
return value;
|
|
748
781
|
}
|
|
@@ -750,17 +783,17 @@ var Effect = class extends Computation {
|
|
|
750
783
|
if (this.a >= state || skipQueue)
|
|
751
784
|
return;
|
|
752
785
|
if (this.a === STATE_CLEAN)
|
|
753
|
-
this.h.enqueue(this.
|
|
786
|
+
this.h.enqueue(this.u, this);
|
|
754
787
|
this.a = state;
|
|
755
788
|
}
|
|
756
|
-
|
|
789
|
+
F(error) {
|
|
757
790
|
var _a, _b, _c;
|
|
758
791
|
(_a = this.B) == null ? void 0 : _a.call(this);
|
|
759
|
-
if (this.
|
|
760
|
-
this.
|
|
792
|
+
if (this.d & LOADING_BIT) {
|
|
793
|
+
this.d = 0;
|
|
761
794
|
(_c = (_b = this.h).R) == null ? void 0 : _c.call(_b, this);
|
|
762
795
|
}
|
|
763
|
-
if (this.
|
|
796
|
+
if (this.u === EFFECT_USER) {
|
|
764
797
|
try {
|
|
765
798
|
return this.L ? this.B = this.L(error) : console.error(new EffectError(this.K, error));
|
|
766
799
|
} catch (e) {
|
|
@@ -769,7 +802,7 @@ var Effect = class extends Computation {
|
|
|
769
802
|
}
|
|
770
803
|
this.handleError(error);
|
|
771
804
|
}
|
|
772
|
-
|
|
805
|
+
z() {
|
|
773
806
|
var _a;
|
|
774
807
|
if (this.a === STATE_DISPOSED)
|
|
775
808
|
return;
|
|
@@ -778,18 +811,18 @@ var Effect = class extends Computation {
|
|
|
778
811
|
this.L = void 0;
|
|
779
812
|
(_a = this.B) == null ? void 0 : _a.call(this);
|
|
780
813
|
this.B = void 0;
|
|
781
|
-
super.
|
|
814
|
+
super.z();
|
|
782
815
|
}
|
|
783
816
|
T() {
|
|
784
817
|
var _a;
|
|
785
818
|
if (this.Q && this.a !== STATE_DISPOSED) {
|
|
786
819
|
(_a = this.B) == null ? void 0 : _a.call(this);
|
|
787
820
|
try {
|
|
788
|
-
this.B = this.K(this.
|
|
821
|
+
this.B = this.K(this.e, this.M);
|
|
789
822
|
} catch (e) {
|
|
790
823
|
this.handleError(e);
|
|
791
824
|
} finally {
|
|
792
|
-
this.M = this.
|
|
825
|
+
this.M = this.e;
|
|
793
826
|
this.Q = false;
|
|
794
827
|
}
|
|
795
828
|
}
|
|
@@ -801,7 +834,7 @@ var EagerComputation = class extends Computation {
|
|
|
801
834
|
!(options == null ? void 0 : options.defer) && this.y();
|
|
802
835
|
}
|
|
803
836
|
q(state, skipQueue) {
|
|
804
|
-
if (this.a >= state && !this.
|
|
837
|
+
if (this.a >= state && !this.J)
|
|
805
838
|
return;
|
|
806
839
|
if (this.a === STATE_CLEAN && !skipQueue)
|
|
807
840
|
this.h.enqueue(EFFECT_PURE, this);
|
|
@@ -813,7 +846,7 @@ var ProjectionComputation = class extends Computation {
|
|
|
813
846
|
super(null, compute2);
|
|
814
847
|
}
|
|
815
848
|
q(state, skipQueue) {
|
|
816
|
-
if (this.a >= state && !this.
|
|
849
|
+
if (this.a >= state && !this.J)
|
|
817
850
|
return;
|
|
818
851
|
if (this.a === STATE_CLEAN && !skipQueue)
|
|
819
852
|
this.h.enqueue(EFFECT_PURE, this);
|
|
@@ -823,7 +856,7 @@ var ProjectionComputation = class extends Computation {
|
|
|
823
856
|
|
|
824
857
|
// src/core/suspense.ts
|
|
825
858
|
var SuspenseQueue = class extends Queue {
|
|
826
|
-
|
|
859
|
+
f = /* @__PURE__ */ new Set();
|
|
827
860
|
o = false;
|
|
828
861
|
S = new Computation(false, null);
|
|
829
862
|
run(type) {
|
|
@@ -832,15 +865,15 @@ var SuspenseQueue = class extends Queue {
|
|
|
832
865
|
return super.run(type);
|
|
833
866
|
}
|
|
834
867
|
R(node) {
|
|
835
|
-
if (node.
|
|
836
|
-
this.
|
|
868
|
+
if (node.d & LOADING_BIT) {
|
|
869
|
+
this.f.add(node);
|
|
837
870
|
if (!this.o) {
|
|
838
871
|
this.o = true;
|
|
839
872
|
this.S.write(true);
|
|
840
873
|
}
|
|
841
874
|
} else {
|
|
842
|
-
this.
|
|
843
|
-
if (this.
|
|
875
|
+
this.f.delete(node);
|
|
876
|
+
if (this.f.size === 0) {
|
|
844
877
|
this.o = false;
|
|
845
878
|
this.S.write(false);
|
|
846
879
|
}
|
|
@@ -850,13 +883,13 @@ var SuspenseQueue = class extends Queue {
|
|
|
850
883
|
var LiveComputation = class extends EagerComputation {
|
|
851
884
|
write(value, flags = 0) {
|
|
852
885
|
var _a, _b;
|
|
853
|
-
const currentFlags = this.
|
|
886
|
+
const currentFlags = this.d;
|
|
854
887
|
const dirty = this.a === STATE_DIRTY;
|
|
855
888
|
super.write(value, flags);
|
|
856
889
|
if (dirty && (flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
|
|
857
890
|
(_b = (_a = this.h).R) == null ? void 0 : _b.call(_a, this);
|
|
858
891
|
}
|
|
859
|
-
return this.
|
|
892
|
+
return this.e;
|
|
860
893
|
}
|
|
861
894
|
};
|
|
862
895
|
function createSuspense(fn, fallback) {
|
|
@@ -897,10 +930,10 @@ function createMemo(compute2, value, options) {
|
|
|
897
930
|
var _a, _b, _c;
|
|
898
931
|
if (node) {
|
|
899
932
|
resolvedValue = node.wait();
|
|
900
|
-
if (!((_a = node.
|
|
933
|
+
if (!((_a = node.b) == null ? void 0 : _a.length) && ((_b = node.n) == null ? void 0 : _b.s) !== node) {
|
|
901
934
|
node.dispose();
|
|
902
935
|
node = void 0;
|
|
903
|
-
} else if (!node.s && !((_c = node.
|
|
936
|
+
} else if (!node.s && !((_c = node.c) == null ? void 0 : _c.length)) {
|
|
904
937
|
node.dispose();
|
|
905
938
|
node.a = STATE_DIRTY;
|
|
906
939
|
}
|
|
@@ -912,10 +945,10 @@ function createAsync(compute2, value, options) {
|
|
|
912
945
|
let uninitialized = value === void 0;
|
|
913
946
|
const lhs = new EagerComputation(
|
|
914
947
|
{
|
|
915
|
-
|
|
948
|
+
e: value
|
|
916
949
|
},
|
|
917
950
|
(p) => {
|
|
918
|
-
const value2 = p == null ? void 0 : p.
|
|
951
|
+
const value2 = p == null ? void 0 : p.e;
|
|
919
952
|
const source = compute2(value2);
|
|
920
953
|
const isPromise = source instanceof Promise;
|
|
921
954
|
const iterator = source[Symbol.asyncIterator];
|
|
@@ -924,13 +957,13 @@ function createAsync(compute2, value, options) {
|
|
|
924
957
|
wait() {
|
|
925
958
|
return source;
|
|
926
959
|
},
|
|
927
|
-
|
|
960
|
+
e: source
|
|
928
961
|
};
|
|
929
962
|
}
|
|
930
963
|
const signal = new Computation(value2, null, options);
|
|
931
964
|
const w = signal.wait;
|
|
932
965
|
signal.wait = function() {
|
|
933
|
-
if (signal.
|
|
966
|
+
if (signal.d & ERROR_BIT && signal.x <= getClock()) {
|
|
934
967
|
lhs.q(STATE_DIRTY);
|
|
935
968
|
throw new NotReadyError();
|
|
936
969
|
}
|
|
@@ -945,7 +978,7 @@ function createAsync(compute2, value, options) {
|
|
|
945
978
|
},
|
|
946
979
|
(error) => {
|
|
947
980
|
uninitialized = true;
|
|
948
|
-
signal.
|
|
981
|
+
signal.F(error);
|
|
949
982
|
}
|
|
950
983
|
);
|
|
951
984
|
} else {
|
|
@@ -974,13 +1007,13 @@ function createEffect(compute2, effect, error, value, options) {
|
|
|
974
1007
|
compute2,
|
|
975
1008
|
effect,
|
|
976
1009
|
error,
|
|
977
|
-
|
|
1010
|
+
options
|
|
978
1011
|
);
|
|
979
1012
|
}
|
|
980
1013
|
function createRenderEffect(compute2, effect, value, options) {
|
|
981
1014
|
void new Effect(value, compute2, effect, void 0, {
|
|
982
1015
|
render: true,
|
|
983
|
-
...
|
|
1016
|
+
...options
|
|
984
1017
|
});
|
|
985
1018
|
}
|
|
986
1019
|
function createRoot(init) {
|
|
@@ -988,12 +1021,7 @@ function createRoot(init) {
|
|
|
988
1021
|
return compute(owner, !init.length ? init : () => init(() => owner.dispose()), null);
|
|
989
1022
|
}
|
|
990
1023
|
function runWithOwner(owner, run) {
|
|
991
|
-
|
|
992
|
-
return compute(owner, run, null);
|
|
993
|
-
} catch (error) {
|
|
994
|
-
owner == null ? void 0 : owner.handleError(error);
|
|
995
|
-
return void 0;
|
|
996
|
-
}
|
|
1024
|
+
return compute(owner, run, null);
|
|
997
1025
|
}
|
|
998
1026
|
function createErrorBoundary(fn, fallback) {
|
|
999
1027
|
const owner = new Owner();
|
|
@@ -1021,7 +1049,7 @@ function createErrorBoundary(fn, fallback) {
|
|
|
1021
1049
|
() => {
|
|
1022
1050
|
const c = new Computation(void 0, fn);
|
|
1023
1051
|
const f = new EagerComputation(void 0, () => flatten(c.read()), { defer: true });
|
|
1024
|
-
f.
|
|
1052
|
+
f.F = function(error2) {
|
|
1025
1053
|
this.handleError(error2);
|
|
1026
1054
|
};
|
|
1027
1055
|
return f;
|
|
@@ -1039,7 +1067,7 @@ function createErrorBoundary(fn, fallback) {
|
|
|
1039
1067
|
incrementClock();
|
|
1040
1068
|
for (let node of nodes) {
|
|
1041
1069
|
node.a = STATE_DIRTY;
|
|
1042
|
-
(_a = node.h) == null ? void 0 : _a.enqueue(node.
|
|
1070
|
+
(_a = node.h) == null ? void 0 : _a.enqueue(node.u, node);
|
|
1043
1071
|
}
|
|
1044
1072
|
});
|
|
1045
1073
|
});
|
|
@@ -1061,19 +1089,6 @@ function resolve(fn) {
|
|
|
1061
1089
|
});
|
|
1062
1090
|
});
|
|
1063
1091
|
}
|
|
1064
|
-
function createReaction(effect, error, options) {
|
|
1065
|
-
const node = new Effect(void 0, () => {
|
|
1066
|
-
}, effect, error, {
|
|
1067
|
-
defer: true,
|
|
1068
|
-
...void 0
|
|
1069
|
-
});
|
|
1070
|
-
return (tracking) => {
|
|
1071
|
-
node.u = tracking;
|
|
1072
|
-
node.a = STATE_DIRTY;
|
|
1073
|
-
node.y();
|
|
1074
|
-
node.u = null;
|
|
1075
|
-
};
|
|
1076
|
-
}
|
|
1077
1092
|
|
|
1078
1093
|
// src/store/projection.ts
|
|
1079
1094
|
function createProjection(fn, initialValue = {}) {
|
|
@@ -1220,7 +1235,7 @@ var proxyTraps = {
|
|
|
1220
1235
|
return desc.get.call(receiver);
|
|
1221
1236
|
}
|
|
1222
1237
|
if (Writing.has(storeValue)) {
|
|
1223
|
-
const value2 = tracked ? tracked.
|
|
1238
|
+
const value2 = tracked ? tracked.e : storeValue[property];
|
|
1224
1239
|
return isWrappable(value2) ? (Writing.add(value2[$RAW] || value2), wrap2(value2)) : value2;
|
|
1225
1240
|
}
|
|
1226
1241
|
let value = tracked ? nodes[property].read() : storeValue[property];
|
|
@@ -1561,13 +1576,13 @@ function omit(props, ...keys) {
|
|
|
1561
1576
|
function mapArray(list, map, options) {
|
|
1562
1577
|
const keyFn = typeof (options == null ? void 0 : options.keyed) === "function" ? options.keyed : void 0;
|
|
1563
1578
|
return updateKeyedMap.bind({
|
|
1564
|
-
|
|
1579
|
+
G: new Owner(),
|
|
1565
1580
|
i: 0,
|
|
1566
1581
|
X: list,
|
|
1567
|
-
|
|
1568
|
-
|
|
1582
|
+
w: [],
|
|
1583
|
+
H: map,
|
|
1569
1584
|
g: [],
|
|
1570
|
-
|
|
1585
|
+
f: [],
|
|
1571
1586
|
C: keyFn,
|
|
1572
1587
|
j: keyFn || (options == null ? void 0 : options.keyed) === false ? [] : void 0,
|
|
1573
1588
|
k: map.length > 1 ? [] : void 0,
|
|
@@ -1577,27 +1592,27 @@ function mapArray(list, map, options) {
|
|
|
1577
1592
|
function updateKeyedMap() {
|
|
1578
1593
|
const newItems = this.X() || [], newLen = newItems.length;
|
|
1579
1594
|
newItems[$TRACK];
|
|
1580
|
-
runWithOwner(this.
|
|
1595
|
+
runWithOwner(this.G, () => {
|
|
1581
1596
|
let i, j, mapper = this.j ? () => {
|
|
1582
1597
|
this.j[j] = new Computation(newItems[j], null);
|
|
1583
1598
|
this.k && (this.k[j] = new Computation(j, null));
|
|
1584
|
-
return this.
|
|
1599
|
+
return this.H(
|
|
1585
1600
|
Computation.prototype.read.bind(this.j[j]),
|
|
1586
1601
|
this.k ? Computation.prototype.read.bind(this.k[j]) : void 0
|
|
1587
1602
|
);
|
|
1588
1603
|
} : this.k ? () => {
|
|
1589
1604
|
const item = newItems[j];
|
|
1590
1605
|
this.k[j] = new Computation(j, null);
|
|
1591
|
-
return this.
|
|
1606
|
+
return this.H(() => item, Computation.prototype.read.bind(this.k[j]));
|
|
1592
1607
|
} : () => {
|
|
1593
1608
|
const item = newItems[j];
|
|
1594
|
-
return this.
|
|
1609
|
+
return this.H(() => item);
|
|
1595
1610
|
};
|
|
1596
1611
|
if (newLen === 0) {
|
|
1597
1612
|
if (this.i !== 0) {
|
|
1598
|
-
this.
|
|
1599
|
-
this.
|
|
1600
|
-
this.
|
|
1613
|
+
this.G.dispose(false);
|
|
1614
|
+
this.f = [];
|
|
1615
|
+
this.w = [];
|
|
1601
1616
|
this.g = [];
|
|
1602
1617
|
this.i = 0;
|
|
1603
1618
|
this.j && (this.j = []);
|
|
@@ -1605,29 +1620,29 @@ function updateKeyedMap() {
|
|
|
1605
1620
|
}
|
|
1606
1621
|
if (this.o && !this.g[0]) {
|
|
1607
1622
|
this.g[0] = compute(
|
|
1608
|
-
this.
|
|
1623
|
+
this.f[0] = new Owner(),
|
|
1609
1624
|
this.o,
|
|
1610
1625
|
null
|
|
1611
1626
|
);
|
|
1612
1627
|
}
|
|
1613
1628
|
} else if (this.i === 0) {
|
|
1614
|
-
if (this.
|
|
1615
|
-
this.
|
|
1629
|
+
if (this.f[0])
|
|
1630
|
+
this.f[0].dispose();
|
|
1616
1631
|
this.g = new Array(newLen);
|
|
1617
1632
|
for (j = 0; j < newLen; j++) {
|
|
1618
|
-
this.
|
|
1619
|
-
this.g[j] = compute(this.
|
|
1633
|
+
this.w[j] = newItems[j];
|
|
1634
|
+
this.g[j] = compute(this.f[j] = new Owner(), mapper, null);
|
|
1620
1635
|
}
|
|
1621
1636
|
this.i = newLen;
|
|
1622
1637
|
} else {
|
|
1623
1638
|
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;
|
|
1624
|
-
for (start = 0, end = Math.min(this.i, newLen); start < end && (this.
|
|
1639
|
+
for (start = 0, end = Math.min(this.i, newLen); start < end && (this.w[start] === newItems[start] || this.j && compare(this.C, this.w[start], newItems[start])); start++) {
|
|
1625
1640
|
if (this.j)
|
|
1626
1641
|
this.j[start].write(newItems[start]);
|
|
1627
1642
|
}
|
|
1628
|
-
for (end = this.i - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.
|
|
1643
|
+
for (end = this.i - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.w[end] === newItems[newEnd] || this.j && compare(this.C, this.w[end], newItems[newEnd])); end--, newEnd--) {
|
|
1629
1644
|
temp[newEnd] = this.g[end];
|
|
1630
|
-
tempNodes[newEnd] = this.
|
|
1645
|
+
tempNodes[newEnd] = this.f[end];
|
|
1631
1646
|
tempRows && (tempRows[newEnd] = this.j[end]);
|
|
1632
1647
|
tempIndexes && (tempIndexes[newEnd] = this.k[end]);
|
|
1633
1648
|
}
|
|
@@ -1641,23 +1656,23 @@ function updateKeyedMap() {
|
|
|
1641
1656
|
newIndices.set(key, j);
|
|
1642
1657
|
}
|
|
1643
1658
|
for (i = start; i <= end; i++) {
|
|
1644
|
-
item = this.
|
|
1659
|
+
item = this.w[i];
|
|
1645
1660
|
key = this.C ? this.C(item) : item;
|
|
1646
1661
|
j = newIndices.get(key);
|
|
1647
1662
|
if (j !== void 0 && j !== -1) {
|
|
1648
1663
|
temp[j] = this.g[i];
|
|
1649
|
-
tempNodes[j] = this.
|
|
1664
|
+
tempNodes[j] = this.f[i];
|
|
1650
1665
|
tempRows && (tempRows[j] = this.j[i]);
|
|
1651
1666
|
tempIndexes && (tempIndexes[j] = this.k[i]);
|
|
1652
1667
|
j = newIndicesNext[j];
|
|
1653
1668
|
newIndices.set(key, j);
|
|
1654
1669
|
} else
|
|
1655
|
-
this.
|
|
1670
|
+
this.f[i].dispose();
|
|
1656
1671
|
}
|
|
1657
1672
|
for (j = start; j < newLen; j++) {
|
|
1658
1673
|
if (j in temp) {
|
|
1659
1674
|
this.g[j] = temp[j];
|
|
1660
|
-
this.
|
|
1675
|
+
this.f[j] = tempNodes[j];
|
|
1661
1676
|
if (tempRows) {
|
|
1662
1677
|
this.j[j] = tempRows[j];
|
|
1663
1678
|
this.j[j].write(newItems[j]);
|
|
@@ -1667,55 +1682,55 @@ function updateKeyedMap() {
|
|
|
1667
1682
|
this.k[j].write(j);
|
|
1668
1683
|
}
|
|
1669
1684
|
} else {
|
|
1670
|
-
this.g[j] = compute(this.
|
|
1685
|
+
this.g[j] = compute(this.f[j] = new Owner(), mapper, null);
|
|
1671
1686
|
}
|
|
1672
1687
|
}
|
|
1673
1688
|
this.g = this.g.slice(0, this.i = newLen);
|
|
1674
|
-
this.
|
|
1689
|
+
this.w = newItems.slice(0);
|
|
1675
1690
|
}
|
|
1676
1691
|
});
|
|
1677
1692
|
return this.g;
|
|
1678
1693
|
}
|
|
1679
1694
|
function repeat(count, map, options) {
|
|
1680
1695
|
return updateRepeat.bind({
|
|
1681
|
-
|
|
1696
|
+
G: new Owner(),
|
|
1682
1697
|
i: 0,
|
|
1683
1698
|
Y: count,
|
|
1684
|
-
|
|
1685
|
-
|
|
1699
|
+
H: map,
|
|
1700
|
+
f: [],
|
|
1686
1701
|
g: [],
|
|
1687
1702
|
o: options == null ? void 0 : options.fallback
|
|
1688
1703
|
});
|
|
1689
1704
|
}
|
|
1690
1705
|
function updateRepeat() {
|
|
1691
1706
|
const newLen = this.Y();
|
|
1692
|
-
runWithOwner(this.
|
|
1707
|
+
runWithOwner(this.G, () => {
|
|
1693
1708
|
if (newLen === 0) {
|
|
1694
1709
|
if (this.i !== 0) {
|
|
1695
|
-
this.
|
|
1696
|
-
this.
|
|
1710
|
+
this.G.dispose(false);
|
|
1711
|
+
this.f = [];
|
|
1697
1712
|
this.g = [];
|
|
1698
1713
|
this.i = 0;
|
|
1699
1714
|
}
|
|
1700
1715
|
if (this.o && !this.g[0]) {
|
|
1701
1716
|
this.g[0] = compute(
|
|
1702
|
-
this.
|
|
1717
|
+
this.f[0] = new Owner(),
|
|
1703
1718
|
this.o,
|
|
1704
1719
|
null
|
|
1705
1720
|
);
|
|
1706
1721
|
}
|
|
1707
1722
|
} else {
|
|
1708
|
-
if (this.i === 0 && this.
|
|
1709
|
-
this.
|
|
1723
|
+
if (this.i === 0 && this.f[0])
|
|
1724
|
+
this.f[0].dispose();
|
|
1710
1725
|
for (let i = this.i; i < newLen; i++) {
|
|
1711
1726
|
this.g[i] = compute(
|
|
1712
|
-
this.
|
|
1713
|
-
() => this.
|
|
1727
|
+
this.f[i] = new Owner(),
|
|
1728
|
+
() => this.H(i),
|
|
1714
1729
|
null
|
|
1715
1730
|
);
|
|
1716
1731
|
}
|
|
1717
1732
|
for (let i = newLen; i < this.i; i++)
|
|
1718
|
-
this.
|
|
1733
|
+
this.f[i].dispose();
|
|
1719
1734
|
this.g = this.g.slice(0, newLen);
|
|
1720
1735
|
this.i = newLen;
|
|
1721
1736
|
}
|
|
@@ -1745,7 +1760,6 @@ exports.createEffect = createEffect;
|
|
|
1745
1760
|
exports.createErrorBoundary = createErrorBoundary;
|
|
1746
1761
|
exports.createMemo = createMemo;
|
|
1747
1762
|
exports.createProjection = createProjection;
|
|
1748
|
-
exports.createReaction = createReaction;
|
|
1749
1763
|
exports.createRenderEffect = createRenderEffect;
|
|
1750
1764
|
exports.createRoot = createRoot;
|
|
1751
1765
|
exports.createSignal = createSignal;
|
|
@@ -1769,6 +1783,7 @@ exports.onCleanup = onCleanup;
|
|
|
1769
1783
|
exports.reconcile = reconcile;
|
|
1770
1784
|
exports.repeat = repeat;
|
|
1771
1785
|
exports.resolve = resolve;
|
|
1786
|
+
exports.runWithObserver = runWithObserver;
|
|
1772
1787
|
exports.runWithOwner = runWithOwner;
|
|
1773
1788
|
exports.setContext = setContext;
|
|
1774
1789
|
exports.untrack = untrack;
|