@solidjs/signals 0.0.3 → 0.0.4
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 +65 -40
- package/dist/node.cjs +113 -95
- package/dist/prod.js +112 -94
- package/dist/types/core/constants.d.ts +2 -1
- package/dist/types/core/owner.d.ts +7 -2
- package/dist/types/map.d.ts +1 -1
- package/dist/types/signals.d.ts +81 -18
- package/package.json +1 -1
package/dist/prod.js
CHANGED
|
@@ -25,7 +25,8 @@ function isUndefined(value) {
|
|
|
25
25
|
var STATE_CLEAN = 0;
|
|
26
26
|
var STATE_CHECK = 1;
|
|
27
27
|
var STATE_DIRTY = 2;
|
|
28
|
-
var
|
|
28
|
+
var STATE_UNINITIALIZED = 3;
|
|
29
|
+
var STATE_DISPOSED = 4;
|
|
29
30
|
var EFFECT_PURE = 0;
|
|
30
31
|
var EFFECT_RENDER = 1;
|
|
31
32
|
var EFFECT_USER = 2;
|
|
@@ -46,9 +47,9 @@ var Owner = class {
|
|
|
46
47
|
// We flatten the owner tree into a linked list so that we don't need a pointer to .firstChild
|
|
47
48
|
// However, the children are actually added in reverse creation order
|
|
48
49
|
// See comment at the top of the file for an example of the _nextSibling traversal
|
|
49
|
-
r = null;
|
|
50
|
-
m = null;
|
|
51
50
|
o = null;
|
|
51
|
+
m = null;
|
|
52
|
+
p = null;
|
|
52
53
|
a = STATE_CLEAN;
|
|
53
54
|
h = null;
|
|
54
55
|
n = defaultContext;
|
|
@@ -59,10 +60,10 @@ var Owner = class {
|
|
|
59
60
|
currentOwner.append(this);
|
|
60
61
|
}
|
|
61
62
|
append(child) {
|
|
62
|
-
child.r = this;
|
|
63
63
|
child.o = this;
|
|
64
|
+
child.p = this;
|
|
64
65
|
if (this.m)
|
|
65
|
-
this.m.
|
|
66
|
+
this.m.p = child;
|
|
66
67
|
child.m = this.m;
|
|
67
68
|
this.m = child;
|
|
68
69
|
if (child.n !== this.n) {
|
|
@@ -77,8 +78,8 @@ var Owner = class {
|
|
|
77
78
|
dispose(self = true) {
|
|
78
79
|
if (this.a === STATE_DISPOSED)
|
|
79
80
|
return;
|
|
80
|
-
let head = self ? this.
|
|
81
|
-
while (current && current.
|
|
81
|
+
let head = self ? this.p || this.o : this, current = this.m, next = null;
|
|
82
|
+
while (current && current.o === this) {
|
|
82
83
|
current.dispose(true);
|
|
83
84
|
current.x();
|
|
84
85
|
next = current.m;
|
|
@@ -88,15 +89,15 @@ var Owner = class {
|
|
|
88
89
|
if (self)
|
|
89
90
|
this.x();
|
|
90
91
|
if (current)
|
|
91
|
-
current.
|
|
92
|
+
current.p = !self ? this : this.p;
|
|
92
93
|
if (head)
|
|
93
94
|
head.m = current;
|
|
94
95
|
}
|
|
95
96
|
x() {
|
|
96
|
-
if (this.
|
|
97
|
-
this.
|
|
98
|
-
this.r = null;
|
|
97
|
+
if (this.p)
|
|
98
|
+
this.p.m = null;
|
|
99
99
|
this.o = null;
|
|
100
|
+
this.p = null;
|
|
100
101
|
this.n = defaultContext;
|
|
101
102
|
this.i = null;
|
|
102
103
|
this.a = STATE_DISPOSED;
|
|
@@ -156,17 +157,18 @@ function setContext(context, value, owner = currentOwner) {
|
|
|
156
157
|
function hasContext(context, owner = currentOwner) {
|
|
157
158
|
return !isUndefined(owner?.n[context.id]);
|
|
158
159
|
}
|
|
159
|
-
function onCleanup(
|
|
160
|
+
function onCleanup(fn) {
|
|
160
161
|
if (!currentOwner)
|
|
161
|
-
return;
|
|
162
|
+
return fn;
|
|
162
163
|
const node = currentOwner;
|
|
163
164
|
if (!node.h) {
|
|
164
|
-
node.h =
|
|
165
|
+
node.h = fn;
|
|
165
166
|
} else if (Array.isArray(node.h)) {
|
|
166
|
-
node.h.push(
|
|
167
|
+
node.h.push(fn);
|
|
167
168
|
} else {
|
|
168
|
-
node.h = [node.h,
|
|
169
|
+
node.h = [node.h, fn];
|
|
169
170
|
}
|
|
171
|
+
return fn;
|
|
170
172
|
}
|
|
171
173
|
|
|
172
174
|
// src/core/flags.ts
|
|
@@ -196,32 +198,32 @@ var Computation = class extends Owner {
|
|
|
196
198
|
b = null;
|
|
197
199
|
c = null;
|
|
198
200
|
d;
|
|
199
|
-
|
|
201
|
+
E;
|
|
200
202
|
// Used in __DEV__ mode, hopefully removed in production
|
|
201
203
|
V;
|
|
202
204
|
// Using false is an optimization as an alternative to _equals: () => false
|
|
203
205
|
// which could enable more efficient DIRTY notification
|
|
204
|
-
|
|
206
|
+
F = isEqual;
|
|
205
207
|
N;
|
|
206
208
|
/** Whether the computation is an error or has ancestors that are unresolved */
|
|
207
209
|
j = 0;
|
|
208
210
|
/** Which flags raised by sources are handled, vs. being passed through. */
|
|
209
211
|
A = DEFAULT_FLAGS;
|
|
210
|
-
F = null;
|
|
211
212
|
G = null;
|
|
212
|
-
H =
|
|
213
|
+
H = null;
|
|
214
|
+
I = -1;
|
|
213
215
|
constructor(initialValue, compute2, options) {
|
|
214
216
|
super(compute2 === null);
|
|
215
|
-
this.
|
|
216
|
-
this.a = compute2 ?
|
|
217
|
+
this.E = compute2;
|
|
218
|
+
this.a = compute2 ? STATE_UNINITIALIZED : STATE_CLEAN;
|
|
217
219
|
this.d = initialValue;
|
|
218
220
|
if (options?.equals !== void 0)
|
|
219
|
-
this.
|
|
221
|
+
this.F = options.equals;
|
|
220
222
|
if (options?.unobserved)
|
|
221
223
|
this.N = options?.unobserved;
|
|
222
224
|
}
|
|
223
225
|
O() {
|
|
224
|
-
if (this.
|
|
226
|
+
if (this.E)
|
|
225
227
|
this.s();
|
|
226
228
|
if (!this.b || this.b.length)
|
|
227
229
|
track(this);
|
|
@@ -260,30 +262,30 @@ var Computation = class extends Owner {
|
|
|
260
262
|
* loading state changes
|
|
261
263
|
*/
|
|
262
264
|
loading() {
|
|
263
|
-
if (this.
|
|
264
|
-
this.
|
|
265
|
+
if (this.H === null) {
|
|
266
|
+
this.H = loadingState(this);
|
|
265
267
|
}
|
|
266
|
-
return this.
|
|
268
|
+
return this.H.read();
|
|
267
269
|
}
|
|
268
270
|
/**
|
|
269
271
|
* Return true if the computation is the computation threw an error
|
|
270
272
|
* Triggers re-execution of the computation when the error state changes
|
|
271
273
|
*/
|
|
272
274
|
error() {
|
|
273
|
-
if (this.
|
|
274
|
-
this.
|
|
275
|
+
if (this.G === null) {
|
|
276
|
+
this.G = errorState(this);
|
|
275
277
|
}
|
|
276
|
-
return this.
|
|
278
|
+
return this.G.read();
|
|
277
279
|
}
|
|
278
280
|
/** Update the computation with a new value. */
|
|
279
281
|
write(value, flags = 0, raw = false) {
|
|
280
282
|
const newValue = !raw && typeof value === "function" ? value(this.d) : value;
|
|
281
|
-
const valueChanged = newValue !== UNCHANGED && (!!(flags & ERROR_BIT) || this.
|
|
283
|
+
const valueChanged = newValue !== UNCHANGED && (!!(flags & ERROR_BIT) || this.a === STATE_UNINITIALIZED || this.F === false || !this.F(this.d, newValue));
|
|
282
284
|
if (valueChanged)
|
|
283
285
|
this.d = newValue;
|
|
284
286
|
const changedFlagsMask = this.j ^ flags, changedFlags = changedFlagsMask & flags;
|
|
285
287
|
this.j = flags;
|
|
286
|
-
this.
|
|
288
|
+
this.I = clock + 1;
|
|
287
289
|
if (this.c) {
|
|
288
290
|
for (let i = 0; i < this.c.length; i++) {
|
|
289
291
|
if (valueChanged) {
|
|
@@ -363,7 +365,7 @@ var Computation = class extends Owner {
|
|
|
363
365
|
}
|
|
364
366
|
}
|
|
365
367
|
}
|
|
366
|
-
if (this.a === STATE_DIRTY) {
|
|
368
|
+
if (this.a === STATE_DIRTY || this.a === STATE_UNINITIALIZED) {
|
|
367
369
|
update(this);
|
|
368
370
|
} else {
|
|
369
371
|
this.write(UNCHANGED, observerFlags);
|
|
@@ -382,7 +384,7 @@ var Computation = class extends Owner {
|
|
|
382
384
|
}
|
|
383
385
|
};
|
|
384
386
|
function loadingState(node) {
|
|
385
|
-
const prevOwner = setOwner(node.
|
|
387
|
+
const prevOwner = setOwner(node.o);
|
|
386
388
|
const options = void 0;
|
|
387
389
|
const computation = new Computation(
|
|
388
390
|
void 0,
|
|
@@ -398,7 +400,7 @@ function loadingState(node) {
|
|
|
398
400
|
return computation;
|
|
399
401
|
}
|
|
400
402
|
function errorState(node) {
|
|
401
|
-
const prevOwner = setOwner(node.
|
|
403
|
+
const prevOwner = setOwner(node.o);
|
|
402
404
|
const options = void 0;
|
|
403
405
|
const computation = new Computation(
|
|
404
406
|
void 0,
|
|
@@ -423,7 +425,7 @@ function track(computation) {
|
|
|
423
425
|
newSources.push(computation);
|
|
424
426
|
}
|
|
425
427
|
if (updateCheck) {
|
|
426
|
-
updateCheck.d = computation.
|
|
428
|
+
updateCheck.d = computation.I > currentObserver.I;
|
|
427
429
|
}
|
|
428
430
|
}
|
|
429
431
|
}
|
|
@@ -435,7 +437,7 @@ function update(node) {
|
|
|
435
437
|
try {
|
|
436
438
|
node.dispose(false);
|
|
437
439
|
node.emptyDisposal();
|
|
438
|
-
const result = compute(node, node.
|
|
440
|
+
const result = compute(node, node.E, node);
|
|
439
441
|
node.write(result, newFlags, true);
|
|
440
442
|
} catch (error) {
|
|
441
443
|
if (error instanceof NotReadyError) {
|
|
@@ -543,10 +545,11 @@ function schedule() {
|
|
|
543
545
|
if (scheduled)
|
|
544
546
|
return;
|
|
545
547
|
scheduled = true;
|
|
546
|
-
|
|
548
|
+
if (!globalQueue.B)
|
|
549
|
+
queueMicrotask(flushSync);
|
|
547
550
|
}
|
|
548
551
|
var Queue = class {
|
|
549
|
-
|
|
552
|
+
B = false;
|
|
550
553
|
u = [[], [], []];
|
|
551
554
|
z = [];
|
|
552
555
|
enqueue(type, node) {
|
|
@@ -571,16 +574,17 @@ var Queue = class {
|
|
|
571
574
|
}
|
|
572
575
|
}
|
|
573
576
|
flush() {
|
|
574
|
-
if (this.
|
|
577
|
+
if (this.B)
|
|
575
578
|
return;
|
|
576
|
-
this.
|
|
579
|
+
this.B = true;
|
|
577
580
|
try {
|
|
578
581
|
this.run(EFFECT_PURE);
|
|
579
582
|
incrementClock();
|
|
583
|
+
scheduled = false;
|
|
580
584
|
this.run(EFFECT_RENDER);
|
|
581
585
|
this.run(EFFECT_USER);
|
|
582
586
|
} finally {
|
|
583
|
-
this.
|
|
587
|
+
this.B = false;
|
|
584
588
|
}
|
|
585
589
|
}
|
|
586
590
|
addChild(child) {
|
|
@@ -594,8 +598,9 @@ var Queue = class {
|
|
|
594
598
|
};
|
|
595
599
|
var globalQueue = new Queue();
|
|
596
600
|
function flushSync() {
|
|
597
|
-
|
|
598
|
-
|
|
601
|
+
while (scheduled) {
|
|
602
|
+
globalQueue.flush();
|
|
603
|
+
}
|
|
599
604
|
}
|
|
600
605
|
function createBoundary(fn, queue) {
|
|
601
606
|
const owner = new Owner();
|
|
@@ -606,7 +611,7 @@ function createBoundary(fn, queue) {
|
|
|
606
611
|
}
|
|
607
612
|
function runTop(node) {
|
|
608
613
|
const ancestors = [];
|
|
609
|
-
for (let current = node; current !== null; current = current.
|
|
614
|
+
for (let current = node; current !== null; current = current.o) {
|
|
610
615
|
if (current.a !== STATE_CLEAN) {
|
|
611
616
|
ancestors.push(current);
|
|
612
617
|
}
|
|
@@ -631,17 +636,17 @@ function runEffectQueue(queue) {
|
|
|
631
636
|
var Effect = class extends Computation {
|
|
632
637
|
J;
|
|
633
638
|
K = false;
|
|
634
|
-
B;
|
|
635
639
|
C;
|
|
640
|
+
D;
|
|
636
641
|
e;
|
|
637
642
|
constructor(initialValue, compute2, effect, options) {
|
|
638
643
|
super(initialValue, compute2, options);
|
|
639
644
|
this.J = effect;
|
|
640
|
-
this.
|
|
641
|
-
this.
|
|
645
|
+
this.C = initialValue;
|
|
646
|
+
this.D = options?.render ? EFFECT_RENDER : EFFECT_USER;
|
|
642
647
|
this.e = getOwner()?.e || globalQueue;
|
|
643
648
|
this.s();
|
|
644
|
-
this.
|
|
649
|
+
this.D === EFFECT_USER ? this.e.enqueue(this.D, this) : this.R();
|
|
645
650
|
}
|
|
646
651
|
write(value, flags = 0) {
|
|
647
652
|
const currentFlags = this.j;
|
|
@@ -659,7 +664,7 @@ var Effect = class extends Computation {
|
|
|
659
664
|
if (this.a >= state)
|
|
660
665
|
return;
|
|
661
666
|
if (this.a === STATE_CLEAN)
|
|
662
|
-
this.e.enqueue(this.
|
|
667
|
+
this.e.enqueue(this.D, this);
|
|
663
668
|
this.a = state;
|
|
664
669
|
}
|
|
665
670
|
Q(error) {
|
|
@@ -667,13 +672,13 @@ var Effect = class extends Computation {
|
|
|
667
672
|
}
|
|
668
673
|
x() {
|
|
669
674
|
this.J = void 0;
|
|
670
|
-
this.
|
|
675
|
+
this.C = void 0;
|
|
671
676
|
super.x();
|
|
672
677
|
}
|
|
673
678
|
R() {
|
|
674
679
|
if (this.K && this.a !== STATE_DISPOSED) {
|
|
675
|
-
this.J(this.d, this.
|
|
676
|
-
this.
|
|
680
|
+
this.J(this.d, this.C);
|
|
681
|
+
this.C = this.d;
|
|
677
682
|
this.K = false;
|
|
678
683
|
}
|
|
679
684
|
}
|
|
@@ -697,24 +702,24 @@ var EagerComputation = class extends Computation {
|
|
|
697
702
|
// src/core/suspense.ts
|
|
698
703
|
var SuspenseQueue = class extends Queue {
|
|
699
704
|
f = /* @__PURE__ */ new Set();
|
|
700
|
-
|
|
705
|
+
q = false;
|
|
701
706
|
L = new Computation(false, null);
|
|
702
707
|
run(type) {
|
|
703
|
-
if (type && this.
|
|
708
|
+
if (type && this.q)
|
|
704
709
|
return;
|
|
705
710
|
super.run(type);
|
|
706
711
|
}
|
|
707
712
|
T(node) {
|
|
708
713
|
if (node.j & LOADING_BIT) {
|
|
709
714
|
this.f.add(node);
|
|
710
|
-
if (!this.
|
|
711
|
-
this.
|
|
715
|
+
if (!this.q) {
|
|
716
|
+
this.q = true;
|
|
712
717
|
queueMicrotask(() => this.L.write(true));
|
|
713
718
|
}
|
|
714
719
|
} else {
|
|
715
720
|
this.f.delete(node);
|
|
716
721
|
if (this.f.size === 0) {
|
|
717
|
-
this.
|
|
722
|
+
this.q = false;
|
|
718
723
|
queueMicrotask(() => this.L.write(false));
|
|
719
724
|
}
|
|
720
725
|
}
|
|
@@ -723,7 +728,7 @@ var SuspenseQueue = class extends Queue {
|
|
|
723
728
|
function createSuspense(fn, fallbackFn) {
|
|
724
729
|
const queue = new SuspenseQueue();
|
|
725
730
|
const tree = createBoundary(fn, queue);
|
|
726
|
-
const equality = new Computation(null, () => queue.L.read() || queue.
|
|
731
|
+
const equality = new Computation(null, () => queue.L.read() || queue.q);
|
|
727
732
|
const comp = new Computation(null, () => equality.read() ? untrack(fallbackFn) : tree);
|
|
728
733
|
return comp.read.bind(comp);
|
|
729
734
|
}
|
|
@@ -744,14 +749,35 @@ function createSignal(first, second, third) {
|
|
|
744
749
|
const node = new Computation(first, null, second);
|
|
745
750
|
return [node.read.bind(node), node.write.bind(node)];
|
|
746
751
|
}
|
|
747
|
-
function
|
|
752
|
+
function createMemo(compute2, value, options) {
|
|
753
|
+
let node = new Computation(
|
|
754
|
+
value,
|
|
755
|
+
compute2,
|
|
756
|
+
options
|
|
757
|
+
);
|
|
758
|
+
let resolvedValue;
|
|
759
|
+
return () => {
|
|
760
|
+
if (node) {
|
|
761
|
+
resolvedValue = node.wait();
|
|
762
|
+
if (!node.b?.length) {
|
|
763
|
+
node.dispose();
|
|
764
|
+
node = void 0;
|
|
765
|
+
} else if (!node.o && !node.c?.length) {
|
|
766
|
+
node.dispose();
|
|
767
|
+
node.a = STATE_UNINITIALIZED;
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
return resolvedValue;
|
|
771
|
+
};
|
|
772
|
+
}
|
|
773
|
+
function createAsync(compute2, value, options) {
|
|
748
774
|
const lhs = new EagerComputation(
|
|
749
775
|
{
|
|
750
|
-
d:
|
|
776
|
+
d: value
|
|
751
777
|
},
|
|
752
778
|
(p) => {
|
|
753
|
-
const
|
|
754
|
-
const source =
|
|
779
|
+
const value2 = p?.d;
|
|
780
|
+
const source = compute2(value2);
|
|
755
781
|
const isPromise = source instanceof Promise;
|
|
756
782
|
const iterator = source[Symbol.asyncIterator];
|
|
757
783
|
if (!isPromise && !iterator) {
|
|
@@ -762,12 +788,12 @@ function createAsync(fn, initial, options) {
|
|
|
762
788
|
d: source
|
|
763
789
|
};
|
|
764
790
|
}
|
|
765
|
-
const signal = new Computation(
|
|
791
|
+
const signal = new Computation(value2, null, options);
|
|
766
792
|
signal.write(UNCHANGED, LOADING_BIT);
|
|
767
793
|
if (isPromise) {
|
|
768
794
|
source.then(
|
|
769
|
-
(
|
|
770
|
-
signal.write(
|
|
795
|
+
(value3) => {
|
|
796
|
+
signal.write(value3, 0);
|
|
771
797
|
},
|
|
772
798
|
(error) => {
|
|
773
799
|
signal.write(error, ERROR_BIT);
|
|
@@ -778,10 +804,10 @@ function createAsync(fn, initial, options) {
|
|
|
778
804
|
onCleanup(() => abort = true);
|
|
779
805
|
(async () => {
|
|
780
806
|
try {
|
|
781
|
-
for await (let
|
|
807
|
+
for await (let value3 of source) {
|
|
782
808
|
if (abort)
|
|
783
809
|
return;
|
|
784
|
-
signal.write(
|
|
810
|
+
signal.write(value3, 0);
|
|
785
811
|
}
|
|
786
812
|
} catch (error) {
|
|
787
813
|
signal.write(error, ERROR_BIT);
|
|
@@ -793,28 +819,16 @@ function createAsync(fn, initial, options) {
|
|
|
793
819
|
);
|
|
794
820
|
return () => lhs.wait().wait();
|
|
795
821
|
}
|
|
796
|
-
function
|
|
797
|
-
let node = new Computation(initialValue, compute2, options);
|
|
798
|
-
let value;
|
|
799
|
-
return () => {
|
|
800
|
-
if (node) {
|
|
801
|
-
value = node.wait();
|
|
802
|
-
if (!node.b?.length)
|
|
803
|
-
node = void 0;
|
|
804
|
-
}
|
|
805
|
-
return value;
|
|
806
|
-
};
|
|
807
|
-
}
|
|
808
|
-
function createEffect(compute2, effect, initialValue, options) {
|
|
822
|
+
function createEffect(compute2, effect, value, options) {
|
|
809
823
|
void new Effect(
|
|
810
|
-
|
|
824
|
+
value,
|
|
811
825
|
compute2,
|
|
812
826
|
effect,
|
|
813
827
|
void 0
|
|
814
828
|
);
|
|
815
829
|
}
|
|
816
|
-
function createRenderEffect(compute2, effect,
|
|
817
|
-
void new Effect(
|
|
830
|
+
function createRenderEffect(compute2, effect, value, options) {
|
|
831
|
+
void new Effect(value, compute2, effect, {
|
|
818
832
|
render: true,
|
|
819
833
|
...void 0
|
|
820
834
|
});
|
|
@@ -1303,14 +1317,14 @@ function mapArray(list, map, options) {
|
|
|
1303
1317
|
S: new Owner(),
|
|
1304
1318
|
w: 0,
|
|
1305
1319
|
U: list,
|
|
1306
|
-
|
|
1320
|
+
r: [],
|
|
1307
1321
|
M: map,
|
|
1308
1322
|
k: [],
|
|
1309
1323
|
f: [],
|
|
1310
1324
|
y: keyFn,
|
|
1311
1325
|
g: keyFn || options?.keyed === false ? [] : void 0,
|
|
1312
1326
|
l: map.length > 1 ? [] : void 0,
|
|
1313
|
-
|
|
1327
|
+
q: options?.fallback
|
|
1314
1328
|
});
|
|
1315
1329
|
}
|
|
1316
1330
|
function updateKeyedMap() {
|
|
@@ -1336,31 +1350,35 @@ function updateKeyedMap() {
|
|
|
1336
1350
|
if (this.w !== 0) {
|
|
1337
1351
|
this.S.dispose(false);
|
|
1338
1352
|
this.f = [];
|
|
1339
|
-
this.
|
|
1353
|
+
this.r = [];
|
|
1340
1354
|
this.k = [];
|
|
1341
1355
|
this.w = 0;
|
|
1342
1356
|
this.g && (this.g = []);
|
|
1343
1357
|
this.l && (this.l = []);
|
|
1344
1358
|
}
|
|
1345
|
-
if (this.
|
|
1346
|
-
this.k[0] = compute(
|
|
1359
|
+
if (this.q && !this.k[0]) {
|
|
1360
|
+
this.k[0] = compute(
|
|
1361
|
+
this.f[0] = new Owner(),
|
|
1362
|
+
this.q,
|
|
1363
|
+
null
|
|
1364
|
+
);
|
|
1347
1365
|
}
|
|
1348
1366
|
} else if (this.w === 0) {
|
|
1349
1367
|
if (this.f[0])
|
|
1350
1368
|
this.f[0].dispose();
|
|
1351
1369
|
this.k = new Array(newLen);
|
|
1352
1370
|
for (j = 0; j < newLen; j++) {
|
|
1353
|
-
this.
|
|
1371
|
+
this.r[j] = newItems[j];
|
|
1354
1372
|
this.k[j] = compute(this.f[j] = new Owner(), mapper, null);
|
|
1355
1373
|
}
|
|
1356
1374
|
this.w = newLen;
|
|
1357
1375
|
} else {
|
|
1358
1376
|
let start, end, newEnd, item, key, newIndices, newIndicesNext, temp = new Array(newLen), tempNodes = new Array(newLen), tempRows = this.g ? new Array(newLen) : void 0, tempIndexes = this.l ? new Array(newLen) : void 0;
|
|
1359
|
-
for (start = 0, end = Math.min(this.w, newLen); start < end && (this.
|
|
1377
|
+
for (start = 0, end = Math.min(this.w, newLen); start < end && (this.r[start] === newItems[start] || this.g && compare(this.y, this.r[start], newItems[start])); start++) {
|
|
1360
1378
|
if (this.g)
|
|
1361
1379
|
this.g[start].write(newItems[start]);
|
|
1362
1380
|
}
|
|
1363
|
-
for (end = this.w - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.
|
|
1381
|
+
for (end = this.w - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.r[end] === newItems[newEnd] || this.g && compare(this.y, this.r[end], newItems[newEnd])); end--, newEnd--) {
|
|
1364
1382
|
temp[newEnd] = this.k[end];
|
|
1365
1383
|
tempNodes[newEnd] = this.f[end];
|
|
1366
1384
|
tempRows && (tempRows[newEnd] = this.g[end]);
|
|
@@ -1376,7 +1394,7 @@ function updateKeyedMap() {
|
|
|
1376
1394
|
newIndices.set(key, j);
|
|
1377
1395
|
}
|
|
1378
1396
|
for (i = start; i <= end; i++) {
|
|
1379
|
-
item = this.
|
|
1397
|
+
item = this.r[i];
|
|
1380
1398
|
key = this.y ? this.y(item) : item;
|
|
1381
1399
|
j = newIndices.get(key);
|
|
1382
1400
|
if (j !== void 0 && j !== -1) {
|
|
@@ -1406,7 +1424,7 @@ function updateKeyedMap() {
|
|
|
1406
1424
|
}
|
|
1407
1425
|
}
|
|
1408
1426
|
this.k = this.k.slice(0, this.w = newLen);
|
|
1409
|
-
this.
|
|
1427
|
+
this.r = newItems.slice(0);
|
|
1410
1428
|
}
|
|
1411
1429
|
});
|
|
1412
1430
|
return this.k;
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
export declare const STATE_CLEAN = 0;
|
|
8
8
|
export declare const STATE_CHECK = 1;
|
|
9
9
|
export declare const STATE_DIRTY = 2;
|
|
10
|
-
export declare const
|
|
10
|
+
export declare const STATE_UNINITIALIZED = 3;
|
|
11
|
+
export declare const STATE_DISPOSED = 4;
|
|
11
12
|
export declare const EFFECT_PURE = 0;
|
|
12
13
|
export declare const EFFECT_RENDER = 1;
|
|
13
14
|
export declare const EFFECT_USER = 2;
|
|
@@ -85,6 +85,11 @@ export declare function setContext<T>(context: Context<T>, value?: T, owner?: Ow
|
|
|
85
85
|
*/
|
|
86
86
|
export declare function hasContext(context: Context<any>, owner?: Owner | null): boolean;
|
|
87
87
|
/**
|
|
88
|
-
* Runs
|
|
88
|
+
* Runs an effect once before the reactive scope is disposed
|
|
89
|
+
* @param fn an effect that should run only once on cleanup
|
|
90
|
+
*
|
|
91
|
+
* @returns the same {@link fn} function that was passed in
|
|
92
|
+
*
|
|
93
|
+
* @description https://docs.solidjs.com/reference/lifecycle/on-cleanup
|
|
89
94
|
*/
|
|
90
|
-
export declare function onCleanup(
|
|
95
|
+
export declare function onCleanup(fn: Disposable): Disposable;
|
package/dist/types/map.d.ts
CHANGED
|
@@ -9,5 +9,5 @@ export type Maybe<T> = T | void | null | undefined | false;
|
|
|
9
9
|
*/
|
|
10
10
|
export declare function mapArray<Item, MappedItem>(list: Accessor<Maybe<readonly Item[]>>, map: (value: Accessor<Item>, index: Accessor<number>) => MappedItem, options?: {
|
|
11
11
|
keyed?: boolean | ((item: Item) => any);
|
|
12
|
-
fallback
|
|
12
|
+
fallback?: Accessor<any>;
|
|
13
13
|
}): Accessor<MappedItem[]>;
|
package/dist/types/signals.d.ts
CHANGED
|
@@ -8,6 +8,15 @@ export type Setter<in out T> = {
|
|
|
8
8
|
<U extends T>(value: Exclude<U, Function> | ((prev: T) => U)): U;
|
|
9
9
|
};
|
|
10
10
|
export type Signal<T> = [get: Accessor<T>, set: Setter<T>];
|
|
11
|
+
export type ComputeFunction<Prev, Next extends Prev = Prev> = (v: Prev) => Next;
|
|
12
|
+
export type EffectFunction<Prev, Next extends Prev = Prev> = (v: Next, p?: Prev) => (() => void) | void;
|
|
13
|
+
export interface EffectOptions {
|
|
14
|
+
name?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface MemoOptions<T> extends EffectOptions {
|
|
17
|
+
equals?: false | ((prev: T, next: T) => boolean);
|
|
18
|
+
}
|
|
19
|
+
export type NoInfer<T extends any> = [T][T extends any ? 0 : never];
|
|
11
20
|
/**
|
|
12
21
|
* Creates a simple reactive state with a getter and setter
|
|
13
22
|
* ```typescript
|
|
@@ -33,31 +42,85 @@ export type Signal<T> = [get: Accessor<T>, set: Setter<T>];
|
|
|
33
42
|
*/
|
|
34
43
|
export declare function createSignal<T>(): Signal<T | undefined>;
|
|
35
44
|
export declare function createSignal<T>(value: Exclude<T, Function>, options?: SignalOptions<T>): Signal<T>;
|
|
36
|
-
export declare function createSignal<T>(fn:
|
|
37
|
-
export declare function createAsync<T>(fn: (prev?: T) => Promise<T> | AsyncIterable<T> | T, initial?: T, options?: SignalOptions<T>): Accessor<T>;
|
|
45
|
+
export declare function createSignal<T>(fn: ComputeFunction<T>, initialValue?: T, options?: SignalOptions<T>): Signal<T>;
|
|
38
46
|
/**
|
|
39
|
-
* Creates a
|
|
40
|
-
*
|
|
41
|
-
*
|
|
47
|
+
* Creates a readonly derived reactive memoized signal
|
|
48
|
+
* ```typescript
|
|
49
|
+
* export function createMemo<T>(
|
|
50
|
+
* compute: (v: T) => T,
|
|
51
|
+
* value?: T,
|
|
52
|
+
* options?: { name?: string, equals?: false | ((prev: T, next: T) => boolean) }
|
|
53
|
+
* ): () => T;
|
|
54
|
+
* ```
|
|
55
|
+
* @param compute a function that receives its previous or the initial value, if set, and returns a new value used to react on a computation
|
|
56
|
+
* @param value an optional initial value for the computation; if set, fn will never receive undefined as first argument
|
|
57
|
+
* @param options allows to set a name in dev mode for debugging purposes and use a custom comparison function in equals
|
|
58
|
+
*
|
|
59
|
+
* @description https://docs.solidjs.com/reference/basic-reactivity/create-memo
|
|
42
60
|
*/
|
|
43
|
-
export declare function createMemo<
|
|
61
|
+
export declare function createMemo<Next extends Prev, Prev = Next>(compute: ComputeFunction<undefined | NoInfer<Prev>, Next>): Accessor<Next>;
|
|
62
|
+
export declare function createMemo<Next extends Prev, Init = Next, Prev = Next>(compute: ComputeFunction<Init | Prev, Next>, value: Init, options?: MemoOptions<Next>): Accessor<Next>;
|
|
44
63
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
64
|
+
* Creates a readonly derived async reactive memoized signal
|
|
65
|
+
* ```typescript
|
|
66
|
+
* export function createAsync<T>(
|
|
67
|
+
* compute: (v: T) => Promise<T> | T,
|
|
68
|
+
* value?: T,
|
|
69
|
+
* options?: { name?: string, equals?: false | ((prev: T, next: T) => boolean) }
|
|
70
|
+
* ): () => T;
|
|
71
|
+
* ```
|
|
72
|
+
* @param compute a function that receives its previous or the initial value, if set, and returns a new value used to react on a computation
|
|
73
|
+
* @param value an optional initial value for the computation; if set, fn will never receive undefined as first argument
|
|
74
|
+
* @param options allows to set a name in dev mode for debugging purposes and use a custom comparison function in equals
|
|
75
|
+
*
|
|
76
|
+
* @description https://docs.solidjs.com/reference/basic-reactivity/create-async
|
|
47
77
|
*/
|
|
48
|
-
export declare function
|
|
49
|
-
name?: string;
|
|
50
|
-
}): void;
|
|
78
|
+
export declare function createAsync<T>(compute: (prev?: T) => Promise<T> | AsyncIterable<T> | T, value?: T, options?: MemoOptions<T>): Accessor<T>;
|
|
51
79
|
/**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
80
|
+
* Creates a reactive effect that runs after the render phase
|
|
81
|
+
* ```typescript
|
|
82
|
+
* export function createEffect<T>(
|
|
83
|
+
* compute: (prev: T) => T,
|
|
84
|
+
* effect: (v: T, prev: T) => (() => void) | void,
|
|
85
|
+
* value?: T,
|
|
86
|
+
* options?: { name?: string }
|
|
87
|
+
* ): void;
|
|
88
|
+
* ```
|
|
89
|
+
* @param compute a function that receives its previous or the initial value, if set, and returns a new value used to react on a computation
|
|
90
|
+
* @param effect a function that receives the new value and is used to perform side effects
|
|
91
|
+
* @param value an optional initial value for the computation; if set, fn will never receive undefined as first argument
|
|
92
|
+
* @param options allows to set a name in dev mode for debugging purposes
|
|
93
|
+
*
|
|
94
|
+
* @description https://docs.solidjs.com/reference/basic-reactivity/create-effect
|
|
54
95
|
*/
|
|
55
|
-
export declare function
|
|
56
|
-
|
|
57
|
-
}): void;
|
|
96
|
+
export declare function createEffect<Next>(compute: ComputeFunction<undefined | NoInfer<Next>, Next>, effect: EffectFunction<NoInfer<Next>, Next>): void;
|
|
97
|
+
export declare function createEffect<Next, Init = Next>(compute: ComputeFunction<Init | Next, Next>, effect: EffectFunction<Next, Next>, value: Init, options?: EffectOptions): void;
|
|
58
98
|
/**
|
|
59
|
-
* Creates a computation
|
|
60
|
-
*
|
|
99
|
+
* Creates a reactive computation that runs during the render phase as DOM elements are created and updated but not necessarily connected
|
|
100
|
+
* ```typescript
|
|
101
|
+
* export function createRenderEffect<T>(
|
|
102
|
+
* compute: (prev: T) => T,
|
|
103
|
+
* effect: (v: T, prev: T) => (() => void) | void,
|
|
104
|
+
* value?: T,
|
|
105
|
+
* options?: { name?: string }
|
|
106
|
+
* ): void;
|
|
107
|
+
* ```
|
|
108
|
+
* @param compute a function that receives its previous or the initial value, if set, and returns a new value used to react on a computation
|
|
109
|
+
* @param effect a function that receives the new value and is used to perform side effects
|
|
110
|
+
* @param value an optional initial value for the computation; if set, fn will never receive undefined as first argument
|
|
111
|
+
* @param options allows to set a name in dev mode for debugging purposes
|
|
112
|
+
*
|
|
113
|
+
* @description https://docs.solidjs.com/reference/secondary-primitives/create-render-effect
|
|
114
|
+
*/
|
|
115
|
+
export declare function createRenderEffect<Next>(compute: ComputeFunction<undefined | NoInfer<Next>, Next>, effect: EffectFunction<NoInfer<Next>, Next>): void;
|
|
116
|
+
export declare function createRenderEffect<Next, Init = Next>(compute: ComputeFunction<Init | Next, Next>, effect: EffectFunction<Next, Next>, value: Init, options?: EffectOptions): void;
|
|
117
|
+
/**
|
|
118
|
+
* Creates a new non-tracked reactive context with manual disposal
|
|
119
|
+
*
|
|
120
|
+
* @param fn a function in which the reactive state is scoped
|
|
121
|
+
* @returns the output of `fn`.
|
|
122
|
+
*
|
|
123
|
+
* @description https://docs.solidjs.com/reference/reactive-utilities/create-root
|
|
61
124
|
*/
|
|
62
125
|
export declare function createRoot<T>(init: ((dispose: () => void) => T) | (() => T)): T;
|
|
63
126
|
/**
|