@solidjs/signals 0.0.5 → 0.0.7
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 +41 -14
- package/dist/node.cjs +184 -157
- package/dist/prod.js +184 -157
- package/dist/types/core/index.d.ts +1 -1
- package/dist/types/core/scheduler.d.ts +2 -2
- package/dist/types/core/suspense.d.ts +2 -2
- package/dist/types/signals.d.ts +3 -3
- package/package.json +1 -1
package/dist/prod.js
CHANGED
|
@@ -103,9 +103,9 @@ var Owner = class {
|
|
|
103
103
|
m = null;
|
|
104
104
|
p = null;
|
|
105
105
|
a = STATE_CLEAN;
|
|
106
|
-
i = null;
|
|
107
|
-
n = defaultContext;
|
|
108
106
|
j = null;
|
|
107
|
+
n = defaultContext;
|
|
108
|
+
k = null;
|
|
109
109
|
e = null;
|
|
110
110
|
constructor(signal = false) {
|
|
111
111
|
if (currentOwner && !signal)
|
|
@@ -121,8 +121,8 @@ var Owner = class {
|
|
|
121
121
|
if (child.n !== this.n) {
|
|
122
122
|
child.n = { ...this.n, ...child.n };
|
|
123
123
|
}
|
|
124
|
-
if (this.
|
|
125
|
-
child.
|
|
124
|
+
if (this.k) {
|
|
125
|
+
child.k = !child.k ? this.k : [...child.k, ...this.k];
|
|
126
126
|
}
|
|
127
127
|
if (this.e)
|
|
128
128
|
child.e = this.e;
|
|
@@ -151,30 +151,30 @@ var Owner = class {
|
|
|
151
151
|
this.o = null;
|
|
152
152
|
this.p = null;
|
|
153
153
|
this.n = defaultContext;
|
|
154
|
-
this.
|
|
154
|
+
this.k = null;
|
|
155
155
|
this.a = STATE_DISPOSED;
|
|
156
156
|
this.emptyDisposal();
|
|
157
157
|
}
|
|
158
158
|
emptyDisposal() {
|
|
159
|
-
if (!this.
|
|
159
|
+
if (!this.j)
|
|
160
160
|
return;
|
|
161
|
-
if (Array.isArray(this.
|
|
162
|
-
for (let i = 0; i < this.
|
|
163
|
-
const callable = this.
|
|
161
|
+
if (Array.isArray(this.j)) {
|
|
162
|
+
for (let i = 0; i < this.j.length; i++) {
|
|
163
|
+
const callable = this.j[i];
|
|
164
164
|
callable.call(callable);
|
|
165
165
|
}
|
|
166
166
|
} else {
|
|
167
|
-
this.
|
|
167
|
+
this.j.call(this.j);
|
|
168
168
|
}
|
|
169
|
-
this.
|
|
169
|
+
this.j = null;
|
|
170
170
|
}
|
|
171
171
|
handleError(error) {
|
|
172
|
-
if (!this.
|
|
172
|
+
if (!this.k)
|
|
173
173
|
throw error;
|
|
174
|
-
let i = 0, len = this.
|
|
174
|
+
let i = 0, len = this.k.length;
|
|
175
175
|
for (i = 0; i < len; i++) {
|
|
176
176
|
try {
|
|
177
|
-
this.
|
|
177
|
+
this.k[i](error);
|
|
178
178
|
break;
|
|
179
179
|
} catch (e) {
|
|
180
180
|
error = e;
|
|
@@ -213,12 +213,12 @@ function onCleanup(fn) {
|
|
|
213
213
|
if (!currentOwner)
|
|
214
214
|
return fn;
|
|
215
215
|
const node = currentOwner;
|
|
216
|
-
if (!node.
|
|
217
|
-
node.
|
|
218
|
-
} else if (Array.isArray(node.
|
|
219
|
-
node.
|
|
216
|
+
if (!node.j) {
|
|
217
|
+
node.j = fn;
|
|
218
|
+
} else if (Array.isArray(node.j)) {
|
|
219
|
+
node.j.push(fn);
|
|
220
220
|
} else {
|
|
221
|
-
node.
|
|
221
|
+
node.j = [node.j, fn];
|
|
222
222
|
}
|
|
223
223
|
return fn;
|
|
224
224
|
}
|
|
@@ -250,34 +250,34 @@ var Computation = class extends Owner {
|
|
|
250
250
|
c = null;
|
|
251
251
|
b = null;
|
|
252
252
|
d;
|
|
253
|
-
|
|
253
|
+
C;
|
|
254
254
|
// Used in __DEV__ mode, hopefully removed in production
|
|
255
255
|
V;
|
|
256
256
|
// Using false is an optimization as an alternative to _equals: () => false
|
|
257
257
|
// which could enable more efficient DIRTY notification
|
|
258
|
-
|
|
259
|
-
|
|
258
|
+
G = isEqual;
|
|
259
|
+
O;
|
|
260
260
|
/** Whether the computation is an error or has ancestors that are unresolved */
|
|
261
261
|
f = 0;
|
|
262
262
|
/** Which flags raised by sources are handled, vs. being passed through. */
|
|
263
|
-
|
|
264
|
-
|
|
263
|
+
D = DEFAULT_FLAGS;
|
|
264
|
+
z = null;
|
|
265
265
|
H = null;
|
|
266
266
|
I = -1;
|
|
267
267
|
constructor(initialValue, compute2, options) {
|
|
268
268
|
super(compute2 === null);
|
|
269
|
-
this.
|
|
269
|
+
this.C = compute2;
|
|
270
270
|
this.a = compute2 ? STATE_UNINITIALIZED : STATE_CLEAN;
|
|
271
271
|
this.d = initialValue;
|
|
272
272
|
if (options?.equals !== void 0)
|
|
273
|
-
this.
|
|
273
|
+
this.G = options.equals;
|
|
274
274
|
if (options?.unobserved)
|
|
275
|
-
this.
|
|
275
|
+
this.O = options?.unobserved;
|
|
276
276
|
}
|
|
277
|
-
|
|
278
|
-
if (this.
|
|
279
|
-
this.
|
|
280
|
-
if (!this.
|
|
277
|
+
P() {
|
|
278
|
+
if (this.C)
|
|
279
|
+
this.t();
|
|
280
|
+
if (!this.C || this.c?.length)
|
|
281
281
|
track(this);
|
|
282
282
|
newFlags |= this.f & ~currentMask;
|
|
283
283
|
if (this.f & ERROR_BIT) {
|
|
@@ -291,7 +291,7 @@ var Computation = class extends Owner {
|
|
|
291
291
|
* Automatically re-executes the surrounding computation when the value changes
|
|
292
292
|
*/
|
|
293
293
|
read() {
|
|
294
|
-
return this.
|
|
294
|
+
return this.P();
|
|
295
295
|
}
|
|
296
296
|
/**
|
|
297
297
|
* Return the current value of this computation
|
|
@@ -304,7 +304,7 @@ var Computation = class extends Owner {
|
|
|
304
304
|
if (!syncResolve && this.loading()) {
|
|
305
305
|
throw new NotReadyError();
|
|
306
306
|
}
|
|
307
|
-
return this.
|
|
307
|
+
return this.P();
|
|
308
308
|
}
|
|
309
309
|
/**
|
|
310
310
|
* Return true if the computation is the value is dependent on an unresolved promise
|
|
@@ -324,15 +324,15 @@ var Computation = class extends Owner {
|
|
|
324
324
|
* Triggers re-execution of the computation when the error state changes
|
|
325
325
|
*/
|
|
326
326
|
error() {
|
|
327
|
-
if (this.
|
|
328
|
-
this.
|
|
327
|
+
if (this.z === null) {
|
|
328
|
+
this.z = errorState(this);
|
|
329
329
|
}
|
|
330
|
-
return this.
|
|
330
|
+
return this.z.read();
|
|
331
331
|
}
|
|
332
332
|
/** Update the computation with a new value. */
|
|
333
333
|
write(value, flags = 0, raw = false) {
|
|
334
334
|
const newValue = !raw && typeof value === "function" ? value(this.d) : value;
|
|
335
|
-
const valueChanged = newValue !== UNCHANGED && (!!(flags & ERROR_BIT) || this.a === STATE_UNINITIALIZED || this.
|
|
335
|
+
const valueChanged = newValue !== UNCHANGED && (!!(flags & ERROR_BIT) || this.a === STATE_UNINITIALIZED || this.G === false || !this.G(this.d, newValue));
|
|
336
336
|
if (valueChanged)
|
|
337
337
|
this.d = newValue;
|
|
338
338
|
const changedFlagsMask = this.f ^ flags, changedFlags = changedFlagsMask & flags;
|
|
@@ -341,9 +341,9 @@ var Computation = class extends Owner {
|
|
|
341
341
|
if (this.b) {
|
|
342
342
|
for (let i = 0; i < this.b.length; i++) {
|
|
343
343
|
if (valueChanged) {
|
|
344
|
-
this.b[i].
|
|
344
|
+
this.b[i].u(STATE_DIRTY);
|
|
345
345
|
} else if (changedFlagsMask) {
|
|
346
|
-
this.b[i].
|
|
346
|
+
this.b[i].Q(changedFlagsMask, changedFlags);
|
|
347
347
|
}
|
|
348
348
|
}
|
|
349
349
|
}
|
|
@@ -352,13 +352,13 @@ var Computation = class extends Owner {
|
|
|
352
352
|
/**
|
|
353
353
|
* Set the current node's state, and recursively mark all of this node's observers as STATE_CHECK
|
|
354
354
|
*/
|
|
355
|
-
|
|
355
|
+
u(state) {
|
|
356
356
|
if (this.a >= state)
|
|
357
357
|
return;
|
|
358
358
|
this.a = state;
|
|
359
359
|
if (this.b) {
|
|
360
360
|
for (let i = 0; i < this.b.length; i++) {
|
|
361
|
-
this.b[i].
|
|
361
|
+
this.b[i].u(STATE_CHECK);
|
|
362
362
|
}
|
|
363
363
|
}
|
|
364
364
|
}
|
|
@@ -368,11 +368,11 @@ var Computation = class extends Owner {
|
|
|
368
368
|
* @param mask A bitmask for which flag(s) were changed.
|
|
369
369
|
* @param newFlags The source's new flags, masked to just the changed ones.
|
|
370
370
|
*/
|
|
371
|
-
|
|
371
|
+
Q(mask, newFlags2) {
|
|
372
372
|
if (this.a >= STATE_DIRTY)
|
|
373
373
|
return;
|
|
374
|
-
if (mask & this.
|
|
375
|
-
this.
|
|
374
|
+
if (mask & this.D) {
|
|
375
|
+
this.u(STATE_DIRTY);
|
|
376
376
|
return;
|
|
377
377
|
}
|
|
378
378
|
if (this.a >= STATE_CHECK)
|
|
@@ -380,17 +380,17 @@ var Computation = class extends Owner {
|
|
|
380
380
|
const prevFlags = this.f & mask;
|
|
381
381
|
const deltaFlags = prevFlags ^ newFlags2;
|
|
382
382
|
if (newFlags2 === prevFlags) ; else if (deltaFlags & prevFlags & mask) {
|
|
383
|
-
this.
|
|
383
|
+
this.u(STATE_CHECK);
|
|
384
384
|
} else {
|
|
385
385
|
this.f ^= deltaFlags;
|
|
386
386
|
if (this.b) {
|
|
387
387
|
for (let i = 0; i < this.b.length; i++) {
|
|
388
|
-
this.b[i].
|
|
388
|
+
this.b[i].Q(mask, newFlags2);
|
|
389
389
|
}
|
|
390
390
|
}
|
|
391
391
|
}
|
|
392
392
|
}
|
|
393
|
-
|
|
393
|
+
J(error) {
|
|
394
394
|
this.write(error, this.f | ERROR_BIT);
|
|
395
395
|
}
|
|
396
396
|
/**
|
|
@@ -400,7 +400,7 @@ var Computation = class extends Owner {
|
|
|
400
400
|
*
|
|
401
401
|
* This function will ensure that the value and states we read from the computation are up to date
|
|
402
402
|
*/
|
|
403
|
-
|
|
403
|
+
t() {
|
|
404
404
|
if (this.a === STATE_DISPOSED) {
|
|
405
405
|
throw new Error("Tried to read a disposed computation");
|
|
406
406
|
}
|
|
@@ -410,7 +410,7 @@ var Computation = class extends Owner {
|
|
|
410
410
|
let observerFlags = 0;
|
|
411
411
|
if (this.a === STATE_CHECK) {
|
|
412
412
|
for (let i = 0; i < this.c.length; i++) {
|
|
413
|
-
this.c[i].
|
|
413
|
+
this.c[i].t();
|
|
414
414
|
observerFlags |= this.c[i].f;
|
|
415
415
|
if (this.a === STATE_DIRTY) {
|
|
416
416
|
break;
|
|
@@ -442,12 +442,12 @@ function loadingState(node) {
|
|
|
442
442
|
void 0,
|
|
443
443
|
() => {
|
|
444
444
|
track(node);
|
|
445
|
-
node.
|
|
445
|
+
node.t();
|
|
446
446
|
return !!(node.f & LOADING_BIT);
|
|
447
447
|
},
|
|
448
448
|
options
|
|
449
449
|
);
|
|
450
|
-
computation.
|
|
450
|
+
computation.D = ERROR_BIT | LOADING_BIT;
|
|
451
451
|
setOwner(prevOwner);
|
|
452
452
|
return computation;
|
|
453
453
|
}
|
|
@@ -458,12 +458,12 @@ function errorState(node) {
|
|
|
458
458
|
void 0,
|
|
459
459
|
() => {
|
|
460
460
|
track(node);
|
|
461
|
-
node.
|
|
461
|
+
node.t();
|
|
462
462
|
return !!(node.f & ERROR_BIT);
|
|
463
463
|
},
|
|
464
464
|
options
|
|
465
465
|
);
|
|
466
|
-
computation.
|
|
466
|
+
computation.D = ERROR_BIT;
|
|
467
467
|
setOwner(prevOwner);
|
|
468
468
|
return computation;
|
|
469
469
|
}
|
|
@@ -489,13 +489,13 @@ function update(node) {
|
|
|
489
489
|
try {
|
|
490
490
|
node.dispose(false);
|
|
491
491
|
node.emptyDisposal();
|
|
492
|
-
const result = compute(node, node.
|
|
492
|
+
const result = compute(node, node.C, node);
|
|
493
493
|
node.write(result, newFlags, true);
|
|
494
494
|
} catch (error) {
|
|
495
495
|
if (error instanceof NotReadyError) {
|
|
496
496
|
node.write(UNCHANGED, newFlags | LOADING_BIT);
|
|
497
497
|
} else {
|
|
498
|
-
node.
|
|
498
|
+
node.J(error);
|
|
499
499
|
}
|
|
500
500
|
} finally {
|
|
501
501
|
if (newSources) {
|
|
@@ -537,7 +537,7 @@ function removeSourceObservers(node, index) {
|
|
|
537
537
|
source.b[swap] = source.b[source.b.length - 1];
|
|
538
538
|
source.b.pop();
|
|
539
539
|
if (!source.b.length)
|
|
540
|
-
source.
|
|
540
|
+
source.O?.();
|
|
541
541
|
}
|
|
542
542
|
}
|
|
543
543
|
}
|
|
@@ -581,7 +581,7 @@ function latest(fn) {
|
|
|
581
581
|
function compute(owner, compute2, observer) {
|
|
582
582
|
const prevOwner = setOwner(owner), prevObserver = currentObserver, prevMask = currentMask;
|
|
583
583
|
currentObserver = observer;
|
|
584
|
-
currentMask = observer?.
|
|
584
|
+
currentMask = observer?.D ?? DEFAULT_FLAGS;
|
|
585
585
|
try {
|
|
586
586
|
return compute2(observer ? observer.d : void 0);
|
|
587
587
|
} finally {
|
|
@@ -597,55 +597,60 @@ function schedule() {
|
|
|
597
597
|
if (scheduled)
|
|
598
598
|
return;
|
|
599
599
|
scheduled = true;
|
|
600
|
-
if (!globalQueue.
|
|
600
|
+
if (!globalQueue.E)
|
|
601
601
|
queueMicrotask(flushSync);
|
|
602
602
|
}
|
|
603
603
|
var Queue = class {
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
604
|
+
E = false;
|
|
605
|
+
q = [[], [], []];
|
|
606
|
+
A = [];
|
|
607
607
|
enqueue(type, node) {
|
|
608
|
-
this.
|
|
608
|
+
this.q[0].push(node);
|
|
609
609
|
if (type)
|
|
610
|
-
this.
|
|
610
|
+
this.q[type].push(node);
|
|
611
611
|
schedule();
|
|
612
612
|
}
|
|
613
613
|
run(type) {
|
|
614
|
-
if (this.
|
|
614
|
+
if (this.q[type].length) {
|
|
615
615
|
if (type === EFFECT_PURE) {
|
|
616
|
-
runPureQueue(this.
|
|
617
|
-
this.
|
|
616
|
+
runPureQueue(this.q[type]);
|
|
617
|
+
this.q[type] = [];
|
|
618
618
|
} else {
|
|
619
|
-
const effects = this.
|
|
620
|
-
this.
|
|
619
|
+
const effects = this.q[type];
|
|
620
|
+
this.q[type] = [];
|
|
621
621
|
runEffectQueue(effects);
|
|
622
622
|
}
|
|
623
623
|
}
|
|
624
|
-
|
|
625
|
-
|
|
624
|
+
let rerun = false;
|
|
625
|
+
for (let i = 0; i < this.A.length; i++) {
|
|
626
|
+
rerun = this.A[i].run(type) || rerun;
|
|
626
627
|
}
|
|
628
|
+
if (type === EFFECT_PURE && this.q[type].length)
|
|
629
|
+
return true;
|
|
627
630
|
}
|
|
628
631
|
flush() {
|
|
629
|
-
if (this.
|
|
632
|
+
if (this.E)
|
|
630
633
|
return;
|
|
631
|
-
this.
|
|
634
|
+
this.E = true;
|
|
632
635
|
try {
|
|
633
|
-
this.run(EFFECT_PURE)
|
|
636
|
+
while (this.run(EFFECT_PURE)) {
|
|
637
|
+
}
|
|
638
|
+
;
|
|
634
639
|
incrementClock();
|
|
635
640
|
scheduled = false;
|
|
636
641
|
this.run(EFFECT_RENDER);
|
|
637
642
|
this.run(EFFECT_USER);
|
|
638
643
|
} finally {
|
|
639
|
-
this.
|
|
644
|
+
this.E = false;
|
|
640
645
|
}
|
|
641
646
|
}
|
|
642
647
|
addChild(child) {
|
|
643
|
-
this.
|
|
648
|
+
this.A.push(child);
|
|
644
649
|
}
|
|
645
650
|
removeChild(child) {
|
|
646
|
-
const index = this.
|
|
651
|
+
const index = this.A.indexOf(child);
|
|
647
652
|
if (index >= 0)
|
|
648
|
-
this.
|
|
653
|
+
this.A.splice(index, 1);
|
|
649
654
|
}
|
|
650
655
|
};
|
|
651
656
|
var globalQueue = new Queue();
|
|
@@ -678,7 +683,7 @@ function runTop(node) {
|
|
|
678
683
|
}
|
|
679
684
|
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
680
685
|
if (ancestors[i].a !== STATE_DISPOSED)
|
|
681
|
-
ancestors[i].
|
|
686
|
+
ancestors[i].t();
|
|
682
687
|
}
|
|
683
688
|
}
|
|
684
689
|
function runPureQueue(queue) {
|
|
@@ -694,52 +699,52 @@ function runEffectQueue(queue) {
|
|
|
694
699
|
|
|
695
700
|
// src/core/effect.ts
|
|
696
701
|
var Effect = class extends Computation {
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
702
|
+
K;
|
|
703
|
+
L = false;
|
|
704
|
+
F;
|
|
705
|
+
B;
|
|
701
706
|
e;
|
|
702
707
|
constructor(initialValue, compute2, effect, options) {
|
|
703
708
|
super(initialValue, compute2, options);
|
|
704
|
-
this.
|
|
705
|
-
this.
|
|
706
|
-
this.
|
|
709
|
+
this.K = effect;
|
|
710
|
+
this.F = initialValue;
|
|
711
|
+
this.B = options?.render ? EFFECT_RENDER : EFFECT_USER;
|
|
707
712
|
this.e = getOwner()?.e || globalQueue;
|
|
708
|
-
this.
|
|
709
|
-
this.
|
|
713
|
+
this.t();
|
|
714
|
+
this.B === EFFECT_USER ? this.e.enqueue(this.B, this) : this.R();
|
|
710
715
|
}
|
|
711
716
|
write(value, flags = 0) {
|
|
712
717
|
const currentFlags = this.f;
|
|
713
718
|
this.f = flags;
|
|
714
|
-
if (this.
|
|
719
|
+
if (this.B === EFFECT_RENDER && (flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
|
|
715
720
|
this.e.S?.(this);
|
|
716
721
|
}
|
|
717
722
|
if (value === UNCHANGED)
|
|
718
723
|
return this.d;
|
|
719
724
|
this.d = value;
|
|
720
|
-
this.
|
|
725
|
+
this.L = true;
|
|
721
726
|
return value;
|
|
722
727
|
}
|
|
723
|
-
|
|
728
|
+
u(state) {
|
|
724
729
|
if (this.a >= state)
|
|
725
730
|
return;
|
|
726
731
|
if (this.a === STATE_CLEAN)
|
|
727
|
-
this.e.enqueue(this.
|
|
732
|
+
this.e.enqueue(this.B, this);
|
|
728
733
|
this.a = state;
|
|
729
734
|
}
|
|
730
|
-
|
|
735
|
+
J(error) {
|
|
731
736
|
this.handleError(error);
|
|
732
737
|
}
|
|
733
738
|
x() {
|
|
734
|
-
this.
|
|
735
|
-
this.
|
|
739
|
+
this.K = void 0;
|
|
740
|
+
this.F = void 0;
|
|
736
741
|
super.x();
|
|
737
742
|
}
|
|
738
743
|
R() {
|
|
739
|
-
if (this.
|
|
740
|
-
this.
|
|
741
|
-
this.
|
|
742
|
-
this.
|
|
744
|
+
if (this.L && this.a !== STATE_DISPOSED) {
|
|
745
|
+
this.K(this.d, this.F);
|
|
746
|
+
this.F = this.d;
|
|
747
|
+
this.L = false;
|
|
743
748
|
}
|
|
744
749
|
}
|
|
745
750
|
};
|
|
@@ -748,39 +753,39 @@ var EagerComputation = class extends Computation {
|
|
|
748
753
|
constructor(initialValue, compute2, options) {
|
|
749
754
|
super(initialValue, compute2, options);
|
|
750
755
|
this.e = getOwner()?.e || globalQueue;
|
|
751
|
-
this.
|
|
756
|
+
this.t();
|
|
752
757
|
}
|
|
753
|
-
|
|
758
|
+
u(state) {
|
|
754
759
|
if (this.a >= state)
|
|
755
760
|
return;
|
|
756
761
|
if (this.a === STATE_CLEAN)
|
|
757
762
|
this.e.enqueue(EFFECT_PURE, this);
|
|
758
|
-
super.
|
|
763
|
+
super.u(state);
|
|
759
764
|
}
|
|
760
765
|
};
|
|
761
766
|
|
|
762
767
|
// src/core/suspense.ts
|
|
763
768
|
var SuspenseQueue = class extends Queue {
|
|
764
769
|
g = /* @__PURE__ */ new Set();
|
|
765
|
-
|
|
766
|
-
|
|
770
|
+
r = false;
|
|
771
|
+
M = new Computation(false, null);
|
|
767
772
|
run(type) {
|
|
768
|
-
if (type && this.
|
|
773
|
+
if (type && this.r)
|
|
769
774
|
return;
|
|
770
|
-
super.run(type);
|
|
775
|
+
return super.run(type);
|
|
771
776
|
}
|
|
772
777
|
S(node) {
|
|
773
778
|
if (node.f & LOADING_BIT) {
|
|
774
779
|
this.g.add(node);
|
|
775
|
-
if (!this.
|
|
776
|
-
this.
|
|
777
|
-
queueTask(() => this.
|
|
780
|
+
if (!this.r) {
|
|
781
|
+
this.r = true;
|
|
782
|
+
queueTask(() => this.M.write(true));
|
|
778
783
|
}
|
|
779
784
|
} else {
|
|
780
785
|
this.g.delete(node);
|
|
781
786
|
if (this.g.size === 0) {
|
|
782
|
-
this.
|
|
783
|
-
queueTask(() => this.
|
|
787
|
+
this.r = false;
|
|
788
|
+
queueTask(() => this.M.write(false));
|
|
784
789
|
}
|
|
785
790
|
}
|
|
786
791
|
}
|
|
@@ -795,14 +800,14 @@ var LiveComputation = class extends EagerComputation {
|
|
|
795
800
|
return this.d;
|
|
796
801
|
}
|
|
797
802
|
};
|
|
798
|
-
function createSuspense(fn,
|
|
803
|
+
function createSuspense(fn, fallback) {
|
|
799
804
|
const queue = new SuspenseQueue();
|
|
800
805
|
const tree = createBoundary(() => {
|
|
801
806
|
const child = new Computation(null, fn);
|
|
802
807
|
return new LiveComputation(null, () => flatten(child.wait()));
|
|
803
808
|
}, queue);
|
|
804
|
-
const equality = new Computation(null, () => queue.
|
|
805
|
-
const comp = new Computation(null, () => equality.read() ?
|
|
809
|
+
const equality = new Computation(null, () => queue.M.read() || queue.r);
|
|
810
|
+
const comp = new Computation(null, () => equality.read() ? fallback() : tree.read());
|
|
806
811
|
return comp.read.bind(comp);
|
|
807
812
|
}
|
|
808
813
|
|
|
@@ -918,14 +923,36 @@ function runWithOwner(owner, run) {
|
|
|
918
923
|
return void 0;
|
|
919
924
|
}
|
|
920
925
|
}
|
|
921
|
-
function
|
|
926
|
+
function createErrorBoundary(fn, fallback) {
|
|
922
927
|
const owner = new Owner();
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
928
|
+
const error = new Computation(null, null);
|
|
929
|
+
const reset = new Computation(null, null, { equals: false });
|
|
930
|
+
const handler = (err) => error.write({ z: err });
|
|
931
|
+
owner.k = owner.k ? [handler, ...owner.k] : [handler];
|
|
932
|
+
const guarded = compute(
|
|
933
|
+
owner,
|
|
934
|
+
() => {
|
|
935
|
+
const c = new Computation(null, () => (reset.read(), fn()));
|
|
936
|
+
const f = new Computation(null, () => flatten(c.read()));
|
|
937
|
+
f.J = function(error2) {
|
|
938
|
+
this.handleError(error2);
|
|
939
|
+
};
|
|
940
|
+
return f;
|
|
941
|
+
},
|
|
942
|
+
null
|
|
943
|
+
);
|
|
944
|
+
const decision = new Computation(null, () => {
|
|
945
|
+
if (!error.read()) {
|
|
946
|
+
const resolved = guarded.read();
|
|
947
|
+
if (!error.read())
|
|
948
|
+
return resolved;
|
|
949
|
+
}
|
|
950
|
+
return fallback(error.read().z, () => {
|
|
951
|
+
error.write(null);
|
|
952
|
+
reset.write(null);
|
|
953
|
+
});
|
|
954
|
+
});
|
|
955
|
+
return decision.read.bind(decision);
|
|
929
956
|
}
|
|
930
957
|
|
|
931
958
|
// src/store/store.ts
|
|
@@ -1390,14 +1417,14 @@ function mapArray(list, map, options) {
|
|
|
1390
1417
|
T: new Owner(),
|
|
1391
1418
|
w: 0,
|
|
1392
1419
|
U: list,
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1420
|
+
s: [],
|
|
1421
|
+
N: map,
|
|
1422
|
+
l: [],
|
|
1396
1423
|
g: [],
|
|
1397
1424
|
y: keyFn,
|
|
1398
1425
|
h: keyFn || options?.keyed === false ? [] : void 0,
|
|
1399
|
-
|
|
1400
|
-
|
|
1426
|
+
i: map.length > 1 ? [] : void 0,
|
|
1427
|
+
r: options?.fallback
|
|
1401
1428
|
});
|
|
1402
1429
|
}
|
|
1403
1430
|
function updateKeyedMap() {
|
|
@@ -1406,56 +1433,56 @@ function updateKeyedMap() {
|
|
|
1406
1433
|
runWithOwner(this.T, () => {
|
|
1407
1434
|
let i, j, mapper = this.h ? () => {
|
|
1408
1435
|
this.h[j] = new Computation(newItems[j], null);
|
|
1409
|
-
this.
|
|
1410
|
-
return this.
|
|
1436
|
+
this.i && (this.i[j] = new Computation(j, null));
|
|
1437
|
+
return this.N(
|
|
1411
1438
|
Computation.prototype.read.bind(this.h[j]),
|
|
1412
|
-
Computation.prototype.read.bind(this.
|
|
1439
|
+
this.i ? Computation.prototype.read.bind(this.i[j]) : void 0
|
|
1413
1440
|
);
|
|
1414
|
-
} : this.
|
|
1441
|
+
} : this.i ? () => {
|
|
1415
1442
|
const item = newItems[j];
|
|
1416
|
-
this.
|
|
1417
|
-
return this.
|
|
1443
|
+
this.i[j] = new Computation(j, null);
|
|
1444
|
+
return this.N(() => item, Computation.prototype.read.bind(this.i[j]));
|
|
1418
1445
|
} : () => {
|
|
1419
1446
|
const item = newItems[j];
|
|
1420
|
-
return this.
|
|
1447
|
+
return this.N(() => item);
|
|
1421
1448
|
};
|
|
1422
1449
|
if (newLen === 0) {
|
|
1423
1450
|
if (this.w !== 0) {
|
|
1424
1451
|
this.T.dispose(false);
|
|
1425
1452
|
this.g = [];
|
|
1426
|
-
this.
|
|
1427
|
-
this.
|
|
1453
|
+
this.s = [];
|
|
1454
|
+
this.l = [];
|
|
1428
1455
|
this.w = 0;
|
|
1429
1456
|
this.h && (this.h = []);
|
|
1430
|
-
this.
|
|
1457
|
+
this.i && (this.i = []);
|
|
1431
1458
|
}
|
|
1432
|
-
if (this.
|
|
1433
|
-
this.
|
|
1459
|
+
if (this.r && !this.l[0]) {
|
|
1460
|
+
this.l[0] = compute(
|
|
1434
1461
|
this.g[0] = new Owner(),
|
|
1435
|
-
this.
|
|
1462
|
+
this.r,
|
|
1436
1463
|
null
|
|
1437
1464
|
);
|
|
1438
1465
|
}
|
|
1439
1466
|
} else if (this.w === 0) {
|
|
1440
1467
|
if (this.g[0])
|
|
1441
1468
|
this.g[0].dispose();
|
|
1442
|
-
this.
|
|
1469
|
+
this.l = new Array(newLen);
|
|
1443
1470
|
for (j = 0; j < newLen; j++) {
|
|
1444
|
-
this.
|
|
1445
|
-
this.
|
|
1471
|
+
this.s[j] = newItems[j];
|
|
1472
|
+
this.l[j] = compute(this.g[j] = new Owner(), mapper, null);
|
|
1446
1473
|
}
|
|
1447
1474
|
this.w = newLen;
|
|
1448
1475
|
} else {
|
|
1449
|
-
let start, end, newEnd, item, key, newIndices, newIndicesNext, temp = new Array(newLen), tempNodes = new Array(newLen), tempRows = this.h ? new Array(newLen) : void 0, tempIndexes = this.
|
|
1450
|
-
for (start = 0, end = Math.min(this.w, newLen); start < end && (this.
|
|
1476
|
+
let start, end, newEnd, item, key, newIndices, newIndicesNext, temp = new Array(newLen), tempNodes = new Array(newLen), tempRows = this.h ? new Array(newLen) : void 0, tempIndexes = this.i ? new Array(newLen) : void 0;
|
|
1477
|
+
for (start = 0, end = Math.min(this.w, newLen); start < end && (this.s[start] === newItems[start] || this.h && compare(this.y, this.s[start], newItems[start])); start++) {
|
|
1451
1478
|
if (this.h)
|
|
1452
1479
|
this.h[start].write(newItems[start]);
|
|
1453
1480
|
}
|
|
1454
|
-
for (end = this.w - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.
|
|
1455
|
-
temp[newEnd] = this.
|
|
1481
|
+
for (end = this.w - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.s[end] === newItems[newEnd] || this.h && compare(this.y, this.s[end], newItems[newEnd])); end--, newEnd--) {
|
|
1482
|
+
temp[newEnd] = this.l[end];
|
|
1456
1483
|
tempNodes[newEnd] = this.g[end];
|
|
1457
1484
|
tempRows && (tempRows[newEnd] = this.h[end]);
|
|
1458
|
-
tempIndexes && (tempIndexes[newEnd] = this.
|
|
1485
|
+
tempIndexes && (tempIndexes[newEnd] = this.i[end]);
|
|
1459
1486
|
}
|
|
1460
1487
|
newIndices = /* @__PURE__ */ new Map();
|
|
1461
1488
|
newIndicesNext = new Array(newEnd + 1);
|
|
@@ -1467,14 +1494,14 @@ function updateKeyedMap() {
|
|
|
1467
1494
|
newIndices.set(key, j);
|
|
1468
1495
|
}
|
|
1469
1496
|
for (i = start; i <= end; i++) {
|
|
1470
|
-
item = this.
|
|
1497
|
+
item = this.s[i];
|
|
1471
1498
|
key = this.y ? this.y(item) : item;
|
|
1472
1499
|
j = newIndices.get(key);
|
|
1473
1500
|
if (j !== void 0 && j !== -1) {
|
|
1474
|
-
temp[j] = this.
|
|
1501
|
+
temp[j] = this.l[i];
|
|
1475
1502
|
tempNodes[j] = this.g[i];
|
|
1476
1503
|
tempRows && (tempRows[j] = this.h[i]);
|
|
1477
|
-
tempIndexes && (tempIndexes[j] = this.
|
|
1504
|
+
tempIndexes && (tempIndexes[j] = this.i[i]);
|
|
1478
1505
|
j = newIndicesNext[j];
|
|
1479
1506
|
newIndices.set(key, j);
|
|
1480
1507
|
} else
|
|
@@ -1482,28 +1509,28 @@ function updateKeyedMap() {
|
|
|
1482
1509
|
}
|
|
1483
1510
|
for (j = start; j < newLen; j++) {
|
|
1484
1511
|
if (j in temp) {
|
|
1485
|
-
this.
|
|
1512
|
+
this.l[j] = temp[j];
|
|
1486
1513
|
this.g[j] = tempNodes[j];
|
|
1487
1514
|
if (tempRows) {
|
|
1488
1515
|
this.h[j] = tempRows[j];
|
|
1489
1516
|
this.h[j].write(newItems[j]);
|
|
1490
1517
|
}
|
|
1491
1518
|
if (tempIndexes) {
|
|
1492
|
-
this.
|
|
1493
|
-
this.
|
|
1519
|
+
this.i[j] = tempIndexes[j];
|
|
1520
|
+
this.i[j].write(j);
|
|
1494
1521
|
}
|
|
1495
1522
|
} else {
|
|
1496
|
-
this.
|
|
1523
|
+
this.l[j] = compute(this.g[j] = new Owner(), mapper, null);
|
|
1497
1524
|
}
|
|
1498
1525
|
}
|
|
1499
|
-
this.
|
|
1500
|
-
this.
|
|
1526
|
+
this.l = this.l.slice(0, this.w = newLen);
|
|
1527
|
+
this.s = newItems.slice(0);
|
|
1501
1528
|
}
|
|
1502
1529
|
});
|
|
1503
|
-
return this.
|
|
1530
|
+
return this.l;
|
|
1504
1531
|
}
|
|
1505
1532
|
function compare(key, a, b) {
|
|
1506
1533
|
return key ? key(a) === key(b) : true;
|
|
1507
1534
|
}
|
|
1508
1535
|
|
|
1509
|
-
export { $PROXY, $RAW, $TARGET, $TRACK, Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, SUPPORTS_PROXY,
|
|
1536
|
+
export { $PROXY, $RAW, $TARGET, $TRACK, Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, SUPPORTS_PROXY, 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, runWithOwner, setContext, untrack, unwrap };
|