@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/node.cjs
CHANGED
|
@@ -105,9 +105,9 @@ var Owner = class {
|
|
|
105
105
|
m = null;
|
|
106
106
|
p = null;
|
|
107
107
|
a = STATE_CLEAN;
|
|
108
|
-
i = null;
|
|
109
|
-
n = defaultContext;
|
|
110
108
|
j = null;
|
|
109
|
+
n = defaultContext;
|
|
110
|
+
k = null;
|
|
111
111
|
e = null;
|
|
112
112
|
constructor(signal = false) {
|
|
113
113
|
if (currentOwner && !signal)
|
|
@@ -123,8 +123,8 @@ var Owner = class {
|
|
|
123
123
|
if (child.n !== this.n) {
|
|
124
124
|
child.n = { ...this.n, ...child.n };
|
|
125
125
|
}
|
|
126
|
-
if (this.
|
|
127
|
-
child.
|
|
126
|
+
if (this.k) {
|
|
127
|
+
child.k = !child.k ? this.k : [...child.k, ...this.k];
|
|
128
128
|
}
|
|
129
129
|
if (this.e)
|
|
130
130
|
child.e = this.e;
|
|
@@ -153,30 +153,30 @@ var Owner = class {
|
|
|
153
153
|
this.o = null;
|
|
154
154
|
this.p = null;
|
|
155
155
|
this.n = defaultContext;
|
|
156
|
-
this.
|
|
156
|
+
this.k = null;
|
|
157
157
|
this.a = STATE_DISPOSED;
|
|
158
158
|
this.emptyDisposal();
|
|
159
159
|
}
|
|
160
160
|
emptyDisposal() {
|
|
161
|
-
if (!this.
|
|
161
|
+
if (!this.j)
|
|
162
162
|
return;
|
|
163
|
-
if (Array.isArray(this.
|
|
164
|
-
for (let i = 0; i < this.
|
|
165
|
-
const callable = this.
|
|
163
|
+
if (Array.isArray(this.j)) {
|
|
164
|
+
for (let i = 0; i < this.j.length; i++) {
|
|
165
|
+
const callable = this.j[i];
|
|
166
166
|
callable.call(callable);
|
|
167
167
|
}
|
|
168
168
|
} else {
|
|
169
|
-
this.
|
|
169
|
+
this.j.call(this.j);
|
|
170
170
|
}
|
|
171
|
-
this.
|
|
171
|
+
this.j = null;
|
|
172
172
|
}
|
|
173
173
|
handleError(error) {
|
|
174
|
-
if (!this.
|
|
174
|
+
if (!this.k)
|
|
175
175
|
throw error;
|
|
176
|
-
let i = 0, len = this.
|
|
176
|
+
let i = 0, len = this.k.length;
|
|
177
177
|
for (i = 0; i < len; i++) {
|
|
178
178
|
try {
|
|
179
|
-
this.
|
|
179
|
+
this.k[i](error);
|
|
180
180
|
break;
|
|
181
181
|
} catch (e) {
|
|
182
182
|
error = e;
|
|
@@ -215,12 +215,12 @@ function onCleanup(fn) {
|
|
|
215
215
|
if (!currentOwner)
|
|
216
216
|
return fn;
|
|
217
217
|
const node = currentOwner;
|
|
218
|
-
if (!node.
|
|
219
|
-
node.
|
|
220
|
-
} else if (Array.isArray(node.
|
|
221
|
-
node.
|
|
218
|
+
if (!node.j) {
|
|
219
|
+
node.j = fn;
|
|
220
|
+
} else if (Array.isArray(node.j)) {
|
|
221
|
+
node.j.push(fn);
|
|
222
222
|
} else {
|
|
223
|
-
node.
|
|
223
|
+
node.j = [node.j, fn];
|
|
224
224
|
}
|
|
225
225
|
return fn;
|
|
226
226
|
}
|
|
@@ -252,35 +252,35 @@ var Computation = class extends Owner {
|
|
|
252
252
|
c = null;
|
|
253
253
|
b = null;
|
|
254
254
|
d;
|
|
255
|
-
|
|
255
|
+
C;
|
|
256
256
|
// Used in __DEV__ mode, hopefully removed in production
|
|
257
257
|
V;
|
|
258
258
|
// Using false is an optimization as an alternative to _equals: () => false
|
|
259
259
|
// which could enable more efficient DIRTY notification
|
|
260
|
-
|
|
261
|
-
|
|
260
|
+
G = isEqual;
|
|
261
|
+
O;
|
|
262
262
|
/** Whether the computation is an error or has ancestors that are unresolved */
|
|
263
263
|
f = 0;
|
|
264
264
|
/** Which flags raised by sources are handled, vs. being passed through. */
|
|
265
|
-
|
|
266
|
-
|
|
265
|
+
D = DEFAULT_FLAGS;
|
|
266
|
+
z = null;
|
|
267
267
|
H = null;
|
|
268
268
|
I = -1;
|
|
269
269
|
constructor(initialValue, compute2, options) {
|
|
270
270
|
super(compute2 === null);
|
|
271
|
-
this.
|
|
271
|
+
this.C = compute2;
|
|
272
272
|
this.a = compute2 ? STATE_UNINITIALIZED : STATE_CLEAN;
|
|
273
273
|
this.d = initialValue;
|
|
274
274
|
if ((options == null ? void 0 : options.equals) !== void 0)
|
|
275
|
-
this.
|
|
275
|
+
this.G = options.equals;
|
|
276
276
|
if (options == null ? void 0 : options.unobserved)
|
|
277
|
-
this.
|
|
277
|
+
this.O = options == null ? void 0 : options.unobserved;
|
|
278
278
|
}
|
|
279
|
-
|
|
279
|
+
P() {
|
|
280
280
|
var _a;
|
|
281
|
-
if (this.
|
|
282
|
-
this.
|
|
283
|
-
if (!this.
|
|
281
|
+
if (this.C)
|
|
282
|
+
this.t();
|
|
283
|
+
if (!this.C || ((_a = this.c) == null ? void 0 : _a.length))
|
|
284
284
|
track(this);
|
|
285
285
|
newFlags |= this.f & ~currentMask;
|
|
286
286
|
if (this.f & ERROR_BIT) {
|
|
@@ -294,7 +294,7 @@ var Computation = class extends Owner {
|
|
|
294
294
|
* Automatically re-executes the surrounding computation when the value changes
|
|
295
295
|
*/
|
|
296
296
|
read() {
|
|
297
|
-
return this.
|
|
297
|
+
return this.P();
|
|
298
298
|
}
|
|
299
299
|
/**
|
|
300
300
|
* Return the current value of this computation
|
|
@@ -307,7 +307,7 @@ var Computation = class extends Owner {
|
|
|
307
307
|
if (!syncResolve && this.loading()) {
|
|
308
308
|
throw new NotReadyError();
|
|
309
309
|
}
|
|
310
|
-
return this.
|
|
310
|
+
return this.P();
|
|
311
311
|
}
|
|
312
312
|
/**
|
|
313
313
|
* Return true if the computation is the value is dependent on an unresolved promise
|
|
@@ -327,15 +327,15 @@ var Computation = class extends Owner {
|
|
|
327
327
|
* Triggers re-execution of the computation when the error state changes
|
|
328
328
|
*/
|
|
329
329
|
error() {
|
|
330
|
-
if (this.
|
|
331
|
-
this.
|
|
330
|
+
if (this.z === null) {
|
|
331
|
+
this.z = errorState(this);
|
|
332
332
|
}
|
|
333
|
-
return this.
|
|
333
|
+
return this.z.read();
|
|
334
334
|
}
|
|
335
335
|
/** Update the computation with a new value. */
|
|
336
336
|
write(value, flags = 0, raw = false) {
|
|
337
337
|
const newValue = !raw && typeof value === "function" ? value(this.d) : value;
|
|
338
|
-
const valueChanged = newValue !== UNCHANGED && (!!(flags & ERROR_BIT) || this.a === STATE_UNINITIALIZED || this.
|
|
338
|
+
const valueChanged = newValue !== UNCHANGED && (!!(flags & ERROR_BIT) || this.a === STATE_UNINITIALIZED || this.G === false || !this.G(this.d, newValue));
|
|
339
339
|
if (valueChanged)
|
|
340
340
|
this.d = newValue;
|
|
341
341
|
const changedFlagsMask = this.f ^ flags, changedFlags = changedFlagsMask & flags;
|
|
@@ -344,9 +344,9 @@ var Computation = class extends Owner {
|
|
|
344
344
|
if (this.b) {
|
|
345
345
|
for (let i = 0; i < this.b.length; i++) {
|
|
346
346
|
if (valueChanged) {
|
|
347
|
-
this.b[i].
|
|
347
|
+
this.b[i].u(STATE_DIRTY);
|
|
348
348
|
} else if (changedFlagsMask) {
|
|
349
|
-
this.b[i].
|
|
349
|
+
this.b[i].Q(changedFlagsMask, changedFlags);
|
|
350
350
|
}
|
|
351
351
|
}
|
|
352
352
|
}
|
|
@@ -355,13 +355,13 @@ var Computation = class extends Owner {
|
|
|
355
355
|
/**
|
|
356
356
|
* Set the current node's state, and recursively mark all of this node's observers as STATE_CHECK
|
|
357
357
|
*/
|
|
358
|
-
|
|
358
|
+
u(state) {
|
|
359
359
|
if (this.a >= state)
|
|
360
360
|
return;
|
|
361
361
|
this.a = state;
|
|
362
362
|
if (this.b) {
|
|
363
363
|
for (let i = 0; i < this.b.length; i++) {
|
|
364
|
-
this.b[i].
|
|
364
|
+
this.b[i].u(STATE_CHECK);
|
|
365
365
|
}
|
|
366
366
|
}
|
|
367
367
|
}
|
|
@@ -371,11 +371,11 @@ var Computation = class extends Owner {
|
|
|
371
371
|
* @param mask A bitmask for which flag(s) were changed.
|
|
372
372
|
* @param newFlags The source's new flags, masked to just the changed ones.
|
|
373
373
|
*/
|
|
374
|
-
|
|
374
|
+
Q(mask, newFlags2) {
|
|
375
375
|
if (this.a >= STATE_DIRTY)
|
|
376
376
|
return;
|
|
377
|
-
if (mask & this.
|
|
378
|
-
this.
|
|
377
|
+
if (mask & this.D) {
|
|
378
|
+
this.u(STATE_DIRTY);
|
|
379
379
|
return;
|
|
380
380
|
}
|
|
381
381
|
if (this.a >= STATE_CHECK)
|
|
@@ -383,17 +383,17 @@ var Computation = class extends Owner {
|
|
|
383
383
|
const prevFlags = this.f & mask;
|
|
384
384
|
const deltaFlags = prevFlags ^ newFlags2;
|
|
385
385
|
if (newFlags2 === prevFlags) ; else if (deltaFlags & prevFlags & mask) {
|
|
386
|
-
this.
|
|
386
|
+
this.u(STATE_CHECK);
|
|
387
387
|
} else {
|
|
388
388
|
this.f ^= deltaFlags;
|
|
389
389
|
if (this.b) {
|
|
390
390
|
for (let i = 0; i < this.b.length; i++) {
|
|
391
|
-
this.b[i].
|
|
391
|
+
this.b[i].Q(mask, newFlags2);
|
|
392
392
|
}
|
|
393
393
|
}
|
|
394
394
|
}
|
|
395
395
|
}
|
|
396
|
-
|
|
396
|
+
J(error) {
|
|
397
397
|
this.write(error, this.f | ERROR_BIT);
|
|
398
398
|
}
|
|
399
399
|
/**
|
|
@@ -403,7 +403,7 @@ var Computation = class extends Owner {
|
|
|
403
403
|
*
|
|
404
404
|
* This function will ensure that the value and states we read from the computation are up to date
|
|
405
405
|
*/
|
|
406
|
-
|
|
406
|
+
t() {
|
|
407
407
|
if (this.a === STATE_DISPOSED) {
|
|
408
408
|
throw new Error("Tried to read a disposed computation");
|
|
409
409
|
}
|
|
@@ -413,7 +413,7 @@ var Computation = class extends Owner {
|
|
|
413
413
|
let observerFlags = 0;
|
|
414
414
|
if (this.a === STATE_CHECK) {
|
|
415
415
|
for (let i = 0; i < this.c.length; i++) {
|
|
416
|
-
this.c[i].
|
|
416
|
+
this.c[i].t();
|
|
417
417
|
observerFlags |= this.c[i].f;
|
|
418
418
|
if (this.a === STATE_DIRTY) {
|
|
419
419
|
break;
|
|
@@ -445,12 +445,12 @@ function loadingState(node) {
|
|
|
445
445
|
void 0,
|
|
446
446
|
() => {
|
|
447
447
|
track(node);
|
|
448
|
-
node.
|
|
448
|
+
node.t();
|
|
449
449
|
return !!(node.f & LOADING_BIT);
|
|
450
450
|
},
|
|
451
451
|
options
|
|
452
452
|
);
|
|
453
|
-
computation.
|
|
453
|
+
computation.D = ERROR_BIT | LOADING_BIT;
|
|
454
454
|
setOwner(prevOwner);
|
|
455
455
|
return computation;
|
|
456
456
|
}
|
|
@@ -461,12 +461,12 @@ function errorState(node) {
|
|
|
461
461
|
void 0,
|
|
462
462
|
() => {
|
|
463
463
|
track(node);
|
|
464
|
-
node.
|
|
464
|
+
node.t();
|
|
465
465
|
return !!(node.f & ERROR_BIT);
|
|
466
466
|
},
|
|
467
467
|
options
|
|
468
468
|
);
|
|
469
|
-
computation.
|
|
469
|
+
computation.D = ERROR_BIT;
|
|
470
470
|
setOwner(prevOwner);
|
|
471
471
|
return computation;
|
|
472
472
|
}
|
|
@@ -492,13 +492,13 @@ function update(node) {
|
|
|
492
492
|
try {
|
|
493
493
|
node.dispose(false);
|
|
494
494
|
node.emptyDisposal();
|
|
495
|
-
const result = compute(node, node.
|
|
495
|
+
const result = compute(node, node.C, node);
|
|
496
496
|
node.write(result, newFlags, true);
|
|
497
497
|
} catch (error) {
|
|
498
498
|
if (error instanceof NotReadyError) {
|
|
499
499
|
node.write(UNCHANGED, newFlags | LOADING_BIT);
|
|
500
500
|
} else {
|
|
501
|
-
node.
|
|
501
|
+
node.J(error);
|
|
502
502
|
}
|
|
503
503
|
} finally {
|
|
504
504
|
if (newSources) {
|
|
@@ -541,7 +541,7 @@ function removeSourceObservers(node, index) {
|
|
|
541
541
|
source.b[swap] = source.b[source.b.length - 1];
|
|
542
542
|
source.b.pop();
|
|
543
543
|
if (!source.b.length)
|
|
544
|
-
(_a = source.
|
|
544
|
+
(_a = source.O) == null ? void 0 : _a.call(source);
|
|
545
545
|
}
|
|
546
546
|
}
|
|
547
547
|
}
|
|
@@ -585,7 +585,7 @@ function latest(fn) {
|
|
|
585
585
|
function compute(owner, compute2, observer) {
|
|
586
586
|
const prevOwner = setOwner(owner), prevObserver = currentObserver, prevMask = currentMask;
|
|
587
587
|
currentObserver = observer;
|
|
588
|
-
currentMask = (observer == null ? void 0 : observer.
|
|
588
|
+
currentMask = (observer == null ? void 0 : observer.D) ?? DEFAULT_FLAGS;
|
|
589
589
|
try {
|
|
590
590
|
return compute2(observer ? observer.d : void 0);
|
|
591
591
|
} finally {
|
|
@@ -601,55 +601,60 @@ function schedule() {
|
|
|
601
601
|
if (scheduled)
|
|
602
602
|
return;
|
|
603
603
|
scheduled = true;
|
|
604
|
-
if (!globalQueue.
|
|
604
|
+
if (!globalQueue.E)
|
|
605
605
|
queueMicrotask(flushSync);
|
|
606
606
|
}
|
|
607
607
|
var Queue = class {
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
608
|
+
E = false;
|
|
609
|
+
q = [[], [], []];
|
|
610
|
+
A = [];
|
|
611
611
|
enqueue(type, node) {
|
|
612
|
-
this.
|
|
612
|
+
this.q[0].push(node);
|
|
613
613
|
if (type)
|
|
614
|
-
this.
|
|
614
|
+
this.q[type].push(node);
|
|
615
615
|
schedule();
|
|
616
616
|
}
|
|
617
617
|
run(type) {
|
|
618
|
-
if (this.
|
|
618
|
+
if (this.q[type].length) {
|
|
619
619
|
if (type === EFFECT_PURE) {
|
|
620
|
-
runPureQueue(this.
|
|
621
|
-
this.
|
|
620
|
+
runPureQueue(this.q[type]);
|
|
621
|
+
this.q[type] = [];
|
|
622
622
|
} else {
|
|
623
|
-
const effects = this.
|
|
624
|
-
this.
|
|
623
|
+
const effects = this.q[type];
|
|
624
|
+
this.q[type] = [];
|
|
625
625
|
runEffectQueue(effects);
|
|
626
626
|
}
|
|
627
627
|
}
|
|
628
|
-
|
|
629
|
-
|
|
628
|
+
let rerun = false;
|
|
629
|
+
for (let i = 0; i < this.A.length; i++) {
|
|
630
|
+
rerun = this.A[i].run(type) || rerun;
|
|
630
631
|
}
|
|
632
|
+
if (type === EFFECT_PURE && this.q[type].length)
|
|
633
|
+
return true;
|
|
631
634
|
}
|
|
632
635
|
flush() {
|
|
633
|
-
if (this.
|
|
636
|
+
if (this.E)
|
|
634
637
|
return;
|
|
635
|
-
this.
|
|
638
|
+
this.E = true;
|
|
636
639
|
try {
|
|
637
|
-
this.run(EFFECT_PURE)
|
|
640
|
+
while (this.run(EFFECT_PURE)) {
|
|
641
|
+
}
|
|
642
|
+
;
|
|
638
643
|
incrementClock();
|
|
639
644
|
scheduled = false;
|
|
640
645
|
this.run(EFFECT_RENDER);
|
|
641
646
|
this.run(EFFECT_USER);
|
|
642
647
|
} finally {
|
|
643
|
-
this.
|
|
648
|
+
this.E = false;
|
|
644
649
|
}
|
|
645
650
|
}
|
|
646
651
|
addChild(child) {
|
|
647
|
-
this.
|
|
652
|
+
this.A.push(child);
|
|
648
653
|
}
|
|
649
654
|
removeChild(child) {
|
|
650
|
-
const index = this.
|
|
655
|
+
const index = this.A.indexOf(child);
|
|
651
656
|
if (index >= 0)
|
|
652
|
-
this.
|
|
657
|
+
this.A.splice(index, 1);
|
|
653
658
|
}
|
|
654
659
|
};
|
|
655
660
|
var globalQueue = new Queue();
|
|
@@ -682,7 +687,7 @@ function runTop(node) {
|
|
|
682
687
|
}
|
|
683
688
|
for (let i = ancestors.length - 1; i >= 0; i--) {
|
|
684
689
|
if (ancestors[i].a !== STATE_DISPOSED)
|
|
685
|
-
ancestors[i].
|
|
690
|
+
ancestors[i].t();
|
|
686
691
|
}
|
|
687
692
|
}
|
|
688
693
|
function runPureQueue(queue) {
|
|
@@ -698,54 +703,54 @@ function runEffectQueue(queue) {
|
|
|
698
703
|
|
|
699
704
|
// src/core/effect.ts
|
|
700
705
|
var Effect = class extends Computation {
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
706
|
+
K;
|
|
707
|
+
L = false;
|
|
708
|
+
F;
|
|
709
|
+
B;
|
|
705
710
|
e;
|
|
706
711
|
constructor(initialValue, compute2, effect, options) {
|
|
707
712
|
var _a;
|
|
708
713
|
super(initialValue, compute2, options);
|
|
709
|
-
this.
|
|
710
|
-
this.
|
|
711
|
-
this.
|
|
714
|
+
this.K = effect;
|
|
715
|
+
this.F = initialValue;
|
|
716
|
+
this.B = (options == null ? void 0 : options.render) ? EFFECT_RENDER : EFFECT_USER;
|
|
712
717
|
this.e = ((_a = getOwner()) == null ? void 0 : _a.e) || globalQueue;
|
|
713
|
-
this.
|
|
714
|
-
this.
|
|
718
|
+
this.t();
|
|
719
|
+
this.B === EFFECT_USER ? this.e.enqueue(this.B, this) : this.R();
|
|
715
720
|
}
|
|
716
721
|
write(value, flags = 0) {
|
|
717
722
|
var _a, _b;
|
|
718
723
|
const currentFlags = this.f;
|
|
719
724
|
this.f = flags;
|
|
720
|
-
if (this.
|
|
725
|
+
if (this.B === EFFECT_RENDER && (flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
|
|
721
726
|
(_b = (_a = this.e).S) == null ? void 0 : _b.call(_a, this);
|
|
722
727
|
}
|
|
723
728
|
if (value === UNCHANGED)
|
|
724
729
|
return this.d;
|
|
725
730
|
this.d = value;
|
|
726
|
-
this.
|
|
731
|
+
this.L = true;
|
|
727
732
|
return value;
|
|
728
733
|
}
|
|
729
|
-
|
|
734
|
+
u(state) {
|
|
730
735
|
if (this.a >= state)
|
|
731
736
|
return;
|
|
732
737
|
if (this.a === STATE_CLEAN)
|
|
733
|
-
this.e.enqueue(this.
|
|
738
|
+
this.e.enqueue(this.B, this);
|
|
734
739
|
this.a = state;
|
|
735
740
|
}
|
|
736
|
-
|
|
741
|
+
J(error) {
|
|
737
742
|
this.handleError(error);
|
|
738
743
|
}
|
|
739
744
|
x() {
|
|
740
|
-
this.
|
|
741
|
-
this.
|
|
745
|
+
this.K = void 0;
|
|
746
|
+
this.F = void 0;
|
|
742
747
|
super.x();
|
|
743
748
|
}
|
|
744
749
|
R() {
|
|
745
|
-
if (this.
|
|
746
|
-
this.
|
|
747
|
-
this.
|
|
748
|
-
this.
|
|
750
|
+
if (this.L && this.a !== STATE_DISPOSED) {
|
|
751
|
+
this.K(this.d, this.F);
|
|
752
|
+
this.F = this.d;
|
|
753
|
+
this.L = false;
|
|
749
754
|
}
|
|
750
755
|
}
|
|
751
756
|
};
|
|
@@ -755,39 +760,39 @@ var EagerComputation = class extends Computation {
|
|
|
755
760
|
var _a;
|
|
756
761
|
super(initialValue, compute2, options);
|
|
757
762
|
this.e = ((_a = getOwner()) == null ? void 0 : _a.e) || globalQueue;
|
|
758
|
-
this.
|
|
763
|
+
this.t();
|
|
759
764
|
}
|
|
760
|
-
|
|
765
|
+
u(state) {
|
|
761
766
|
if (this.a >= state)
|
|
762
767
|
return;
|
|
763
768
|
if (this.a === STATE_CLEAN)
|
|
764
769
|
this.e.enqueue(EFFECT_PURE, this);
|
|
765
|
-
super.
|
|
770
|
+
super.u(state);
|
|
766
771
|
}
|
|
767
772
|
};
|
|
768
773
|
|
|
769
774
|
// src/core/suspense.ts
|
|
770
775
|
var SuspenseQueue = class extends Queue {
|
|
771
776
|
g = /* @__PURE__ */ new Set();
|
|
772
|
-
|
|
773
|
-
|
|
777
|
+
r = false;
|
|
778
|
+
M = new Computation(false, null);
|
|
774
779
|
run(type) {
|
|
775
|
-
if (type && this.
|
|
780
|
+
if (type && this.r)
|
|
776
781
|
return;
|
|
777
|
-
super.run(type);
|
|
782
|
+
return super.run(type);
|
|
778
783
|
}
|
|
779
784
|
S(node) {
|
|
780
785
|
if (node.f & LOADING_BIT) {
|
|
781
786
|
this.g.add(node);
|
|
782
|
-
if (!this.
|
|
783
|
-
this.
|
|
784
|
-
queueTask(() => this.
|
|
787
|
+
if (!this.r) {
|
|
788
|
+
this.r = true;
|
|
789
|
+
queueTask(() => this.M.write(true));
|
|
785
790
|
}
|
|
786
791
|
} else {
|
|
787
792
|
this.g.delete(node);
|
|
788
793
|
if (this.g.size === 0) {
|
|
789
|
-
this.
|
|
790
|
-
queueTask(() => this.
|
|
794
|
+
this.r = false;
|
|
795
|
+
queueTask(() => this.M.write(false));
|
|
791
796
|
}
|
|
792
797
|
}
|
|
793
798
|
}
|
|
@@ -803,14 +808,14 @@ var LiveComputation = class extends EagerComputation {
|
|
|
803
808
|
return this.d;
|
|
804
809
|
}
|
|
805
810
|
};
|
|
806
|
-
function createSuspense(fn,
|
|
811
|
+
function createSuspense(fn, fallback) {
|
|
807
812
|
const queue = new SuspenseQueue();
|
|
808
813
|
const tree = createBoundary(() => {
|
|
809
814
|
const child = new Computation(null, fn);
|
|
810
815
|
return new LiveComputation(null, () => flatten(child.wait()));
|
|
811
816
|
}, queue);
|
|
812
|
-
const equality = new Computation(null, () => queue.
|
|
813
|
-
const comp = new Computation(null, () => equality.read() ?
|
|
817
|
+
const equality = new Computation(null, () => queue.M.read() || queue.r);
|
|
818
|
+
const comp = new Computation(null, () => equality.read() ? fallback() : tree.read());
|
|
814
819
|
return comp.read.bind(comp);
|
|
815
820
|
}
|
|
816
821
|
|
|
@@ -927,14 +932,36 @@ function runWithOwner(owner, run) {
|
|
|
927
932
|
return void 0;
|
|
928
933
|
}
|
|
929
934
|
}
|
|
930
|
-
function
|
|
935
|
+
function createErrorBoundary(fn, fallback) {
|
|
931
936
|
const owner = new Owner();
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
937
|
+
const error = new Computation(null, null);
|
|
938
|
+
const reset = new Computation(null, null, { equals: false });
|
|
939
|
+
const handler = (err) => error.write({ z: err });
|
|
940
|
+
owner.k = owner.k ? [handler, ...owner.k] : [handler];
|
|
941
|
+
const guarded = compute(
|
|
942
|
+
owner,
|
|
943
|
+
() => {
|
|
944
|
+
const c = new Computation(null, () => (reset.read(), fn()));
|
|
945
|
+
const f = new Computation(null, () => flatten(c.read()));
|
|
946
|
+
f.J = function(error2) {
|
|
947
|
+
this.handleError(error2);
|
|
948
|
+
};
|
|
949
|
+
return f;
|
|
950
|
+
},
|
|
951
|
+
null
|
|
952
|
+
);
|
|
953
|
+
const decision = new Computation(null, () => {
|
|
954
|
+
if (!error.read()) {
|
|
955
|
+
const resolved = guarded.read();
|
|
956
|
+
if (!error.read())
|
|
957
|
+
return resolved;
|
|
958
|
+
}
|
|
959
|
+
return fallback(error.read().z, () => {
|
|
960
|
+
error.write(null);
|
|
961
|
+
reset.write(null);
|
|
962
|
+
});
|
|
963
|
+
});
|
|
964
|
+
return decision.read.bind(decision);
|
|
938
965
|
}
|
|
939
966
|
|
|
940
967
|
// src/store/store.ts
|
|
@@ -1401,14 +1428,14 @@ function mapArray(list, map, options) {
|
|
|
1401
1428
|
T: new Owner(),
|
|
1402
1429
|
w: 0,
|
|
1403
1430
|
U: list,
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1431
|
+
s: [],
|
|
1432
|
+
N: map,
|
|
1433
|
+
l: [],
|
|
1407
1434
|
g: [],
|
|
1408
1435
|
y: keyFn,
|
|
1409
1436
|
h: keyFn || (options == null ? void 0 : options.keyed) === false ? [] : void 0,
|
|
1410
|
-
|
|
1411
|
-
|
|
1437
|
+
i: map.length > 1 ? [] : void 0,
|
|
1438
|
+
r: options == null ? void 0 : options.fallback
|
|
1412
1439
|
});
|
|
1413
1440
|
}
|
|
1414
1441
|
function updateKeyedMap() {
|
|
@@ -1417,56 +1444,56 @@ function updateKeyedMap() {
|
|
|
1417
1444
|
runWithOwner(this.T, () => {
|
|
1418
1445
|
let i, j, mapper = this.h ? () => {
|
|
1419
1446
|
this.h[j] = new Computation(newItems[j], null);
|
|
1420
|
-
this.
|
|
1421
|
-
return this.
|
|
1447
|
+
this.i && (this.i[j] = new Computation(j, null));
|
|
1448
|
+
return this.N(
|
|
1422
1449
|
Computation.prototype.read.bind(this.h[j]),
|
|
1423
|
-
Computation.prototype.read.bind(this.
|
|
1450
|
+
this.i ? Computation.prototype.read.bind(this.i[j]) : void 0
|
|
1424
1451
|
);
|
|
1425
|
-
} : this.
|
|
1452
|
+
} : this.i ? () => {
|
|
1426
1453
|
const item = newItems[j];
|
|
1427
|
-
this.
|
|
1428
|
-
return this.
|
|
1454
|
+
this.i[j] = new Computation(j, null);
|
|
1455
|
+
return this.N(() => item, Computation.prototype.read.bind(this.i[j]));
|
|
1429
1456
|
} : () => {
|
|
1430
1457
|
const item = newItems[j];
|
|
1431
|
-
return this.
|
|
1458
|
+
return this.N(() => item);
|
|
1432
1459
|
};
|
|
1433
1460
|
if (newLen === 0) {
|
|
1434
1461
|
if (this.w !== 0) {
|
|
1435
1462
|
this.T.dispose(false);
|
|
1436
1463
|
this.g = [];
|
|
1437
|
-
this.
|
|
1438
|
-
this.
|
|
1464
|
+
this.s = [];
|
|
1465
|
+
this.l = [];
|
|
1439
1466
|
this.w = 0;
|
|
1440
1467
|
this.h && (this.h = []);
|
|
1441
|
-
this.
|
|
1468
|
+
this.i && (this.i = []);
|
|
1442
1469
|
}
|
|
1443
|
-
if (this.
|
|
1444
|
-
this.
|
|
1470
|
+
if (this.r && !this.l[0]) {
|
|
1471
|
+
this.l[0] = compute(
|
|
1445
1472
|
this.g[0] = new Owner(),
|
|
1446
|
-
this.
|
|
1473
|
+
this.r,
|
|
1447
1474
|
null
|
|
1448
1475
|
);
|
|
1449
1476
|
}
|
|
1450
1477
|
} else if (this.w === 0) {
|
|
1451
1478
|
if (this.g[0])
|
|
1452
1479
|
this.g[0].dispose();
|
|
1453
|
-
this.
|
|
1480
|
+
this.l = new Array(newLen);
|
|
1454
1481
|
for (j = 0; j < newLen; j++) {
|
|
1455
|
-
this.
|
|
1456
|
-
this.
|
|
1482
|
+
this.s[j] = newItems[j];
|
|
1483
|
+
this.l[j] = compute(this.g[j] = new Owner(), mapper, null);
|
|
1457
1484
|
}
|
|
1458
1485
|
this.w = newLen;
|
|
1459
1486
|
} else {
|
|
1460
|
-
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.
|
|
1461
|
-
for (start = 0, end = Math.min(this.w, newLen); start < end && (this.
|
|
1487
|
+
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;
|
|
1488
|
+
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++) {
|
|
1462
1489
|
if (this.h)
|
|
1463
1490
|
this.h[start].write(newItems[start]);
|
|
1464
1491
|
}
|
|
1465
|
-
for (end = this.w - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.
|
|
1466
|
-
temp[newEnd] = this.
|
|
1492
|
+
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--) {
|
|
1493
|
+
temp[newEnd] = this.l[end];
|
|
1467
1494
|
tempNodes[newEnd] = this.g[end];
|
|
1468
1495
|
tempRows && (tempRows[newEnd] = this.h[end]);
|
|
1469
|
-
tempIndexes && (tempIndexes[newEnd] = this.
|
|
1496
|
+
tempIndexes && (tempIndexes[newEnd] = this.i[end]);
|
|
1470
1497
|
}
|
|
1471
1498
|
newIndices = /* @__PURE__ */ new Map();
|
|
1472
1499
|
newIndicesNext = new Array(newEnd + 1);
|
|
@@ -1478,14 +1505,14 @@ function updateKeyedMap() {
|
|
|
1478
1505
|
newIndices.set(key, j);
|
|
1479
1506
|
}
|
|
1480
1507
|
for (i = start; i <= end; i++) {
|
|
1481
|
-
item = this.
|
|
1508
|
+
item = this.s[i];
|
|
1482
1509
|
key = this.y ? this.y(item) : item;
|
|
1483
1510
|
j = newIndices.get(key);
|
|
1484
1511
|
if (j !== void 0 && j !== -1) {
|
|
1485
|
-
temp[j] = this.
|
|
1512
|
+
temp[j] = this.l[i];
|
|
1486
1513
|
tempNodes[j] = this.g[i];
|
|
1487
1514
|
tempRows && (tempRows[j] = this.h[i]);
|
|
1488
|
-
tempIndexes && (tempIndexes[j] = this.
|
|
1515
|
+
tempIndexes && (tempIndexes[j] = this.i[i]);
|
|
1489
1516
|
j = newIndicesNext[j];
|
|
1490
1517
|
newIndices.set(key, j);
|
|
1491
1518
|
} else
|
|
@@ -1493,25 +1520,25 @@ function updateKeyedMap() {
|
|
|
1493
1520
|
}
|
|
1494
1521
|
for (j = start; j < newLen; j++) {
|
|
1495
1522
|
if (j in temp) {
|
|
1496
|
-
this.
|
|
1523
|
+
this.l[j] = temp[j];
|
|
1497
1524
|
this.g[j] = tempNodes[j];
|
|
1498
1525
|
if (tempRows) {
|
|
1499
1526
|
this.h[j] = tempRows[j];
|
|
1500
1527
|
this.h[j].write(newItems[j]);
|
|
1501
1528
|
}
|
|
1502
1529
|
if (tempIndexes) {
|
|
1503
|
-
this.
|
|
1504
|
-
this.
|
|
1530
|
+
this.i[j] = tempIndexes[j];
|
|
1531
|
+
this.i[j].write(j);
|
|
1505
1532
|
}
|
|
1506
1533
|
} else {
|
|
1507
|
-
this.
|
|
1534
|
+
this.l[j] = compute(this.g[j] = new Owner(), mapper, null);
|
|
1508
1535
|
}
|
|
1509
1536
|
}
|
|
1510
|
-
this.
|
|
1511
|
-
this.
|
|
1537
|
+
this.l = this.l.slice(0, this.w = newLen);
|
|
1538
|
+
this.s = newItems.slice(0);
|
|
1512
1539
|
}
|
|
1513
1540
|
});
|
|
1514
|
-
return this.
|
|
1541
|
+
return this.l;
|
|
1515
1542
|
}
|
|
1516
1543
|
function compare(key, a, b) {
|
|
1517
1544
|
return key ? key(a) === key(b) : true;
|
|
@@ -1528,11 +1555,11 @@ exports.NotReadyError = NotReadyError;
|
|
|
1528
1555
|
exports.Owner = Owner;
|
|
1529
1556
|
exports.Queue = Queue;
|
|
1530
1557
|
exports.SUPPORTS_PROXY = SUPPORTS_PROXY;
|
|
1531
|
-
exports.catchError = catchError;
|
|
1532
1558
|
exports.createAsync = createAsync;
|
|
1533
1559
|
exports.createBoundary = createBoundary;
|
|
1534
1560
|
exports.createContext = createContext;
|
|
1535
1561
|
exports.createEffect = createEffect;
|
|
1562
|
+
exports.createErrorBoundary = createErrorBoundary;
|
|
1536
1563
|
exports.createMemo = createMemo;
|
|
1537
1564
|
exports.createProjection = createProjection;
|
|
1538
1565
|
exports.createRenderEffect = createRenderEffect;
|