@solidjs/signals 0.1.0 → 0.2.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 +58 -30
- package/dist/node.cjs +220 -192
- package/dist/prod.js +219 -191
- package/dist/types/core/core.d.ts +10 -2
- package/dist/types/core/index.d.ts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/signals.d.ts +7 -19
- package/package.json +1 -1
package/dist/prod.js
CHANGED
|
@@ -43,11 +43,11 @@ function schedule() {
|
|
|
43
43
|
if (scheduled)
|
|
44
44
|
return;
|
|
45
45
|
scheduled = true;
|
|
46
|
-
if (!globalQueue.
|
|
46
|
+
if (!globalQueue.I)
|
|
47
47
|
queueMicrotask(flushSync);
|
|
48
48
|
}
|
|
49
49
|
var Queue = class {
|
|
50
|
-
|
|
50
|
+
I = false;
|
|
51
51
|
r = [[], [], []];
|
|
52
52
|
D = [];
|
|
53
53
|
created = clock;
|
|
@@ -76,9 +76,9 @@ var Queue = class {
|
|
|
76
76
|
return true;
|
|
77
77
|
}
|
|
78
78
|
flush() {
|
|
79
|
-
if (this.
|
|
79
|
+
if (this.I)
|
|
80
80
|
return;
|
|
81
|
-
this.
|
|
81
|
+
this.I = true;
|
|
82
82
|
try {
|
|
83
83
|
while (this.run(EFFECT_PURE)) {
|
|
84
84
|
}
|
|
@@ -87,7 +87,7 @@ var Queue = class {
|
|
|
87
87
|
this.run(EFFECT_RENDER);
|
|
88
88
|
this.run(EFFECT_USER);
|
|
89
89
|
} finally {
|
|
90
|
-
this.
|
|
90
|
+
this.I = false;
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
addChild(child) {
|
|
@@ -236,19 +236,19 @@ var Owner = class {
|
|
|
236
236
|
let head = self ? this.t || this.s : this, current = this.n, next = null;
|
|
237
237
|
while (current && current.s === this) {
|
|
238
238
|
current.dispose(true);
|
|
239
|
-
current.
|
|
239
|
+
current.z();
|
|
240
240
|
next = current.n;
|
|
241
241
|
current.n = null;
|
|
242
242
|
current = next;
|
|
243
243
|
}
|
|
244
244
|
if (self)
|
|
245
|
-
this.
|
|
245
|
+
this.z();
|
|
246
246
|
if (current)
|
|
247
247
|
current.t = !self ? this : this.t;
|
|
248
248
|
if (head)
|
|
249
249
|
head.n = current;
|
|
250
250
|
}
|
|
251
|
-
|
|
251
|
+
z() {
|
|
252
252
|
if (this.t)
|
|
253
253
|
this.t.n = null;
|
|
254
254
|
this.s = null;
|
|
@@ -349,11 +349,11 @@ function getObserver() {
|
|
|
349
349
|
}
|
|
350
350
|
var UNCHANGED = Symbol(0);
|
|
351
351
|
var Computation = class extends Owner {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
352
|
+
b = null;
|
|
353
|
+
c = null;
|
|
354
|
+
e;
|
|
355
355
|
E;
|
|
356
|
-
|
|
356
|
+
A;
|
|
357
357
|
// Used in __DEV__ mode, hopefully removed in production
|
|
358
358
|
Z;
|
|
359
359
|
// Using false is an optimization as an alternative to _equals: () => false
|
|
@@ -361,37 +361,37 @@ var Computation = class extends Owner {
|
|
|
361
361
|
N = isEqual;
|
|
362
362
|
U;
|
|
363
363
|
/** Whether the computation is an error or has ancestors that are unresolved */
|
|
364
|
-
|
|
364
|
+
d = 0;
|
|
365
365
|
/** Which flags raised by sources are handled, vs. being passed through. */
|
|
366
366
|
O = DEFAULT_FLAGS;
|
|
367
367
|
P = null;
|
|
368
|
-
|
|
369
|
-
|
|
368
|
+
x = -1;
|
|
369
|
+
J = false;
|
|
370
370
|
constructor(initialValue, compute2, options) {
|
|
371
371
|
super(compute2 === null);
|
|
372
|
-
this.
|
|
372
|
+
this.A = compute2;
|
|
373
373
|
this.a = compute2 ? STATE_DIRTY : STATE_CLEAN;
|
|
374
|
-
this.
|
|
375
|
-
this.
|
|
374
|
+
this.d = compute2 && initialValue === void 0 ? UNINITIALIZED_BIT : 0;
|
|
375
|
+
this.e = initialValue;
|
|
376
376
|
if (options?.equals !== void 0)
|
|
377
377
|
this.N = options.equals;
|
|
378
378
|
if (options?.unobserved)
|
|
379
379
|
this.U = options?.unobserved;
|
|
380
380
|
}
|
|
381
381
|
V() {
|
|
382
|
-
if (this.
|
|
383
|
-
if (this.
|
|
382
|
+
if (this.A) {
|
|
383
|
+
if (this.d & ERROR_BIT && this.x <= getClock())
|
|
384
384
|
update(this);
|
|
385
385
|
else
|
|
386
386
|
this.y();
|
|
387
387
|
}
|
|
388
|
-
if (!this.
|
|
388
|
+
if (!this.A || this.b?.length)
|
|
389
389
|
track(this);
|
|
390
|
-
newFlags |= this.
|
|
391
|
-
if (this.
|
|
390
|
+
newFlags |= this.d & ~currentMask;
|
|
391
|
+
if (this.d & ERROR_BIT) {
|
|
392
392
|
throw this.E;
|
|
393
393
|
} else {
|
|
394
|
-
return this.
|
|
394
|
+
return this.e;
|
|
395
395
|
}
|
|
396
396
|
}
|
|
397
397
|
/**
|
|
@@ -409,14 +409,14 @@ var Computation = class extends Owner {
|
|
|
409
409
|
* before continuing
|
|
410
410
|
*/
|
|
411
411
|
wait() {
|
|
412
|
-
if (this.
|
|
412
|
+
if (this.A && this.d & ERROR_BIT && this.x <= getClock()) {
|
|
413
413
|
update(this);
|
|
414
414
|
}
|
|
415
|
-
if ((notStale || this.
|
|
415
|
+
if ((notStale || this.d & UNINITIALIZED_BIT) && this.loading()) {
|
|
416
416
|
throw new NotReadyError();
|
|
417
417
|
}
|
|
418
418
|
if (staleCheck && this.loading())
|
|
419
|
-
staleCheck.
|
|
419
|
+
staleCheck.e = true;
|
|
420
420
|
return this.V();
|
|
421
421
|
}
|
|
422
422
|
/**
|
|
@@ -434,37 +434,37 @@ var Computation = class extends Owner {
|
|
|
434
434
|
}
|
|
435
435
|
/** Update the computation with a new value. */
|
|
436
436
|
write(value, flags = 0, raw = false) {
|
|
437
|
-
const newValue = !raw && typeof value === "function" ? value(this.
|
|
438
|
-
const valueChanged = newValue !== UNCHANGED && (!!(this.
|
|
437
|
+
const newValue = !raw && typeof value === "function" ? value(this.e) : value;
|
|
438
|
+
const valueChanged = newValue !== UNCHANGED && (!!(this.d & UNINITIALIZED_BIT) || this.N === false || !this.N(this.e, newValue));
|
|
439
439
|
if (valueChanged) {
|
|
440
|
-
this.
|
|
440
|
+
this.e = newValue;
|
|
441
441
|
this.E = void 0;
|
|
442
442
|
}
|
|
443
|
-
const changedFlagsMask = this.
|
|
444
|
-
this.
|
|
445
|
-
this.
|
|
446
|
-
if (this.
|
|
447
|
-
for (let i = 0; i < this.
|
|
443
|
+
const changedFlagsMask = this.d ^ flags, changedFlags = changedFlagsMask & flags;
|
|
444
|
+
this.d = flags;
|
|
445
|
+
this.x = getClock() + 1;
|
|
446
|
+
if (this.c) {
|
|
447
|
+
for (let i = 0; i < this.c.length; i++) {
|
|
448
448
|
if (valueChanged) {
|
|
449
|
-
this.
|
|
449
|
+
this.c[i].q(STATE_DIRTY);
|
|
450
450
|
} else if (changedFlagsMask) {
|
|
451
|
-
this.
|
|
451
|
+
this.c[i].W(changedFlagsMask, changedFlags);
|
|
452
452
|
}
|
|
453
453
|
}
|
|
454
454
|
}
|
|
455
|
-
return this.
|
|
455
|
+
return this.e;
|
|
456
456
|
}
|
|
457
457
|
/**
|
|
458
458
|
* Set the current node's state, and recursively mark all of this node's observers as STATE_CHECK
|
|
459
459
|
*/
|
|
460
460
|
q(state, skipQueue) {
|
|
461
|
-
if (this.a >= state && !this.
|
|
461
|
+
if (this.a >= state && !this.J)
|
|
462
462
|
return;
|
|
463
|
-
this.
|
|
463
|
+
this.J = !!skipQueue;
|
|
464
464
|
this.a = state;
|
|
465
|
-
if (this.
|
|
466
|
-
for (let i = 0; i < this.
|
|
467
|
-
this.
|
|
465
|
+
if (this.c) {
|
|
466
|
+
for (let i = 0; i < this.c.length; i++) {
|
|
467
|
+
this.c[i].q(STATE_CHECK, skipQueue);
|
|
468
468
|
}
|
|
469
469
|
}
|
|
470
470
|
}
|
|
@@ -483,22 +483,22 @@ var Computation = class extends Owner {
|
|
|
483
483
|
}
|
|
484
484
|
if (this.a >= STATE_CHECK)
|
|
485
485
|
return;
|
|
486
|
-
const prevFlags = this.
|
|
486
|
+
const prevFlags = this.d & mask;
|
|
487
487
|
const deltaFlags = prevFlags ^ newFlags2;
|
|
488
488
|
if (newFlags2 === prevFlags) ; else if (deltaFlags & prevFlags & mask) {
|
|
489
489
|
this.q(STATE_CHECK);
|
|
490
490
|
} else {
|
|
491
|
-
this.
|
|
492
|
-
if (this.
|
|
493
|
-
for (let i = 0; i < this.
|
|
494
|
-
this.
|
|
491
|
+
this.d ^= deltaFlags;
|
|
492
|
+
if (this.c) {
|
|
493
|
+
for (let i = 0; i < this.c.length; i++) {
|
|
494
|
+
this.c[i].W(mask, newFlags2);
|
|
495
495
|
}
|
|
496
496
|
}
|
|
497
497
|
}
|
|
498
498
|
}
|
|
499
|
-
|
|
499
|
+
F(error) {
|
|
500
500
|
this.E = error;
|
|
501
|
-
this.write(UNCHANGED, this.
|
|
501
|
+
this.write(UNCHANGED, this.d & ~LOADING_BIT | ERROR_BIT | UNINITIALIZED_BIT);
|
|
502
502
|
}
|
|
503
503
|
/**
|
|
504
504
|
* This is the core part of the reactivity system, which makes sure that the values are updated
|
|
@@ -516,9 +516,9 @@ var Computation = class extends Owner {
|
|
|
516
516
|
}
|
|
517
517
|
let observerFlags = 0;
|
|
518
518
|
if (this.a === STATE_CHECK) {
|
|
519
|
-
for (let i = 0; i < this.
|
|
520
|
-
this.
|
|
521
|
-
observerFlags |= this.
|
|
519
|
+
for (let i = 0; i < this.b.length; i++) {
|
|
520
|
+
this.b[i].y();
|
|
521
|
+
observerFlags |= this.b[i].d;
|
|
522
522
|
if (this.a === STATE_DIRTY) {
|
|
523
523
|
break;
|
|
524
524
|
}
|
|
@@ -534,12 +534,12 @@ var Computation = class extends Owner {
|
|
|
534
534
|
/**
|
|
535
535
|
* Remove ourselves from the owner graph and the computation graph
|
|
536
536
|
*/
|
|
537
|
-
|
|
537
|
+
z() {
|
|
538
538
|
if (this.a === STATE_DISPOSED)
|
|
539
539
|
return;
|
|
540
|
-
if (this.
|
|
540
|
+
if (this.b)
|
|
541
541
|
removeSourceObservers(this, 0);
|
|
542
|
-
super.
|
|
542
|
+
super.z();
|
|
543
543
|
}
|
|
544
544
|
};
|
|
545
545
|
function loadingState(node) {
|
|
@@ -550,7 +550,7 @@ function loadingState(node) {
|
|
|
550
550
|
() => {
|
|
551
551
|
track(node);
|
|
552
552
|
node.y();
|
|
553
|
-
return !!(node.
|
|
553
|
+
return !!(node.d & LOADING_BIT);
|
|
554
554
|
},
|
|
555
555
|
options
|
|
556
556
|
);
|
|
@@ -560,7 +560,7 @@ function loadingState(node) {
|
|
|
560
560
|
}
|
|
561
561
|
function track(computation) {
|
|
562
562
|
if (currentObserver) {
|
|
563
|
-
if (!newSources && currentObserver.
|
|
563
|
+
if (!newSources && currentObserver.b && currentObserver.b[newSourcesIndex] === computation) {
|
|
564
564
|
newSourcesIndex++;
|
|
565
565
|
} else if (!newSources)
|
|
566
566
|
newSources = [computation];
|
|
@@ -568,7 +568,7 @@ function track(computation) {
|
|
|
568
568
|
newSources.push(computation);
|
|
569
569
|
}
|
|
570
570
|
if (updateCheck) {
|
|
571
|
-
updateCheck.
|
|
571
|
+
updateCheck.e = computation.x > currentObserver.x;
|
|
572
572
|
}
|
|
573
573
|
}
|
|
574
574
|
}
|
|
@@ -580,55 +580,55 @@ function update(node) {
|
|
|
580
580
|
try {
|
|
581
581
|
node.dispose(false);
|
|
582
582
|
node.emptyDisposal();
|
|
583
|
-
const result = compute(node, node.
|
|
583
|
+
const result = compute(node, node.A, node);
|
|
584
584
|
node.write(result, newFlags, true);
|
|
585
585
|
} catch (error) {
|
|
586
586
|
if (error instanceof NotReadyError) {
|
|
587
|
-
node.write(UNCHANGED, newFlags | LOADING_BIT | node.
|
|
587
|
+
node.write(UNCHANGED, newFlags | LOADING_BIT | node.d & UNINITIALIZED_BIT);
|
|
588
588
|
} else {
|
|
589
|
-
node.
|
|
589
|
+
node.F(error);
|
|
590
590
|
}
|
|
591
591
|
} finally {
|
|
592
592
|
if (newSources) {
|
|
593
|
-
if (node.
|
|
593
|
+
if (node.b)
|
|
594
594
|
removeSourceObservers(node, newSourcesIndex);
|
|
595
|
-
if (node.
|
|
596
|
-
node.
|
|
595
|
+
if (node.b && newSourcesIndex > 0) {
|
|
596
|
+
node.b.length = newSourcesIndex + newSources.length;
|
|
597
597
|
for (let i = 0; i < newSources.length; i++) {
|
|
598
|
-
node.
|
|
598
|
+
node.b[newSourcesIndex + i] = newSources[i];
|
|
599
599
|
}
|
|
600
600
|
} else {
|
|
601
|
-
node.
|
|
601
|
+
node.b = newSources;
|
|
602
602
|
}
|
|
603
603
|
let source;
|
|
604
|
-
for (let i = newSourcesIndex; i < node.
|
|
605
|
-
source = node.
|
|
606
|
-
if (!source.
|
|
607
|
-
source.
|
|
604
|
+
for (let i = newSourcesIndex; i < node.b.length; i++) {
|
|
605
|
+
source = node.b[i];
|
|
606
|
+
if (!source.c)
|
|
607
|
+
source.c = [node];
|
|
608
608
|
else
|
|
609
|
-
source.
|
|
609
|
+
source.c.push(node);
|
|
610
610
|
}
|
|
611
|
-
} else if (node.
|
|
611
|
+
} else if (node.b && newSourcesIndex < node.b.length) {
|
|
612
612
|
removeSourceObservers(node, newSourcesIndex);
|
|
613
|
-
node.
|
|
613
|
+
node.b.length = newSourcesIndex;
|
|
614
614
|
}
|
|
615
615
|
newSources = prevSources;
|
|
616
616
|
newSourcesIndex = prevSourcesIndex;
|
|
617
617
|
newFlags = prevFlags;
|
|
618
|
-
node.
|
|
618
|
+
node.x = getClock() + 1;
|
|
619
619
|
node.a = STATE_CLEAN;
|
|
620
620
|
}
|
|
621
621
|
}
|
|
622
622
|
function removeSourceObservers(node, index) {
|
|
623
623
|
let source;
|
|
624
624
|
let swap;
|
|
625
|
-
for (let i = index; i < node.
|
|
626
|
-
source = node.
|
|
627
|
-
if (source.
|
|
628
|
-
swap = source.
|
|
629
|
-
source.
|
|
630
|
-
source.
|
|
631
|
-
if (!source.
|
|
625
|
+
for (let i = index; i < node.b.length; i++) {
|
|
626
|
+
source = node.b[i];
|
|
627
|
+
if (source.c) {
|
|
628
|
+
swap = source.c.indexOf(node);
|
|
629
|
+
source.c[swap] = source.c[source.c.length - 1];
|
|
630
|
+
source.c.pop();
|
|
631
|
+
if (!source.c.length)
|
|
632
632
|
source.U?.();
|
|
633
633
|
}
|
|
634
634
|
}
|
|
@@ -643,32 +643,40 @@ function untrack(fn) {
|
|
|
643
643
|
}
|
|
644
644
|
function hasUpdated(fn) {
|
|
645
645
|
const current = updateCheck;
|
|
646
|
-
updateCheck = {
|
|
646
|
+
updateCheck = { e: false };
|
|
647
647
|
try {
|
|
648
648
|
fn();
|
|
649
|
-
return updateCheck.
|
|
649
|
+
return updateCheck.e;
|
|
650
650
|
} finally {
|
|
651
651
|
updateCheck = current;
|
|
652
652
|
}
|
|
653
653
|
}
|
|
654
|
-
function
|
|
654
|
+
function isPending(fn, loadingValue) {
|
|
655
|
+
const argLength = arguments.length;
|
|
655
656
|
const current = staleCheck;
|
|
656
|
-
staleCheck = {
|
|
657
|
+
staleCheck = { e: false };
|
|
657
658
|
try {
|
|
658
659
|
latest(fn);
|
|
659
|
-
return staleCheck.
|
|
660
|
-
} catch {
|
|
660
|
+
return staleCheck.e;
|
|
661
|
+
} catch (err) {
|
|
662
|
+
if (argLength > 1 && err instanceof NotReadyError)
|
|
663
|
+
return !!loadingValue;
|
|
664
|
+
throw err;
|
|
661
665
|
} finally {
|
|
662
666
|
staleCheck = current;
|
|
663
667
|
}
|
|
664
|
-
return false;
|
|
665
668
|
}
|
|
666
|
-
function latest(fn) {
|
|
669
|
+
function latest(fn, fallback) {
|
|
670
|
+
const argLength = arguments.length;
|
|
667
671
|
const prevFlags = newFlags;
|
|
668
672
|
const prevNotStale = notStale;
|
|
669
673
|
notStale = false;
|
|
670
674
|
try {
|
|
671
675
|
return fn();
|
|
676
|
+
} catch (err) {
|
|
677
|
+
if (argLength > 1 && err instanceof NotReadyError)
|
|
678
|
+
return fallback;
|
|
679
|
+
throw err;
|
|
672
680
|
} finally {
|
|
673
681
|
newFlags = prevFlags;
|
|
674
682
|
notStale = prevNotStale;
|
|
@@ -683,13 +691,53 @@ function catchError(fn) {
|
|
|
683
691
|
return e;
|
|
684
692
|
}
|
|
685
693
|
}
|
|
694
|
+
function runWithObserver(observer, run) {
|
|
695
|
+
const prevSources = newSources, prevSourcesIndex = newSourcesIndex, prevFlags = newFlags;
|
|
696
|
+
newSources = null;
|
|
697
|
+
newSourcesIndex = observer.b ? observer.b.length : 0;
|
|
698
|
+
newFlags = 0;
|
|
699
|
+
try {
|
|
700
|
+
return compute(observer, run, observer);
|
|
701
|
+
} catch (error) {
|
|
702
|
+
if (error instanceof NotReadyError) {
|
|
703
|
+
observer.write(
|
|
704
|
+
UNCHANGED,
|
|
705
|
+
newFlags | LOADING_BIT | observer.d & UNINITIALIZED_BIT
|
|
706
|
+
);
|
|
707
|
+
} else {
|
|
708
|
+
observer.F(error);
|
|
709
|
+
}
|
|
710
|
+
} finally {
|
|
711
|
+
if (newSources) {
|
|
712
|
+
if (newSourcesIndex > 0) {
|
|
713
|
+
observer.b.length = newSourcesIndex + newSources.length;
|
|
714
|
+
for (let i = 0; i < newSources.length; i++) {
|
|
715
|
+
observer.b[newSourcesIndex + i] = newSources[i];
|
|
716
|
+
}
|
|
717
|
+
} else {
|
|
718
|
+
observer.b = newSources;
|
|
719
|
+
}
|
|
720
|
+
let source;
|
|
721
|
+
for (let i = newSourcesIndex; i < observer.b.length; i++) {
|
|
722
|
+
source = observer.b[i];
|
|
723
|
+
if (!source.c)
|
|
724
|
+
source.c = [observer];
|
|
725
|
+
else
|
|
726
|
+
source.c.push(observer);
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
newSources = prevSources;
|
|
730
|
+
newSourcesIndex = prevSourcesIndex;
|
|
731
|
+
newFlags = prevFlags;
|
|
732
|
+
}
|
|
733
|
+
}
|
|
686
734
|
function compute(owner, fn, observer) {
|
|
687
735
|
const prevOwner = setOwner(owner), prevObserver = currentObserver, prevMask = currentMask, prevNotStale = notStale;
|
|
688
736
|
currentObserver = observer;
|
|
689
737
|
currentMask = observer?.O ?? DEFAULT_FLAGS;
|
|
690
738
|
notStale = true;
|
|
691
739
|
try {
|
|
692
|
-
return fn(observer ? observer.
|
|
740
|
+
return fn(observer ? observer.e : void 0);
|
|
693
741
|
} finally {
|
|
694
742
|
setOwner(prevOwner);
|
|
695
743
|
currentObserver = prevObserver;
|
|
@@ -712,32 +760,30 @@ var Effect = class extends Computation {
|
|
|
712
760
|
B;
|
|
713
761
|
Q = false;
|
|
714
762
|
M;
|
|
715
|
-
|
|
763
|
+
u;
|
|
716
764
|
constructor(initialValue, compute2, effect, error, options) {
|
|
717
765
|
super(initialValue, compute2, options);
|
|
718
766
|
this.K = effect;
|
|
719
767
|
this.L = error;
|
|
720
768
|
this.M = initialValue;
|
|
721
|
-
this.
|
|
722
|
-
if (this.
|
|
723
|
-
this.
|
|
724
|
-
}
|
|
725
|
-
if (!options?.defer) {
|
|
726
|
-
this.y();
|
|
727
|
-
this.w === EFFECT_USER ? this.h.enqueue(this.w, this) : this.T();
|
|
769
|
+
this.u = options?.render ? EFFECT_RENDER : EFFECT_USER;
|
|
770
|
+
if (this.u === EFFECT_RENDER) {
|
|
771
|
+
this.A = (p) => getClock() > this.h.created ? latest(() => compute2(p)) : compute2(p);
|
|
728
772
|
}
|
|
773
|
+
this.y();
|
|
774
|
+
!options?.defer && (this.u === EFFECT_USER ? this.h.enqueue(this.u, this) : this.T());
|
|
729
775
|
}
|
|
730
776
|
write(value, flags = 0) {
|
|
731
777
|
if (this.a == STATE_DIRTY) {
|
|
732
|
-
const currentFlags = this.
|
|
733
|
-
this.
|
|
734
|
-
if (this.
|
|
778
|
+
const currentFlags = this.d;
|
|
779
|
+
this.d = flags;
|
|
780
|
+
if (this.u === EFFECT_RENDER && (flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
|
|
735
781
|
this.h.R?.(this);
|
|
736
782
|
}
|
|
737
783
|
}
|
|
738
784
|
if (value === UNCHANGED)
|
|
739
|
-
return this.
|
|
740
|
-
this.
|
|
785
|
+
return this.e;
|
|
786
|
+
this.e = value;
|
|
741
787
|
this.Q = true;
|
|
742
788
|
return value;
|
|
743
789
|
}
|
|
@@ -745,16 +791,16 @@ var Effect = class extends Computation {
|
|
|
745
791
|
if (this.a >= state || skipQueue)
|
|
746
792
|
return;
|
|
747
793
|
if (this.a === STATE_CLEAN)
|
|
748
|
-
this.h.enqueue(this.
|
|
794
|
+
this.h.enqueue(this.u, this);
|
|
749
795
|
this.a = state;
|
|
750
796
|
}
|
|
751
|
-
|
|
797
|
+
F(error) {
|
|
752
798
|
this.B?.();
|
|
753
|
-
if (this.
|
|
754
|
-
this.
|
|
799
|
+
if (this.d & LOADING_BIT) {
|
|
800
|
+
this.d = 0;
|
|
755
801
|
this.h.R?.(this);
|
|
756
802
|
}
|
|
757
|
-
if (this.
|
|
803
|
+
if (this.u === EFFECT_USER) {
|
|
758
804
|
try {
|
|
759
805
|
return this.L ? this.B = this.L(error) : console.error(new EffectError(this.K, error));
|
|
760
806
|
} catch (e) {
|
|
@@ -763,7 +809,7 @@ var Effect = class extends Computation {
|
|
|
763
809
|
}
|
|
764
810
|
this.handleError(error);
|
|
765
811
|
}
|
|
766
|
-
|
|
812
|
+
z() {
|
|
767
813
|
if (this.a === STATE_DISPOSED)
|
|
768
814
|
return;
|
|
769
815
|
this.K = void 0;
|
|
@@ -771,17 +817,17 @@ var Effect = class extends Computation {
|
|
|
771
817
|
this.L = void 0;
|
|
772
818
|
this.B?.();
|
|
773
819
|
this.B = void 0;
|
|
774
|
-
super.
|
|
820
|
+
super.z();
|
|
775
821
|
}
|
|
776
822
|
T() {
|
|
777
823
|
if (this.Q && this.a !== STATE_DISPOSED) {
|
|
778
824
|
this.B?.();
|
|
779
825
|
try {
|
|
780
|
-
this.B = this.K(this.
|
|
826
|
+
this.B = this.K(this.e, this.M);
|
|
781
827
|
} catch (e) {
|
|
782
828
|
this.handleError(e);
|
|
783
829
|
} finally {
|
|
784
|
-
this.M = this.
|
|
830
|
+
this.M = this.e;
|
|
785
831
|
this.Q = false;
|
|
786
832
|
}
|
|
787
833
|
}
|
|
@@ -793,7 +839,7 @@ var EagerComputation = class extends Computation {
|
|
|
793
839
|
!options?.defer && this.y();
|
|
794
840
|
}
|
|
795
841
|
q(state, skipQueue) {
|
|
796
|
-
if (this.a >= state && !this.
|
|
842
|
+
if (this.a >= state && !this.J)
|
|
797
843
|
return;
|
|
798
844
|
if (this.a === STATE_CLEAN && !skipQueue)
|
|
799
845
|
this.h.enqueue(EFFECT_PURE, this);
|
|
@@ -805,7 +851,7 @@ var ProjectionComputation = class extends Computation {
|
|
|
805
851
|
super(null, compute2);
|
|
806
852
|
}
|
|
807
853
|
q(state, skipQueue) {
|
|
808
|
-
if (this.a >= state && !this.
|
|
854
|
+
if (this.a >= state && !this.J)
|
|
809
855
|
return;
|
|
810
856
|
if (this.a === STATE_CLEAN && !skipQueue)
|
|
811
857
|
this.h.enqueue(EFFECT_PURE, this);
|
|
@@ -815,7 +861,7 @@ var ProjectionComputation = class extends Computation {
|
|
|
815
861
|
|
|
816
862
|
// src/core/suspense.ts
|
|
817
863
|
var SuspenseQueue = class extends Queue {
|
|
818
|
-
|
|
864
|
+
f = /* @__PURE__ */ new Set();
|
|
819
865
|
o = false;
|
|
820
866
|
S = new Computation(false, null);
|
|
821
867
|
run(type) {
|
|
@@ -824,15 +870,15 @@ var SuspenseQueue = class extends Queue {
|
|
|
824
870
|
return super.run(type);
|
|
825
871
|
}
|
|
826
872
|
R(node) {
|
|
827
|
-
if (node.
|
|
828
|
-
this.
|
|
873
|
+
if (node.d & LOADING_BIT) {
|
|
874
|
+
this.f.add(node);
|
|
829
875
|
if (!this.o) {
|
|
830
876
|
this.o = true;
|
|
831
877
|
this.S.write(true);
|
|
832
878
|
}
|
|
833
879
|
} else {
|
|
834
|
-
this.
|
|
835
|
-
if (this.
|
|
880
|
+
this.f.delete(node);
|
|
881
|
+
if (this.f.size === 0) {
|
|
836
882
|
this.o = false;
|
|
837
883
|
this.S.write(false);
|
|
838
884
|
}
|
|
@@ -841,13 +887,13 @@ var SuspenseQueue = class extends Queue {
|
|
|
841
887
|
};
|
|
842
888
|
var LiveComputation = class extends EagerComputation {
|
|
843
889
|
write(value, flags = 0) {
|
|
844
|
-
const currentFlags = this.
|
|
890
|
+
const currentFlags = this.d;
|
|
845
891
|
const dirty = this.a === STATE_DIRTY;
|
|
846
892
|
super.write(value, flags);
|
|
847
893
|
if (dirty && (flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
|
|
848
894
|
this.h.R?.(this);
|
|
849
895
|
}
|
|
850
|
-
return this.
|
|
896
|
+
return this.e;
|
|
851
897
|
}
|
|
852
898
|
};
|
|
853
899
|
function createSuspense(fn, fallback) {
|
|
@@ -887,10 +933,10 @@ function createMemo(compute2, value, options) {
|
|
|
887
933
|
return () => {
|
|
888
934
|
if (node) {
|
|
889
935
|
resolvedValue = node.wait();
|
|
890
|
-
if (!node.
|
|
936
|
+
if (!node.b?.length && node.n?.s !== node) {
|
|
891
937
|
node.dispose();
|
|
892
938
|
node = void 0;
|
|
893
|
-
} else if (!node.s && !node.
|
|
939
|
+
} else if (!node.s && !node.c?.length) {
|
|
894
940
|
node.dispose();
|
|
895
941
|
node.a = STATE_DIRTY;
|
|
896
942
|
}
|
|
@@ -902,10 +948,10 @@ function createAsync(compute2, value, options) {
|
|
|
902
948
|
let uninitialized = value === void 0;
|
|
903
949
|
const lhs = new EagerComputation(
|
|
904
950
|
{
|
|
905
|
-
|
|
951
|
+
e: value
|
|
906
952
|
},
|
|
907
953
|
(p) => {
|
|
908
|
-
const value2 = p?.
|
|
954
|
+
const value2 = p?.e;
|
|
909
955
|
const source = compute2(value2);
|
|
910
956
|
const isPromise = source instanceof Promise;
|
|
911
957
|
const iterator = source[Symbol.asyncIterator];
|
|
@@ -914,13 +960,13 @@ function createAsync(compute2, value, options) {
|
|
|
914
960
|
wait() {
|
|
915
961
|
return source;
|
|
916
962
|
},
|
|
917
|
-
|
|
963
|
+
e: source
|
|
918
964
|
};
|
|
919
965
|
}
|
|
920
966
|
const signal = new Computation(value2, null, options);
|
|
921
967
|
const w = signal.wait;
|
|
922
968
|
signal.wait = function() {
|
|
923
|
-
if (signal.
|
|
969
|
+
if (signal.d & ERROR_BIT && signal.x <= getClock()) {
|
|
924
970
|
lhs.q(STATE_DIRTY);
|
|
925
971
|
throw new NotReadyError();
|
|
926
972
|
}
|
|
@@ -935,7 +981,7 @@ function createAsync(compute2, value, options) {
|
|
|
935
981
|
},
|
|
936
982
|
(error) => {
|
|
937
983
|
uninitialized = true;
|
|
938
|
-
signal.
|
|
984
|
+
signal.F(error);
|
|
939
985
|
}
|
|
940
986
|
);
|
|
941
987
|
} else {
|
|
@@ -964,13 +1010,13 @@ function createEffect(compute2, effect, error, value, options) {
|
|
|
964
1010
|
compute2,
|
|
965
1011
|
effect,
|
|
966
1012
|
error,
|
|
967
|
-
|
|
1013
|
+
options
|
|
968
1014
|
);
|
|
969
1015
|
}
|
|
970
1016
|
function createRenderEffect(compute2, effect, value, options) {
|
|
971
1017
|
void new Effect(value, compute2, effect, void 0, {
|
|
972
1018
|
render: true,
|
|
973
|
-
...
|
|
1019
|
+
...options
|
|
974
1020
|
});
|
|
975
1021
|
}
|
|
976
1022
|
function createRoot(init) {
|
|
@@ -978,12 +1024,7 @@ function createRoot(init) {
|
|
|
978
1024
|
return compute(owner, !init.length ? init : () => init(() => owner.dispose()), null);
|
|
979
1025
|
}
|
|
980
1026
|
function runWithOwner(owner, run) {
|
|
981
|
-
|
|
982
|
-
return compute(owner, run, null);
|
|
983
|
-
} catch (error) {
|
|
984
|
-
owner?.handleError(error);
|
|
985
|
-
return void 0;
|
|
986
|
-
}
|
|
1027
|
+
return compute(owner, run, null);
|
|
987
1028
|
}
|
|
988
1029
|
function createErrorBoundary(fn, fallback) {
|
|
989
1030
|
const owner = new Owner();
|
|
@@ -1011,7 +1052,7 @@ function createErrorBoundary(fn, fallback) {
|
|
|
1011
1052
|
() => {
|
|
1012
1053
|
const c = new Computation(void 0, fn);
|
|
1013
1054
|
const f = new EagerComputation(void 0, () => flatten(c.read()), { defer: true });
|
|
1014
|
-
f.
|
|
1055
|
+
f.F = function(error2) {
|
|
1015
1056
|
this.handleError(error2);
|
|
1016
1057
|
};
|
|
1017
1058
|
return f;
|
|
@@ -1028,7 +1069,7 @@ function createErrorBoundary(fn, fallback) {
|
|
|
1028
1069
|
incrementClock();
|
|
1029
1070
|
for (let node of nodes) {
|
|
1030
1071
|
node.a = STATE_DIRTY;
|
|
1031
|
-
node.h?.enqueue(node.
|
|
1072
|
+
node.h?.enqueue(node.u, node);
|
|
1032
1073
|
}
|
|
1033
1074
|
});
|
|
1034
1075
|
});
|
|
@@ -1050,19 +1091,6 @@ function resolve(fn) {
|
|
|
1050
1091
|
});
|
|
1051
1092
|
});
|
|
1052
1093
|
}
|
|
1053
|
-
function createReaction(effect, error, options) {
|
|
1054
|
-
const node = new Effect(void 0, () => {
|
|
1055
|
-
}, effect, error, {
|
|
1056
|
-
defer: true,
|
|
1057
|
-
...void 0
|
|
1058
|
-
});
|
|
1059
|
-
return (tracking) => {
|
|
1060
|
-
node.u = tracking;
|
|
1061
|
-
node.a = STATE_DIRTY;
|
|
1062
|
-
node.y();
|
|
1063
|
-
node.u = null;
|
|
1064
|
-
};
|
|
1065
|
-
}
|
|
1066
1094
|
|
|
1067
1095
|
// src/store/projection.ts
|
|
1068
1096
|
function createProjection(fn, initialValue = {}) {
|
|
@@ -1209,7 +1237,7 @@ var proxyTraps = {
|
|
|
1209
1237
|
return desc.get.call(receiver);
|
|
1210
1238
|
}
|
|
1211
1239
|
if (Writing.has(storeValue)) {
|
|
1212
|
-
const value2 = tracked ? tracked.
|
|
1240
|
+
const value2 = tracked ? tracked.e : storeValue[property];
|
|
1213
1241
|
return isWrappable(value2) ? (Writing.add(value2[$RAW] || value2), wrap2(value2)) : value2;
|
|
1214
1242
|
}
|
|
1215
1243
|
let value = tracked ? nodes[property].read() : storeValue[property];
|
|
@@ -1548,13 +1576,13 @@ function omit(props, ...keys) {
|
|
|
1548
1576
|
function mapArray(list, map, options) {
|
|
1549
1577
|
const keyFn = typeof options?.keyed === "function" ? options.keyed : void 0;
|
|
1550
1578
|
return updateKeyedMap.bind({
|
|
1551
|
-
|
|
1579
|
+
G: new Owner(),
|
|
1552
1580
|
i: 0,
|
|
1553
1581
|
X: list,
|
|
1554
|
-
|
|
1555
|
-
|
|
1582
|
+
w: [],
|
|
1583
|
+
H: map,
|
|
1556
1584
|
g: [],
|
|
1557
|
-
|
|
1585
|
+
f: [],
|
|
1558
1586
|
C: keyFn,
|
|
1559
1587
|
j: keyFn || options?.keyed === false ? [] : void 0,
|
|
1560
1588
|
k: map.length > 1 ? [] : void 0,
|
|
@@ -1564,27 +1592,27 @@ function mapArray(list, map, options) {
|
|
|
1564
1592
|
function updateKeyedMap() {
|
|
1565
1593
|
const newItems = this.X() || [], newLen = newItems.length;
|
|
1566
1594
|
newItems[$TRACK];
|
|
1567
|
-
runWithOwner(this.
|
|
1595
|
+
runWithOwner(this.G, () => {
|
|
1568
1596
|
let i, j, mapper = this.j ? () => {
|
|
1569
1597
|
this.j[j] = new Computation(newItems[j], null);
|
|
1570
1598
|
this.k && (this.k[j] = new Computation(j, null));
|
|
1571
|
-
return this.
|
|
1599
|
+
return this.H(
|
|
1572
1600
|
Computation.prototype.read.bind(this.j[j]),
|
|
1573
1601
|
this.k ? Computation.prototype.read.bind(this.k[j]) : void 0
|
|
1574
1602
|
);
|
|
1575
1603
|
} : this.k ? () => {
|
|
1576
1604
|
const item = newItems[j];
|
|
1577
1605
|
this.k[j] = new Computation(j, null);
|
|
1578
|
-
return this.
|
|
1606
|
+
return this.H(() => item, Computation.prototype.read.bind(this.k[j]));
|
|
1579
1607
|
} : () => {
|
|
1580
1608
|
const item = newItems[j];
|
|
1581
|
-
return this.
|
|
1609
|
+
return this.H(() => item);
|
|
1582
1610
|
};
|
|
1583
1611
|
if (newLen === 0) {
|
|
1584
1612
|
if (this.i !== 0) {
|
|
1585
|
-
this.
|
|
1586
|
-
this.
|
|
1587
|
-
this.
|
|
1613
|
+
this.G.dispose(false);
|
|
1614
|
+
this.f = [];
|
|
1615
|
+
this.w = [];
|
|
1588
1616
|
this.g = [];
|
|
1589
1617
|
this.i = 0;
|
|
1590
1618
|
this.j && (this.j = []);
|
|
@@ -1592,29 +1620,29 @@ function updateKeyedMap() {
|
|
|
1592
1620
|
}
|
|
1593
1621
|
if (this.o && !this.g[0]) {
|
|
1594
1622
|
this.g[0] = compute(
|
|
1595
|
-
this.
|
|
1623
|
+
this.f[0] = new Owner(),
|
|
1596
1624
|
this.o,
|
|
1597
1625
|
null
|
|
1598
1626
|
);
|
|
1599
1627
|
}
|
|
1600
1628
|
} else if (this.i === 0) {
|
|
1601
|
-
if (this.
|
|
1602
|
-
this.
|
|
1629
|
+
if (this.f[0])
|
|
1630
|
+
this.f[0].dispose();
|
|
1603
1631
|
this.g = new Array(newLen);
|
|
1604
1632
|
for (j = 0; j < newLen; j++) {
|
|
1605
|
-
this.
|
|
1606
|
-
this.g[j] = compute(this.
|
|
1633
|
+
this.w[j] = newItems[j];
|
|
1634
|
+
this.g[j] = compute(this.f[j] = new Owner(), mapper, null);
|
|
1607
1635
|
}
|
|
1608
1636
|
this.i = newLen;
|
|
1609
1637
|
} else {
|
|
1610
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;
|
|
1611
|
-
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++) {
|
|
1612
1640
|
if (this.j)
|
|
1613
1641
|
this.j[start].write(newItems[start]);
|
|
1614
1642
|
}
|
|
1615
|
-
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--) {
|
|
1616
1644
|
temp[newEnd] = this.g[end];
|
|
1617
|
-
tempNodes[newEnd] = this.
|
|
1645
|
+
tempNodes[newEnd] = this.f[end];
|
|
1618
1646
|
tempRows && (tempRows[newEnd] = this.j[end]);
|
|
1619
1647
|
tempIndexes && (tempIndexes[newEnd] = this.k[end]);
|
|
1620
1648
|
}
|
|
@@ -1628,23 +1656,23 @@ function updateKeyedMap() {
|
|
|
1628
1656
|
newIndices.set(key, j);
|
|
1629
1657
|
}
|
|
1630
1658
|
for (i = start; i <= end; i++) {
|
|
1631
|
-
item = this.
|
|
1659
|
+
item = this.w[i];
|
|
1632
1660
|
key = this.C ? this.C(item) : item;
|
|
1633
1661
|
j = newIndices.get(key);
|
|
1634
1662
|
if (j !== void 0 && j !== -1) {
|
|
1635
1663
|
temp[j] = this.g[i];
|
|
1636
|
-
tempNodes[j] = this.
|
|
1664
|
+
tempNodes[j] = this.f[i];
|
|
1637
1665
|
tempRows && (tempRows[j] = this.j[i]);
|
|
1638
1666
|
tempIndexes && (tempIndexes[j] = this.k[i]);
|
|
1639
1667
|
j = newIndicesNext[j];
|
|
1640
1668
|
newIndices.set(key, j);
|
|
1641
1669
|
} else
|
|
1642
|
-
this.
|
|
1670
|
+
this.f[i].dispose();
|
|
1643
1671
|
}
|
|
1644
1672
|
for (j = start; j < newLen; j++) {
|
|
1645
1673
|
if (j in temp) {
|
|
1646
1674
|
this.g[j] = temp[j];
|
|
1647
|
-
this.
|
|
1675
|
+
this.f[j] = tempNodes[j];
|
|
1648
1676
|
if (tempRows) {
|
|
1649
1677
|
this.j[j] = tempRows[j];
|
|
1650
1678
|
this.j[j].write(newItems[j]);
|
|
@@ -1654,55 +1682,55 @@ function updateKeyedMap() {
|
|
|
1654
1682
|
this.k[j].write(j);
|
|
1655
1683
|
}
|
|
1656
1684
|
} else {
|
|
1657
|
-
this.g[j] = compute(this.
|
|
1685
|
+
this.g[j] = compute(this.f[j] = new Owner(), mapper, null);
|
|
1658
1686
|
}
|
|
1659
1687
|
}
|
|
1660
1688
|
this.g = this.g.slice(0, this.i = newLen);
|
|
1661
|
-
this.
|
|
1689
|
+
this.w = newItems.slice(0);
|
|
1662
1690
|
}
|
|
1663
1691
|
});
|
|
1664
1692
|
return this.g;
|
|
1665
1693
|
}
|
|
1666
1694
|
function repeat(count, map, options) {
|
|
1667
1695
|
return updateRepeat.bind({
|
|
1668
|
-
|
|
1696
|
+
G: new Owner(),
|
|
1669
1697
|
i: 0,
|
|
1670
1698
|
Y: count,
|
|
1671
|
-
|
|
1672
|
-
|
|
1699
|
+
H: map,
|
|
1700
|
+
f: [],
|
|
1673
1701
|
g: [],
|
|
1674
1702
|
o: options?.fallback
|
|
1675
1703
|
});
|
|
1676
1704
|
}
|
|
1677
1705
|
function updateRepeat() {
|
|
1678
1706
|
const newLen = this.Y();
|
|
1679
|
-
runWithOwner(this.
|
|
1707
|
+
runWithOwner(this.G, () => {
|
|
1680
1708
|
if (newLen === 0) {
|
|
1681
1709
|
if (this.i !== 0) {
|
|
1682
|
-
this.
|
|
1683
|
-
this.
|
|
1710
|
+
this.G.dispose(false);
|
|
1711
|
+
this.f = [];
|
|
1684
1712
|
this.g = [];
|
|
1685
1713
|
this.i = 0;
|
|
1686
1714
|
}
|
|
1687
1715
|
if (this.o && !this.g[0]) {
|
|
1688
1716
|
this.g[0] = compute(
|
|
1689
|
-
this.
|
|
1717
|
+
this.f[0] = new Owner(),
|
|
1690
1718
|
this.o,
|
|
1691
1719
|
null
|
|
1692
1720
|
);
|
|
1693
1721
|
}
|
|
1694
1722
|
} else {
|
|
1695
|
-
if (this.i === 0 && this.
|
|
1696
|
-
this.
|
|
1723
|
+
if (this.i === 0 && this.f[0])
|
|
1724
|
+
this.f[0].dispose();
|
|
1697
1725
|
for (let i = this.i; i < newLen; i++) {
|
|
1698
1726
|
this.g[i] = compute(
|
|
1699
|
-
this.
|
|
1700
|
-
() => this.
|
|
1727
|
+
this.f[i] = new Owner(),
|
|
1728
|
+
() => this.H(i),
|
|
1701
1729
|
null
|
|
1702
1730
|
);
|
|
1703
1731
|
}
|
|
1704
1732
|
for (let i = newLen; i < this.i; i++)
|
|
1705
|
-
this.
|
|
1733
|
+
this.f[i].dispose();
|
|
1706
1734
|
this.g = this.g.slice(0, newLen);
|
|
1707
1735
|
this.i = newLen;
|
|
1708
1736
|
}
|
|
@@ -1713,4 +1741,4 @@ function compare(key, a, b) {
|
|
|
1713
1741
|
return key ? key(a) === key(b) : true;
|
|
1714
1742
|
}
|
|
1715
1743
|
|
|
1716
|
-
export { $PROXY, $RAW, $TARGET, $TRACK, Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, SUPPORTS_PROXY, catchError, createAsync, createBoundary, createContext, createEffect, createErrorBoundary, createMemo, createProjection,
|
|
1744
|
+
export { $PROXY, $RAW, $TARGET, $TRACK, Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, SUPPORTS_PROXY, catchError, createAsync, createBoundary, createContext, createEffect, createErrorBoundary, createMemo, createProjection, createRenderEffect, createRoot, createSignal, createStore, createSuspense, flatten, flushSync, getContext, getObserver, getOwner, hasContext, hasUpdated, isEqual, isPending, isWrappable, latest, mapArray, merge, omit, onCleanup, reconcile, repeat, resolve, runWithObserver, runWithOwner, setContext, untrack, unwrap };
|