@solidjs/signals 0.9.3 → 0.9.5
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 +47 -25
- package/dist/node.cjs +247 -228
- package/dist/prod.js +114 -95
- package/dist/types/core/scheduler.d.ts +1 -1
- package/package.json +1 -1
package/dist/dev.js
CHANGED
|
@@ -226,7 +226,8 @@ class GlobalQueue extends Queue {
|
|
|
226
226
|
runOptimistic(t);
|
|
227
227
|
return;
|
|
228
228
|
}
|
|
229
|
-
this._pendingNodes
|
|
229
|
+
this._pendingNodes !== activeTransition.pendingNodes &&
|
|
230
|
+
this._pendingNodes.push(...activeTransition.pendingNodes);
|
|
230
231
|
this._optimisticNodes !== activeTransition.optimisticNodes &&
|
|
231
232
|
this._optimisticNodes.push(...activeTransition.optimisticNodes);
|
|
232
233
|
this.restoreQueues(activeTransition.queueStash);
|
|
@@ -255,10 +256,12 @@ class GlobalQueue extends Queue {
|
|
|
255
256
|
}
|
|
256
257
|
return false;
|
|
257
258
|
}
|
|
258
|
-
initTransition(
|
|
259
|
-
if (
|
|
259
|
+
initTransition(transition) {
|
|
260
|
+
if (transition) transition = currentTransition(transition);
|
|
261
|
+
if (transition && transition === activeTransition) return;
|
|
262
|
+
if (!transition && activeTransition && activeTransition.time === clock) return;
|
|
260
263
|
if (!activeTransition) {
|
|
261
|
-
activeTransition =
|
|
264
|
+
activeTransition = transition ?? {
|
|
262
265
|
time: clock,
|
|
263
266
|
pendingNodes: [],
|
|
264
267
|
asyncNodes: [],
|
|
@@ -267,6 +270,11 @@ class GlobalQueue extends Queue {
|
|
|
267
270
|
queueStash: { _queues: [[], []], _children: [] },
|
|
268
271
|
done: false
|
|
269
272
|
};
|
|
273
|
+
} else if (transition) {
|
|
274
|
+
activeTransition.done = transition;
|
|
275
|
+
transition.actions.push(...activeTransition.actions);
|
|
276
|
+
transitions.delete(activeTransition);
|
|
277
|
+
activeTransition = transition;
|
|
270
278
|
}
|
|
271
279
|
transitions.add(activeTransition);
|
|
272
280
|
activeTransition.time = clock;
|
|
@@ -333,7 +341,10 @@ function runTransitionPending(pendingNodes, value) {
|
|
|
333
341
|
for (let i = 0; i < p.length; i++) {
|
|
334
342
|
const n = p[i];
|
|
335
343
|
n._transition = activeTransition;
|
|
336
|
-
if (n._pendingCheck)
|
|
344
|
+
if (n._pendingCheck) {
|
|
345
|
+
n._pendingCheck._transition = activeTransition;
|
|
346
|
+
n._pendingCheck._set(value);
|
|
347
|
+
}
|
|
337
348
|
}
|
|
338
349
|
}
|
|
339
350
|
const globalQueue = new GlobalQueue();
|
|
@@ -360,10 +371,15 @@ function transitionComplete(transition) {
|
|
|
360
371
|
done && (transition.done = true);
|
|
361
372
|
return done;
|
|
362
373
|
}
|
|
374
|
+
function currentTransition(transition) {
|
|
375
|
+
while (transition.done && typeof transition.done === "object") transition = transition.done;
|
|
376
|
+
return transition;
|
|
377
|
+
}
|
|
363
378
|
function runInTransition(transition, fn) {
|
|
364
379
|
const prevTransition = activeTransition;
|
|
380
|
+
activeTransition = null;
|
|
365
381
|
try {
|
|
366
|
-
activeTransition = transition;
|
|
382
|
+
activeTransition = currentTransition(transition);
|
|
367
383
|
return fn();
|
|
368
384
|
} finally {
|
|
369
385
|
activeTransition = prevTransition;
|
|
@@ -382,6 +398,7 @@ function action(genFn) {
|
|
|
382
398
|
};
|
|
383
399
|
const process = result => {
|
|
384
400
|
if (result.done) {
|
|
401
|
+
ctx = currentTransition(ctx);
|
|
385
402
|
ctx.actions.splice(ctx.actions.indexOf(iterator), 1);
|
|
386
403
|
activeTransition = ctx;
|
|
387
404
|
schedule();
|
|
@@ -389,7 +406,7 @@ function action(genFn) {
|
|
|
389
406
|
return;
|
|
390
407
|
}
|
|
391
408
|
const yielded = result.value;
|
|
392
|
-
if (yielded instanceof Promise) return yielded.then(step);
|
|
409
|
+
if (yielded instanceof Promise) return yielded.then(v => runInTransition(ctx, () => step(v)));
|
|
393
410
|
runInTransition(ctx, () => step(yielded));
|
|
394
411
|
};
|
|
395
412
|
runInTransition(ctx, () => step());
|
|
@@ -407,7 +424,7 @@ function recompute(el, create = false) {
|
|
|
407
424
|
const honoraryOptimistic = el._type && el._transition != activeTransition;
|
|
408
425
|
if (!create) {
|
|
409
426
|
if (el._transition && activeTransition !== el._transition && !honoraryOptimistic)
|
|
410
|
-
globalQueue.initTransition(el);
|
|
427
|
+
globalQueue.initTransition(el._transition);
|
|
411
428
|
deleteFromHeap(el, el._flags & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue);
|
|
412
429
|
if (el._transition) disposeChildren(el);
|
|
413
430
|
else {
|
|
@@ -466,6 +483,8 @@ function recompute(el, create = false) {
|
|
|
466
483
|
value
|
|
467
484
|
);
|
|
468
485
|
const statusFlagsChanged = el._statusFlags !== prevStatusFlags || el._error !== prevError;
|
|
486
|
+
if (el._child && el._statusFlags & STATUS_PENDING && activeTransition)
|
|
487
|
+
activeTransition.asyncNodes.push(el);
|
|
469
488
|
el._notifyQueue?.(statusFlagsChanged, prevStatusFlags);
|
|
470
489
|
if (valueChanged || statusFlagsChanged) {
|
|
471
490
|
if (valueChanged) {
|
|
@@ -498,13 +517,13 @@ function handleAsync(el, result, setter) {
|
|
|
498
517
|
result
|
|
499
518
|
.then(value => {
|
|
500
519
|
if (el._inFlight !== result) return;
|
|
501
|
-
globalQueue.initTransition(el);
|
|
502
|
-
setter
|
|
520
|
+
globalQueue.initTransition(el._transition);
|
|
521
|
+
setter ? setter(value) : setSignal(el, () => value);
|
|
503
522
|
flush();
|
|
504
523
|
})
|
|
505
524
|
.catch(e => {
|
|
506
525
|
if (el._inFlight !== result) return;
|
|
507
|
-
globalQueue.initTransition(el);
|
|
526
|
+
globalQueue.initTransition(el._transition);
|
|
508
527
|
setStatusFlags(el, STATUS_ERROR, e);
|
|
509
528
|
el._time = clock;
|
|
510
529
|
notifySubs(el);
|
|
@@ -516,13 +535,13 @@ function handleAsync(el, result, setter) {
|
|
|
516
535
|
try {
|
|
517
536
|
for await (let value of result) {
|
|
518
537
|
if (el._inFlight !== result) return;
|
|
519
|
-
globalQueue.initTransition(el);
|
|
520
|
-
setter
|
|
538
|
+
globalQueue.initTransition(el._transition);
|
|
539
|
+
setter ? setter(value) : setSignal(el, () => value);
|
|
521
540
|
flush();
|
|
522
541
|
}
|
|
523
542
|
} catch (error) {
|
|
524
543
|
if (el._inFlight !== result) return;
|
|
525
|
-
globalQueue.initTransition(el);
|
|
544
|
+
globalQueue.initTransition(el._transition);
|
|
526
545
|
setStatusFlags(el, STATUS_ERROR, error);
|
|
527
546
|
el._time = clock;
|
|
528
547
|
notifySubs(el);
|
|
@@ -531,7 +550,7 @@ function handleAsync(el, result, setter) {
|
|
|
531
550
|
}
|
|
532
551
|
})();
|
|
533
552
|
}
|
|
534
|
-
globalQueue.initTransition(el);
|
|
553
|
+
globalQueue.initTransition(el._transition);
|
|
535
554
|
throw new NotReadyError(context);
|
|
536
555
|
}
|
|
537
556
|
function updateIfNecessary(el) {
|
|
@@ -840,6 +859,8 @@ function read(el) {
|
|
|
840
859
|
function setSignal(el, v) {
|
|
841
860
|
if (!el._pureWrite && context && el._firewall !== context)
|
|
842
861
|
console.warn("A Signal was written to in an owned scope.");
|
|
862
|
+
if (el._transition && activeTransition !== el._transition)
|
|
863
|
+
globalQueue.initTransition(el._transition);
|
|
843
864
|
if (typeof v === "function") {
|
|
844
865
|
v = v(
|
|
845
866
|
el._pendingValue === NOT_PENDING || (el._optimistic && el._transition)
|
|
@@ -924,11 +945,14 @@ function createRoot(init, options) {
|
|
|
924
945
|
}
|
|
925
946
|
function runWithOwner(owner, fn) {
|
|
926
947
|
const oldContext = context;
|
|
948
|
+
const prevTracking = tracking;
|
|
927
949
|
context = owner;
|
|
950
|
+
tracking = false;
|
|
928
951
|
try {
|
|
929
952
|
return fn();
|
|
930
953
|
} finally {
|
|
931
954
|
context = oldContext;
|
|
955
|
+
tracking = prevTracking;
|
|
932
956
|
}
|
|
933
957
|
}
|
|
934
958
|
function staleValues(fn, set = true) {
|
|
@@ -1082,9 +1106,7 @@ function createSignal(first, second, third) {
|
|
|
1082
1106
|
const node = computed(first, second, third);
|
|
1083
1107
|
return [read.bind(null, node), setSignal.bind(null, node)];
|
|
1084
1108
|
}
|
|
1085
|
-
const
|
|
1086
|
-
const needsId = o?.id != null;
|
|
1087
|
-
const node = signal(first, needsId ? { id: getNextChildId(o), ...second } : second);
|
|
1109
|
+
const node = signal(first, second);
|
|
1088
1110
|
return [read.bind(null, node), setSignal.bind(null, node)];
|
|
1089
1111
|
}
|
|
1090
1112
|
function createMemo(compute, value, options) {
|
|
@@ -1143,8 +1165,10 @@ function createOptimistic(first, second, third) {
|
|
|
1143
1165
|
if (typeof first === "function") {
|
|
1144
1166
|
const node = computed(
|
|
1145
1167
|
prev => {
|
|
1146
|
-
|
|
1147
|
-
|
|
1168
|
+
const n = getOwner();
|
|
1169
|
+
const value = first(prev);
|
|
1170
|
+
if (n._statusFlags & STATUS_UNINITIALIZED) return value;
|
|
1171
|
+
n._pendingValue = value;
|
|
1148
1172
|
return prev;
|
|
1149
1173
|
},
|
|
1150
1174
|
second,
|
|
@@ -1153,9 +1177,7 @@ function createOptimistic(first, second, third) {
|
|
|
1153
1177
|
node._optimistic = true;
|
|
1154
1178
|
return [read.bind(null, node), setSignal.bind(null, node)];
|
|
1155
1179
|
}
|
|
1156
|
-
const
|
|
1157
|
-
const needsId = o?.id != null;
|
|
1158
|
-
const node = signal(first, needsId ? { id: getNextChildId(o), ...second } : second);
|
|
1180
|
+
const node = signal(first, second);
|
|
1159
1181
|
node._optimistic = true;
|
|
1160
1182
|
return [
|
|
1161
1183
|
read.bind(null, node),
|
|
@@ -1338,13 +1360,13 @@ function createProjectionInternal(fn, initialValue = {}, options) {
|
|
|
1338
1360
|
};
|
|
1339
1361
|
const wrappedStore = wrapProjection(initialValue);
|
|
1340
1362
|
node = computed(() => {
|
|
1341
|
-
const owner =
|
|
1363
|
+
const owner = getOwner();
|
|
1342
1364
|
storeSetter(new Proxy(wrappedStore, writeTraps), s => {
|
|
1343
1365
|
const value = handleAsync(owner, fn(s), value => {
|
|
1344
1366
|
value !== wrappedStore &&
|
|
1345
1367
|
value !== undefined &&
|
|
1346
1368
|
storeSetter(wrappedStore, reconcile(value, options?.key || "id", options?.all));
|
|
1347
|
-
setSignal(
|
|
1369
|
+
setSignal(owner, undefined);
|
|
1348
1370
|
});
|
|
1349
1371
|
value !== wrappedStore &&
|
|
1350
1372
|
value !== undefined &&
|