@solidjs/signals 0.0.5 → 0.0.6
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 +33 -11
- package/dist/node.cjs +139 -117
- package/dist/prod.js +139 -117
- package/dist/types/core/index.d.ts +1 -1
- package/dist/types/core/suspense.d.ts +1 -1
- package/dist/types/signals.d.ts +3 -3
- package/package.json +1 -1
package/dist/dev.js
CHANGED
|
@@ -803,14 +803,14 @@ var LiveComputation = class extends EagerComputation {
|
|
|
803
803
|
return this._value;
|
|
804
804
|
}
|
|
805
805
|
};
|
|
806
|
-
function createSuspense(fn,
|
|
806
|
+
function createSuspense(fn, fallback) {
|
|
807
807
|
const queue = new SuspenseQueue();
|
|
808
808
|
const tree = createBoundary(() => {
|
|
809
809
|
const child = new Computation(null, fn);
|
|
810
810
|
return new LiveComputation(null, () => flatten(child.wait()));
|
|
811
811
|
}, queue);
|
|
812
812
|
const equality = new Computation(null, () => queue._signal.read() || queue._fallback);
|
|
813
|
-
const comp = new Computation(null, () => equality.read() ?
|
|
813
|
+
const comp = new Computation(null, () => equality.read() ? fallback() : tree.read());
|
|
814
814
|
return comp.read.bind(comp);
|
|
815
815
|
}
|
|
816
816
|
|
|
@@ -926,14 +926,36 @@ function runWithOwner(owner, run) {
|
|
|
926
926
|
return void 0;
|
|
927
927
|
}
|
|
928
928
|
}
|
|
929
|
-
function
|
|
929
|
+
function createErrorBoundary(fn, fallback) {
|
|
930
930
|
const owner = new Owner();
|
|
931
|
+
const error = new Computation(null, null);
|
|
932
|
+
const reset = new Computation(null, null, { equals: false });
|
|
933
|
+
const handler = (err) => error.write({ _error: err });
|
|
931
934
|
owner._handlers = owner._handlers ? [handler, ...owner._handlers] : [handler];
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
935
|
+
const guarded = compute(
|
|
936
|
+
owner,
|
|
937
|
+
() => {
|
|
938
|
+
const c = new Computation(null, () => (reset.read(), fn()));
|
|
939
|
+
const f = new Computation(null, () => flatten(c.read()));
|
|
940
|
+
f._setError = function(error2) {
|
|
941
|
+
this.handleError(error2);
|
|
942
|
+
};
|
|
943
|
+
return f;
|
|
944
|
+
},
|
|
945
|
+
null
|
|
946
|
+
);
|
|
947
|
+
const decision = new Computation(null, () => {
|
|
948
|
+
if (!error.read()) {
|
|
949
|
+
const resolved = guarded.read();
|
|
950
|
+
if (!error.read())
|
|
951
|
+
return resolved;
|
|
952
|
+
}
|
|
953
|
+
return fallback(error.read()._error, () => {
|
|
954
|
+
error.write(null);
|
|
955
|
+
reset.write(null);
|
|
956
|
+
});
|
|
957
|
+
});
|
|
958
|
+
return decision.read.bind(decision);
|
|
937
959
|
}
|
|
938
960
|
|
|
939
961
|
// src/store/store.ts
|
|
@@ -1414,10 +1436,10 @@ function updateKeyedMap() {
|
|
|
1414
1436
|
runWithOwner(this._owner, () => {
|
|
1415
1437
|
let i, j, mapper = this._rows ? () => {
|
|
1416
1438
|
this._rows[j] = new Computation(newItems[j], null);
|
|
1417
|
-
this._indexes[j] = new Computation(j, null);
|
|
1439
|
+
this._indexes && (this._indexes[j] = new Computation(j, null));
|
|
1418
1440
|
return this._map(
|
|
1419
1441
|
Computation.prototype.read.bind(this._rows[j]),
|
|
1420
|
-
Computation.prototype.read.bind(this._indexes[j])
|
|
1442
|
+
this._indexes ? Computation.prototype.read.bind(this._indexes[j]) : void 0
|
|
1421
1443
|
);
|
|
1422
1444
|
} : this._indexes ? () => {
|
|
1423
1445
|
const item = newItems[j];
|
|
@@ -1514,4 +1536,4 @@ function compare(key, a, b) {
|
|
|
1514
1536
|
return key ? key(a) === key(b) : true;
|
|
1515
1537
|
}
|
|
1516
1538
|
|
|
1517
|
-
export { $PROXY, $RAW, $TARGET, $TRACK, Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, SUPPORTS_PROXY,
|
|
1539
|
+
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 };
|
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.
|
|
281
|
+
if (this.C)
|
|
282
282
|
this.s();
|
|
283
|
-
if (!this.
|
|
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;
|
|
@@ -346,7 +346,7 @@ var Computation = class extends Owner {
|
|
|
346
346
|
if (valueChanged) {
|
|
347
347
|
this.b[i].t(STATE_DIRTY);
|
|
348
348
|
} else if (changedFlagsMask) {
|
|
349
|
-
this.b[i].
|
|
349
|
+
this.b[i].Q(changedFlagsMask, changedFlags);
|
|
350
350
|
}
|
|
351
351
|
}
|
|
352
352
|
}
|
|
@@ -371,10 +371,10 @@ 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.
|
|
377
|
+
if (mask & this.D) {
|
|
378
378
|
this.t(STATE_DIRTY);
|
|
379
379
|
return;
|
|
380
380
|
}
|
|
@@ -388,12 +388,12 @@ var Computation = class extends Owner {
|
|
|
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
|
/**
|
|
@@ -450,7 +450,7 @@ function loadingState(node) {
|
|
|
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
|
}
|
|
@@ -466,7 +466,7 @@ function errorState(node) {
|
|
|
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,13 +601,13 @@ 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
|
-
|
|
608
|
+
E = false;
|
|
609
609
|
u = [[], [], []];
|
|
610
|
-
|
|
610
|
+
A = [];
|
|
611
611
|
enqueue(type, node) {
|
|
612
612
|
this.u[0].push(node);
|
|
613
613
|
if (type)
|
|
@@ -625,14 +625,14 @@ var Queue = class {
|
|
|
625
625
|
runEffectQueue(effects);
|
|
626
626
|
}
|
|
627
627
|
}
|
|
628
|
-
for (let i = 0; i < this.
|
|
629
|
-
this.
|
|
628
|
+
for (let i = 0; i < this.A.length; i++) {
|
|
629
|
+
this.A[i].run(type);
|
|
630
630
|
}
|
|
631
631
|
}
|
|
632
632
|
flush() {
|
|
633
|
-
if (this.
|
|
633
|
+
if (this.E)
|
|
634
634
|
return;
|
|
635
|
-
this.
|
|
635
|
+
this.E = true;
|
|
636
636
|
try {
|
|
637
637
|
this.run(EFFECT_PURE);
|
|
638
638
|
incrementClock();
|
|
@@ -640,16 +640,16 @@ var Queue = class {
|
|
|
640
640
|
this.run(EFFECT_RENDER);
|
|
641
641
|
this.run(EFFECT_USER);
|
|
642
642
|
} finally {
|
|
643
|
-
this.
|
|
643
|
+
this.E = false;
|
|
644
644
|
}
|
|
645
645
|
}
|
|
646
646
|
addChild(child) {
|
|
647
|
-
this.
|
|
647
|
+
this.A.push(child);
|
|
648
648
|
}
|
|
649
649
|
removeChild(child) {
|
|
650
|
-
const index = this.
|
|
650
|
+
const index = this.A.indexOf(child);
|
|
651
651
|
if (index >= 0)
|
|
652
|
-
this.
|
|
652
|
+
this.A.splice(index, 1);
|
|
653
653
|
}
|
|
654
654
|
};
|
|
655
655
|
var globalQueue = new Queue();
|
|
@@ -698,54 +698,54 @@ function runEffectQueue(queue) {
|
|
|
698
698
|
|
|
699
699
|
// src/core/effect.ts
|
|
700
700
|
var Effect = class extends Computation {
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
701
|
+
K;
|
|
702
|
+
L = false;
|
|
703
|
+
F;
|
|
704
|
+
B;
|
|
705
705
|
e;
|
|
706
706
|
constructor(initialValue, compute2, effect, options) {
|
|
707
707
|
var _a;
|
|
708
708
|
super(initialValue, compute2, options);
|
|
709
|
-
this.
|
|
710
|
-
this.
|
|
711
|
-
this.
|
|
709
|
+
this.K = effect;
|
|
710
|
+
this.F = initialValue;
|
|
711
|
+
this.B = (options == null ? void 0 : options.render) ? EFFECT_RENDER : EFFECT_USER;
|
|
712
712
|
this.e = ((_a = getOwner()) == null ? void 0 : _a.e) || globalQueue;
|
|
713
713
|
this.s();
|
|
714
|
-
this.
|
|
714
|
+
this.B === EFFECT_USER ? this.e.enqueue(this.B, this) : this.R();
|
|
715
715
|
}
|
|
716
716
|
write(value, flags = 0) {
|
|
717
717
|
var _a, _b;
|
|
718
718
|
const currentFlags = this.f;
|
|
719
719
|
this.f = flags;
|
|
720
|
-
if (this.
|
|
720
|
+
if (this.B === EFFECT_RENDER && (flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
|
|
721
721
|
(_b = (_a = this.e).S) == null ? void 0 : _b.call(_a, this);
|
|
722
722
|
}
|
|
723
723
|
if (value === UNCHANGED)
|
|
724
724
|
return this.d;
|
|
725
725
|
this.d = value;
|
|
726
|
-
this.
|
|
726
|
+
this.L = true;
|
|
727
727
|
return value;
|
|
728
728
|
}
|
|
729
729
|
t(state) {
|
|
730
730
|
if (this.a >= state)
|
|
731
731
|
return;
|
|
732
732
|
if (this.a === STATE_CLEAN)
|
|
733
|
-
this.e.enqueue(this.
|
|
733
|
+
this.e.enqueue(this.B, this);
|
|
734
734
|
this.a = state;
|
|
735
735
|
}
|
|
736
|
-
|
|
736
|
+
J(error) {
|
|
737
737
|
this.handleError(error);
|
|
738
738
|
}
|
|
739
739
|
x() {
|
|
740
|
-
this.
|
|
741
|
-
this.
|
|
740
|
+
this.K = void 0;
|
|
741
|
+
this.F = void 0;
|
|
742
742
|
super.x();
|
|
743
743
|
}
|
|
744
744
|
R() {
|
|
745
|
-
if (this.
|
|
746
|
-
this.
|
|
747
|
-
this.
|
|
748
|
-
this.
|
|
745
|
+
if (this.L && this.a !== STATE_DISPOSED) {
|
|
746
|
+
this.K(this.d, this.F);
|
|
747
|
+
this.F = this.d;
|
|
748
|
+
this.L = false;
|
|
749
749
|
}
|
|
750
750
|
}
|
|
751
751
|
};
|
|
@@ -770,7 +770,7 @@ var EagerComputation = class extends Computation {
|
|
|
770
770
|
var SuspenseQueue = class extends Queue {
|
|
771
771
|
g = /* @__PURE__ */ new Set();
|
|
772
772
|
q = false;
|
|
773
|
-
|
|
773
|
+
M = new Computation(false, null);
|
|
774
774
|
run(type) {
|
|
775
775
|
if (type && this.q)
|
|
776
776
|
return;
|
|
@@ -781,13 +781,13 @@ var SuspenseQueue = class extends Queue {
|
|
|
781
781
|
this.g.add(node);
|
|
782
782
|
if (!this.q) {
|
|
783
783
|
this.q = true;
|
|
784
|
-
queueTask(() => this.
|
|
784
|
+
queueTask(() => this.M.write(true));
|
|
785
785
|
}
|
|
786
786
|
} else {
|
|
787
787
|
this.g.delete(node);
|
|
788
788
|
if (this.g.size === 0) {
|
|
789
789
|
this.q = false;
|
|
790
|
-
queueTask(() => this.
|
|
790
|
+
queueTask(() => this.M.write(false));
|
|
791
791
|
}
|
|
792
792
|
}
|
|
793
793
|
}
|
|
@@ -803,14 +803,14 @@ var LiveComputation = class extends EagerComputation {
|
|
|
803
803
|
return this.d;
|
|
804
804
|
}
|
|
805
805
|
};
|
|
806
|
-
function createSuspense(fn,
|
|
806
|
+
function createSuspense(fn, fallback) {
|
|
807
807
|
const queue = new SuspenseQueue();
|
|
808
808
|
const tree = createBoundary(() => {
|
|
809
809
|
const child = new Computation(null, fn);
|
|
810
810
|
return new LiveComputation(null, () => flatten(child.wait()));
|
|
811
811
|
}, queue);
|
|
812
|
-
const equality = new Computation(null, () => queue.
|
|
813
|
-
const comp = new Computation(null, () => equality.read() ?
|
|
812
|
+
const equality = new Computation(null, () => queue.M.read() || queue.q);
|
|
813
|
+
const comp = new Computation(null, () => equality.read() ? fallback() : tree.read());
|
|
814
814
|
return comp.read.bind(comp);
|
|
815
815
|
}
|
|
816
816
|
|
|
@@ -927,14 +927,36 @@ function runWithOwner(owner, run) {
|
|
|
927
927
|
return void 0;
|
|
928
928
|
}
|
|
929
929
|
}
|
|
930
|
-
function
|
|
930
|
+
function createErrorBoundary(fn, fallback) {
|
|
931
931
|
const owner = new Owner();
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
932
|
+
const error = new Computation(null, null);
|
|
933
|
+
const reset = new Computation(null, null, { equals: false });
|
|
934
|
+
const handler = (err) => error.write({ z: err });
|
|
935
|
+
owner.k = owner.k ? [handler, ...owner.k] : [handler];
|
|
936
|
+
const guarded = compute(
|
|
937
|
+
owner,
|
|
938
|
+
() => {
|
|
939
|
+
const c = new Computation(null, () => (reset.read(), fn()));
|
|
940
|
+
const f = new Computation(null, () => flatten(c.read()));
|
|
941
|
+
f.J = function(error2) {
|
|
942
|
+
this.handleError(error2);
|
|
943
|
+
};
|
|
944
|
+
return f;
|
|
945
|
+
},
|
|
946
|
+
null
|
|
947
|
+
);
|
|
948
|
+
const decision = new Computation(null, () => {
|
|
949
|
+
if (!error.read()) {
|
|
950
|
+
const resolved = guarded.read();
|
|
951
|
+
if (!error.read())
|
|
952
|
+
return resolved;
|
|
953
|
+
}
|
|
954
|
+
return fallback(error.read().z, () => {
|
|
955
|
+
error.write(null);
|
|
956
|
+
reset.write(null);
|
|
957
|
+
});
|
|
958
|
+
});
|
|
959
|
+
return decision.read.bind(decision);
|
|
938
960
|
}
|
|
939
961
|
|
|
940
962
|
// src/store/store.ts
|
|
@@ -1402,12 +1424,12 @@ function mapArray(list, map, options) {
|
|
|
1402
1424
|
w: 0,
|
|
1403
1425
|
U: list,
|
|
1404
1426
|
r: [],
|
|
1405
|
-
|
|
1406
|
-
|
|
1427
|
+
N: map,
|
|
1428
|
+
l: [],
|
|
1407
1429
|
g: [],
|
|
1408
1430
|
y: keyFn,
|
|
1409
1431
|
h: keyFn || (options == null ? void 0 : options.keyed) === false ? [] : void 0,
|
|
1410
|
-
|
|
1432
|
+
i: map.length > 1 ? [] : void 0,
|
|
1411
1433
|
q: options == null ? void 0 : options.fallback
|
|
1412
1434
|
});
|
|
1413
1435
|
}
|
|
@@ -1417,31 +1439,31 @@ function updateKeyedMap() {
|
|
|
1417
1439
|
runWithOwner(this.T, () => {
|
|
1418
1440
|
let i, j, mapper = this.h ? () => {
|
|
1419
1441
|
this.h[j] = new Computation(newItems[j], null);
|
|
1420
|
-
this.
|
|
1421
|
-
return this.
|
|
1442
|
+
this.i && (this.i[j] = new Computation(j, null));
|
|
1443
|
+
return this.N(
|
|
1422
1444
|
Computation.prototype.read.bind(this.h[j]),
|
|
1423
|
-
Computation.prototype.read.bind(this.
|
|
1445
|
+
this.i ? Computation.prototype.read.bind(this.i[j]) : void 0
|
|
1424
1446
|
);
|
|
1425
|
-
} : this.
|
|
1447
|
+
} : this.i ? () => {
|
|
1426
1448
|
const item = newItems[j];
|
|
1427
|
-
this.
|
|
1428
|
-
return this.
|
|
1449
|
+
this.i[j] = new Computation(j, null);
|
|
1450
|
+
return this.N(() => item, Computation.prototype.read.bind(this.i[j]));
|
|
1429
1451
|
} : () => {
|
|
1430
1452
|
const item = newItems[j];
|
|
1431
|
-
return this.
|
|
1453
|
+
return this.N(() => item);
|
|
1432
1454
|
};
|
|
1433
1455
|
if (newLen === 0) {
|
|
1434
1456
|
if (this.w !== 0) {
|
|
1435
1457
|
this.T.dispose(false);
|
|
1436
1458
|
this.g = [];
|
|
1437
1459
|
this.r = [];
|
|
1438
|
-
this.
|
|
1460
|
+
this.l = [];
|
|
1439
1461
|
this.w = 0;
|
|
1440
1462
|
this.h && (this.h = []);
|
|
1441
|
-
this.
|
|
1463
|
+
this.i && (this.i = []);
|
|
1442
1464
|
}
|
|
1443
|
-
if (this.q && !this.
|
|
1444
|
-
this.
|
|
1465
|
+
if (this.q && !this.l[0]) {
|
|
1466
|
+
this.l[0] = compute(
|
|
1445
1467
|
this.g[0] = new Owner(),
|
|
1446
1468
|
this.q,
|
|
1447
1469
|
null
|
|
@@ -1450,23 +1472,23 @@ function updateKeyedMap() {
|
|
|
1450
1472
|
} else if (this.w === 0) {
|
|
1451
1473
|
if (this.g[0])
|
|
1452
1474
|
this.g[0].dispose();
|
|
1453
|
-
this.
|
|
1475
|
+
this.l = new Array(newLen);
|
|
1454
1476
|
for (j = 0; j < newLen; j++) {
|
|
1455
1477
|
this.r[j] = newItems[j];
|
|
1456
|
-
this.
|
|
1478
|
+
this.l[j] = compute(this.g[j] = new Owner(), mapper, null);
|
|
1457
1479
|
}
|
|
1458
1480
|
this.w = newLen;
|
|
1459
1481
|
} 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.
|
|
1482
|
+
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;
|
|
1461
1483
|
for (start = 0, end = Math.min(this.w, newLen); start < end && (this.r[start] === newItems[start] || this.h && compare(this.y, this.r[start], newItems[start])); start++) {
|
|
1462
1484
|
if (this.h)
|
|
1463
1485
|
this.h[start].write(newItems[start]);
|
|
1464
1486
|
}
|
|
1465
1487
|
for (end = this.w - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.r[end] === newItems[newEnd] || this.h && compare(this.y, this.r[end], newItems[newEnd])); end--, newEnd--) {
|
|
1466
|
-
temp[newEnd] = this.
|
|
1488
|
+
temp[newEnd] = this.l[end];
|
|
1467
1489
|
tempNodes[newEnd] = this.g[end];
|
|
1468
1490
|
tempRows && (tempRows[newEnd] = this.h[end]);
|
|
1469
|
-
tempIndexes && (tempIndexes[newEnd] = this.
|
|
1491
|
+
tempIndexes && (tempIndexes[newEnd] = this.i[end]);
|
|
1470
1492
|
}
|
|
1471
1493
|
newIndices = /* @__PURE__ */ new Map();
|
|
1472
1494
|
newIndicesNext = new Array(newEnd + 1);
|
|
@@ -1482,10 +1504,10 @@ function updateKeyedMap() {
|
|
|
1482
1504
|
key = this.y ? this.y(item) : item;
|
|
1483
1505
|
j = newIndices.get(key);
|
|
1484
1506
|
if (j !== void 0 && j !== -1) {
|
|
1485
|
-
temp[j] = this.
|
|
1507
|
+
temp[j] = this.l[i];
|
|
1486
1508
|
tempNodes[j] = this.g[i];
|
|
1487
1509
|
tempRows && (tempRows[j] = this.h[i]);
|
|
1488
|
-
tempIndexes && (tempIndexes[j] = this.
|
|
1510
|
+
tempIndexes && (tempIndexes[j] = this.i[i]);
|
|
1489
1511
|
j = newIndicesNext[j];
|
|
1490
1512
|
newIndices.set(key, j);
|
|
1491
1513
|
} else
|
|
@@ -1493,25 +1515,25 @@ function updateKeyedMap() {
|
|
|
1493
1515
|
}
|
|
1494
1516
|
for (j = start; j < newLen; j++) {
|
|
1495
1517
|
if (j in temp) {
|
|
1496
|
-
this.
|
|
1518
|
+
this.l[j] = temp[j];
|
|
1497
1519
|
this.g[j] = tempNodes[j];
|
|
1498
1520
|
if (tempRows) {
|
|
1499
1521
|
this.h[j] = tempRows[j];
|
|
1500
1522
|
this.h[j].write(newItems[j]);
|
|
1501
1523
|
}
|
|
1502
1524
|
if (tempIndexes) {
|
|
1503
|
-
this.
|
|
1504
|
-
this.
|
|
1525
|
+
this.i[j] = tempIndexes[j];
|
|
1526
|
+
this.i[j].write(j);
|
|
1505
1527
|
}
|
|
1506
1528
|
} else {
|
|
1507
|
-
this.
|
|
1529
|
+
this.l[j] = compute(this.g[j] = new Owner(), mapper, null);
|
|
1508
1530
|
}
|
|
1509
1531
|
}
|
|
1510
|
-
this.
|
|
1532
|
+
this.l = this.l.slice(0, this.w = newLen);
|
|
1511
1533
|
this.r = newItems.slice(0);
|
|
1512
1534
|
}
|
|
1513
1535
|
});
|
|
1514
|
-
return this.
|
|
1536
|
+
return this.l;
|
|
1515
1537
|
}
|
|
1516
1538
|
function compare(key, a, b) {
|
|
1517
1539
|
return key ? key(a) === key(b) : true;
|
|
@@ -1528,11 +1550,11 @@ exports.NotReadyError = NotReadyError;
|
|
|
1528
1550
|
exports.Owner = Owner;
|
|
1529
1551
|
exports.Queue = Queue;
|
|
1530
1552
|
exports.SUPPORTS_PROXY = SUPPORTS_PROXY;
|
|
1531
|
-
exports.catchError = catchError;
|
|
1532
1553
|
exports.createAsync = createAsync;
|
|
1533
1554
|
exports.createBoundary = createBoundary;
|
|
1534
1555
|
exports.createContext = createContext;
|
|
1535
1556
|
exports.createEffect = createEffect;
|
|
1557
|
+
exports.createErrorBoundary = createErrorBoundary;
|
|
1536
1558
|
exports.createMemo = createMemo;
|
|
1537
1559
|
exports.createProjection = createProjection;
|
|
1538
1560
|
exports.createRenderEffect = createRenderEffect;
|
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.
|
|
277
|
+
P() {
|
|
278
|
+
if (this.C)
|
|
279
279
|
this.s();
|
|
280
|
-
if (!this.
|
|
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;
|
|
@@ -343,7 +343,7 @@ var Computation = class extends Owner {
|
|
|
343
343
|
if (valueChanged) {
|
|
344
344
|
this.b[i].t(STATE_DIRTY);
|
|
345
345
|
} else if (changedFlagsMask) {
|
|
346
|
-
this.b[i].
|
|
346
|
+
this.b[i].Q(changedFlagsMask, changedFlags);
|
|
347
347
|
}
|
|
348
348
|
}
|
|
349
349
|
}
|
|
@@ -368,10 +368,10 @@ 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.
|
|
374
|
+
if (mask & this.D) {
|
|
375
375
|
this.t(STATE_DIRTY);
|
|
376
376
|
return;
|
|
377
377
|
}
|
|
@@ -385,12 +385,12 @@ var Computation = class extends Owner {
|
|
|
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
|
/**
|
|
@@ -447,7 +447,7 @@ function loadingState(node) {
|
|
|
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
|
}
|
|
@@ -463,7 +463,7 @@ function errorState(node) {
|
|
|
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,13 +597,13 @@ 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
|
-
|
|
604
|
+
E = false;
|
|
605
605
|
u = [[], [], []];
|
|
606
|
-
|
|
606
|
+
A = [];
|
|
607
607
|
enqueue(type, node) {
|
|
608
608
|
this.u[0].push(node);
|
|
609
609
|
if (type)
|
|
@@ -621,14 +621,14 @@ var Queue = class {
|
|
|
621
621
|
runEffectQueue(effects);
|
|
622
622
|
}
|
|
623
623
|
}
|
|
624
|
-
for (let i = 0; i < this.
|
|
625
|
-
this.
|
|
624
|
+
for (let i = 0; i < this.A.length; i++) {
|
|
625
|
+
this.A[i].run(type);
|
|
626
626
|
}
|
|
627
627
|
}
|
|
628
628
|
flush() {
|
|
629
|
-
if (this.
|
|
629
|
+
if (this.E)
|
|
630
630
|
return;
|
|
631
|
-
this.
|
|
631
|
+
this.E = true;
|
|
632
632
|
try {
|
|
633
633
|
this.run(EFFECT_PURE);
|
|
634
634
|
incrementClock();
|
|
@@ -636,16 +636,16 @@ var Queue = class {
|
|
|
636
636
|
this.run(EFFECT_RENDER);
|
|
637
637
|
this.run(EFFECT_USER);
|
|
638
638
|
} finally {
|
|
639
|
-
this.
|
|
639
|
+
this.E = false;
|
|
640
640
|
}
|
|
641
641
|
}
|
|
642
642
|
addChild(child) {
|
|
643
|
-
this.
|
|
643
|
+
this.A.push(child);
|
|
644
644
|
}
|
|
645
645
|
removeChild(child) {
|
|
646
|
-
const index = this.
|
|
646
|
+
const index = this.A.indexOf(child);
|
|
647
647
|
if (index >= 0)
|
|
648
|
-
this.
|
|
648
|
+
this.A.splice(index, 1);
|
|
649
649
|
}
|
|
650
650
|
};
|
|
651
651
|
var globalQueue = new Queue();
|
|
@@ -694,52 +694,52 @@ function runEffectQueue(queue) {
|
|
|
694
694
|
|
|
695
695
|
// src/core/effect.ts
|
|
696
696
|
var Effect = class extends Computation {
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
697
|
+
K;
|
|
698
|
+
L = false;
|
|
699
|
+
F;
|
|
700
|
+
B;
|
|
701
701
|
e;
|
|
702
702
|
constructor(initialValue, compute2, effect, options) {
|
|
703
703
|
super(initialValue, compute2, options);
|
|
704
|
-
this.
|
|
705
|
-
this.
|
|
706
|
-
this.
|
|
704
|
+
this.K = effect;
|
|
705
|
+
this.F = initialValue;
|
|
706
|
+
this.B = options?.render ? EFFECT_RENDER : EFFECT_USER;
|
|
707
707
|
this.e = getOwner()?.e || globalQueue;
|
|
708
708
|
this.s();
|
|
709
|
-
this.
|
|
709
|
+
this.B === EFFECT_USER ? this.e.enqueue(this.B, this) : this.R();
|
|
710
710
|
}
|
|
711
711
|
write(value, flags = 0) {
|
|
712
712
|
const currentFlags = this.f;
|
|
713
713
|
this.f = flags;
|
|
714
|
-
if (this.
|
|
714
|
+
if (this.B === EFFECT_RENDER && (flags & LOADING_BIT) !== (currentFlags & LOADING_BIT)) {
|
|
715
715
|
this.e.S?.(this);
|
|
716
716
|
}
|
|
717
717
|
if (value === UNCHANGED)
|
|
718
718
|
return this.d;
|
|
719
719
|
this.d = value;
|
|
720
|
-
this.
|
|
720
|
+
this.L = true;
|
|
721
721
|
return value;
|
|
722
722
|
}
|
|
723
723
|
t(state) {
|
|
724
724
|
if (this.a >= state)
|
|
725
725
|
return;
|
|
726
726
|
if (this.a === STATE_CLEAN)
|
|
727
|
-
this.e.enqueue(this.
|
|
727
|
+
this.e.enqueue(this.B, this);
|
|
728
728
|
this.a = state;
|
|
729
729
|
}
|
|
730
|
-
|
|
730
|
+
J(error) {
|
|
731
731
|
this.handleError(error);
|
|
732
732
|
}
|
|
733
733
|
x() {
|
|
734
|
-
this.
|
|
735
|
-
this.
|
|
734
|
+
this.K = void 0;
|
|
735
|
+
this.F = void 0;
|
|
736
736
|
super.x();
|
|
737
737
|
}
|
|
738
738
|
R() {
|
|
739
|
-
if (this.
|
|
740
|
-
this.
|
|
741
|
-
this.
|
|
742
|
-
this.
|
|
739
|
+
if (this.L && this.a !== STATE_DISPOSED) {
|
|
740
|
+
this.K(this.d, this.F);
|
|
741
|
+
this.F = this.d;
|
|
742
|
+
this.L = false;
|
|
743
743
|
}
|
|
744
744
|
}
|
|
745
745
|
};
|
|
@@ -763,7 +763,7 @@ var EagerComputation = class extends Computation {
|
|
|
763
763
|
var SuspenseQueue = class extends Queue {
|
|
764
764
|
g = /* @__PURE__ */ new Set();
|
|
765
765
|
q = false;
|
|
766
|
-
|
|
766
|
+
M = new Computation(false, null);
|
|
767
767
|
run(type) {
|
|
768
768
|
if (type && this.q)
|
|
769
769
|
return;
|
|
@@ -774,13 +774,13 @@ var SuspenseQueue = class extends Queue {
|
|
|
774
774
|
this.g.add(node);
|
|
775
775
|
if (!this.q) {
|
|
776
776
|
this.q = true;
|
|
777
|
-
queueTask(() => this.
|
|
777
|
+
queueTask(() => this.M.write(true));
|
|
778
778
|
}
|
|
779
779
|
} else {
|
|
780
780
|
this.g.delete(node);
|
|
781
781
|
if (this.g.size === 0) {
|
|
782
782
|
this.q = false;
|
|
783
|
-
queueTask(() => this.
|
|
783
|
+
queueTask(() => this.M.write(false));
|
|
784
784
|
}
|
|
785
785
|
}
|
|
786
786
|
}
|
|
@@ -795,14 +795,14 @@ var LiveComputation = class extends EagerComputation {
|
|
|
795
795
|
return this.d;
|
|
796
796
|
}
|
|
797
797
|
};
|
|
798
|
-
function createSuspense(fn,
|
|
798
|
+
function createSuspense(fn, fallback) {
|
|
799
799
|
const queue = new SuspenseQueue();
|
|
800
800
|
const tree = createBoundary(() => {
|
|
801
801
|
const child = new Computation(null, fn);
|
|
802
802
|
return new LiveComputation(null, () => flatten(child.wait()));
|
|
803
803
|
}, queue);
|
|
804
|
-
const equality = new Computation(null, () => queue.
|
|
805
|
-
const comp = new Computation(null, () => equality.read() ?
|
|
804
|
+
const equality = new Computation(null, () => queue.M.read() || queue.q);
|
|
805
|
+
const comp = new Computation(null, () => equality.read() ? fallback() : tree.read());
|
|
806
806
|
return comp.read.bind(comp);
|
|
807
807
|
}
|
|
808
808
|
|
|
@@ -918,14 +918,36 @@ function runWithOwner(owner, run) {
|
|
|
918
918
|
return void 0;
|
|
919
919
|
}
|
|
920
920
|
}
|
|
921
|
-
function
|
|
921
|
+
function createErrorBoundary(fn, fallback) {
|
|
922
922
|
const owner = new Owner();
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
923
|
+
const error = new Computation(null, null);
|
|
924
|
+
const reset = new Computation(null, null, { equals: false });
|
|
925
|
+
const handler = (err) => error.write({ z: err });
|
|
926
|
+
owner.k = owner.k ? [handler, ...owner.k] : [handler];
|
|
927
|
+
const guarded = compute(
|
|
928
|
+
owner,
|
|
929
|
+
() => {
|
|
930
|
+
const c = new Computation(null, () => (reset.read(), fn()));
|
|
931
|
+
const f = new Computation(null, () => flatten(c.read()));
|
|
932
|
+
f.J = function(error2) {
|
|
933
|
+
this.handleError(error2);
|
|
934
|
+
};
|
|
935
|
+
return f;
|
|
936
|
+
},
|
|
937
|
+
null
|
|
938
|
+
);
|
|
939
|
+
const decision = new Computation(null, () => {
|
|
940
|
+
if (!error.read()) {
|
|
941
|
+
const resolved = guarded.read();
|
|
942
|
+
if (!error.read())
|
|
943
|
+
return resolved;
|
|
944
|
+
}
|
|
945
|
+
return fallback(error.read().z, () => {
|
|
946
|
+
error.write(null);
|
|
947
|
+
reset.write(null);
|
|
948
|
+
});
|
|
949
|
+
});
|
|
950
|
+
return decision.read.bind(decision);
|
|
929
951
|
}
|
|
930
952
|
|
|
931
953
|
// src/store/store.ts
|
|
@@ -1391,12 +1413,12 @@ function mapArray(list, map, options) {
|
|
|
1391
1413
|
w: 0,
|
|
1392
1414
|
U: list,
|
|
1393
1415
|
r: [],
|
|
1394
|
-
|
|
1395
|
-
|
|
1416
|
+
N: map,
|
|
1417
|
+
l: [],
|
|
1396
1418
|
g: [],
|
|
1397
1419
|
y: keyFn,
|
|
1398
1420
|
h: keyFn || options?.keyed === false ? [] : void 0,
|
|
1399
|
-
|
|
1421
|
+
i: map.length > 1 ? [] : void 0,
|
|
1400
1422
|
q: options?.fallback
|
|
1401
1423
|
});
|
|
1402
1424
|
}
|
|
@@ -1406,31 +1428,31 @@ function updateKeyedMap() {
|
|
|
1406
1428
|
runWithOwner(this.T, () => {
|
|
1407
1429
|
let i, j, mapper = this.h ? () => {
|
|
1408
1430
|
this.h[j] = new Computation(newItems[j], null);
|
|
1409
|
-
this.
|
|
1410
|
-
return this.
|
|
1431
|
+
this.i && (this.i[j] = new Computation(j, null));
|
|
1432
|
+
return this.N(
|
|
1411
1433
|
Computation.prototype.read.bind(this.h[j]),
|
|
1412
|
-
Computation.prototype.read.bind(this.
|
|
1434
|
+
this.i ? Computation.prototype.read.bind(this.i[j]) : void 0
|
|
1413
1435
|
);
|
|
1414
|
-
} : this.
|
|
1436
|
+
} : this.i ? () => {
|
|
1415
1437
|
const item = newItems[j];
|
|
1416
|
-
this.
|
|
1417
|
-
return this.
|
|
1438
|
+
this.i[j] = new Computation(j, null);
|
|
1439
|
+
return this.N(() => item, Computation.prototype.read.bind(this.i[j]));
|
|
1418
1440
|
} : () => {
|
|
1419
1441
|
const item = newItems[j];
|
|
1420
|
-
return this.
|
|
1442
|
+
return this.N(() => item);
|
|
1421
1443
|
};
|
|
1422
1444
|
if (newLen === 0) {
|
|
1423
1445
|
if (this.w !== 0) {
|
|
1424
1446
|
this.T.dispose(false);
|
|
1425
1447
|
this.g = [];
|
|
1426
1448
|
this.r = [];
|
|
1427
|
-
this.
|
|
1449
|
+
this.l = [];
|
|
1428
1450
|
this.w = 0;
|
|
1429
1451
|
this.h && (this.h = []);
|
|
1430
|
-
this.
|
|
1452
|
+
this.i && (this.i = []);
|
|
1431
1453
|
}
|
|
1432
|
-
if (this.q && !this.
|
|
1433
|
-
this.
|
|
1454
|
+
if (this.q && !this.l[0]) {
|
|
1455
|
+
this.l[0] = compute(
|
|
1434
1456
|
this.g[0] = new Owner(),
|
|
1435
1457
|
this.q,
|
|
1436
1458
|
null
|
|
@@ -1439,23 +1461,23 @@ function updateKeyedMap() {
|
|
|
1439
1461
|
} else if (this.w === 0) {
|
|
1440
1462
|
if (this.g[0])
|
|
1441
1463
|
this.g[0].dispose();
|
|
1442
|
-
this.
|
|
1464
|
+
this.l = new Array(newLen);
|
|
1443
1465
|
for (j = 0; j < newLen; j++) {
|
|
1444
1466
|
this.r[j] = newItems[j];
|
|
1445
|
-
this.
|
|
1467
|
+
this.l[j] = compute(this.g[j] = new Owner(), mapper, null);
|
|
1446
1468
|
}
|
|
1447
1469
|
this.w = newLen;
|
|
1448
1470
|
} 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.
|
|
1471
|
+
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;
|
|
1450
1472
|
for (start = 0, end = Math.min(this.w, newLen); start < end && (this.r[start] === newItems[start] || this.h && compare(this.y, this.r[start], newItems[start])); start++) {
|
|
1451
1473
|
if (this.h)
|
|
1452
1474
|
this.h[start].write(newItems[start]);
|
|
1453
1475
|
}
|
|
1454
1476
|
for (end = this.w - 1, newEnd = newLen - 1; end >= start && newEnd >= start && (this.r[end] === newItems[newEnd] || this.h && compare(this.y, this.r[end], newItems[newEnd])); end--, newEnd--) {
|
|
1455
|
-
temp[newEnd] = this.
|
|
1477
|
+
temp[newEnd] = this.l[end];
|
|
1456
1478
|
tempNodes[newEnd] = this.g[end];
|
|
1457
1479
|
tempRows && (tempRows[newEnd] = this.h[end]);
|
|
1458
|
-
tempIndexes && (tempIndexes[newEnd] = this.
|
|
1480
|
+
tempIndexes && (tempIndexes[newEnd] = this.i[end]);
|
|
1459
1481
|
}
|
|
1460
1482
|
newIndices = /* @__PURE__ */ new Map();
|
|
1461
1483
|
newIndicesNext = new Array(newEnd + 1);
|
|
@@ -1471,10 +1493,10 @@ function updateKeyedMap() {
|
|
|
1471
1493
|
key = this.y ? this.y(item) : item;
|
|
1472
1494
|
j = newIndices.get(key);
|
|
1473
1495
|
if (j !== void 0 && j !== -1) {
|
|
1474
|
-
temp[j] = this.
|
|
1496
|
+
temp[j] = this.l[i];
|
|
1475
1497
|
tempNodes[j] = this.g[i];
|
|
1476
1498
|
tempRows && (tempRows[j] = this.h[i]);
|
|
1477
|
-
tempIndexes && (tempIndexes[j] = this.
|
|
1499
|
+
tempIndexes && (tempIndexes[j] = this.i[i]);
|
|
1478
1500
|
j = newIndicesNext[j];
|
|
1479
1501
|
newIndices.set(key, j);
|
|
1480
1502
|
} else
|
|
@@ -1482,28 +1504,28 @@ function updateKeyedMap() {
|
|
|
1482
1504
|
}
|
|
1483
1505
|
for (j = start; j < newLen; j++) {
|
|
1484
1506
|
if (j in temp) {
|
|
1485
|
-
this.
|
|
1507
|
+
this.l[j] = temp[j];
|
|
1486
1508
|
this.g[j] = tempNodes[j];
|
|
1487
1509
|
if (tempRows) {
|
|
1488
1510
|
this.h[j] = tempRows[j];
|
|
1489
1511
|
this.h[j].write(newItems[j]);
|
|
1490
1512
|
}
|
|
1491
1513
|
if (tempIndexes) {
|
|
1492
|
-
this.
|
|
1493
|
-
this.
|
|
1514
|
+
this.i[j] = tempIndexes[j];
|
|
1515
|
+
this.i[j].write(j);
|
|
1494
1516
|
}
|
|
1495
1517
|
} else {
|
|
1496
|
-
this.
|
|
1518
|
+
this.l[j] = compute(this.g[j] = new Owner(), mapper, null);
|
|
1497
1519
|
}
|
|
1498
1520
|
}
|
|
1499
|
-
this.
|
|
1521
|
+
this.l = this.l.slice(0, this.w = newLen);
|
|
1500
1522
|
this.r = newItems.slice(0);
|
|
1501
1523
|
}
|
|
1502
1524
|
});
|
|
1503
|
-
return this.
|
|
1525
|
+
return this.l;
|
|
1504
1526
|
}
|
|
1505
1527
|
function compare(key, a, b) {
|
|
1506
1528
|
return key ? key(a) === key(b) : true;
|
|
1507
1529
|
}
|
|
1508
1530
|
|
|
1509
|
-
export { $PROXY, $RAW, $TARGET, $TRACK, Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, SUPPORTS_PROXY,
|
|
1531
|
+
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 };
|
|
@@ -2,7 +2,7 @@ export { ContextNotFoundError, NoOwnerError, NotReadyError, type ErrorHandler }
|
|
|
2
2
|
export { Owner, createContext, getContext, setContext, hasContext, getOwner, onCleanup, type Context, type ContextRecord, type Disposable } from "./owner.js";
|
|
3
3
|
export { Computation, getObserver, isEqual, untrack, hasUpdated, isPending, latest, UNCHANGED, compute, type SignalOptions } from "./core.js";
|
|
4
4
|
export { Effect, EagerComputation } from "./effect.js";
|
|
5
|
-
export { flushSync, createBoundary, type IQueue, Queue } from "./scheduler.js";
|
|
5
|
+
export { flushSync, createBoundary, queueTask, type IQueue, Queue } from "./scheduler.js";
|
|
6
6
|
export { createSuspense } from "./suspense.js";
|
|
7
7
|
export { SUPPORTS_PROXY } from "./constants.js";
|
|
8
8
|
export * from "./flags.js";
|
|
@@ -8,4 +8,4 @@ export declare class SuspenseQueue extends Queue {
|
|
|
8
8
|
run(type: number): void;
|
|
9
9
|
_update(node: Effect): void;
|
|
10
10
|
}
|
|
11
|
-
export declare function createSuspense(fn: () => any,
|
|
11
|
+
export declare function createSuspense(fn: () => any, fallback: () => any): () => any;
|
package/dist/types/signals.d.ts
CHANGED
|
@@ -130,12 +130,12 @@ export declare function createRoot<T>(init: ((dispose: () => void) => T) | (() =
|
|
|
130
130
|
*/
|
|
131
131
|
export declare function runWithOwner<T>(owner: Owner | null, run: () => T): T | undefined;
|
|
132
132
|
/**
|
|
133
|
-
*
|
|
133
|
+
* Switches to fallback whenever an error is thrown within the context of the child scopes
|
|
134
134
|
* @param fn boundary for the error
|
|
135
|
-
* @param
|
|
135
|
+
* @param fallback an error handler that receives the error
|
|
136
136
|
*
|
|
137
137
|
* * If the error is thrown again inside the error handler, it will trigger the next available parent handler
|
|
138
138
|
*
|
|
139
139
|
* @description https://docs.solidjs.com/reference/reactive-utilities/catch-error
|
|
140
140
|
*/
|
|
141
|
-
export declare function
|
|
141
|
+
export declare function createErrorBoundary<T, U>(fn: () => T, fallback: (error: unknown, reset: () => void) => U): Accessor<T | U>;
|