@solidjs/signals 0.7.1 → 0.7.3
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 +40 -24
- package/dist/node.cjs +337 -321
- package/dist/prod.js +337 -321
- package/dist/types/core/core.d.ts +3 -1
- package/dist/types/core/scheduler.d.ts +1 -1
- package/package.json +1 -1
package/dist/dev.js
CHANGED
|
@@ -200,7 +200,7 @@ var Transition = class _Transition {
|
|
|
200
200
|
}
|
|
201
201
|
}
|
|
202
202
|
flush() {
|
|
203
|
-
if (this._running)
|
|
203
|
+
if (this._running || this._done)
|
|
204
204
|
return;
|
|
205
205
|
this._running = true;
|
|
206
206
|
let currentTransition = ActiveTransition;
|
|
@@ -239,6 +239,9 @@ var Transition = class _Transition {
|
|
|
239
239
|
this._queues[0].push.apply(this._queues[0], queue._queues[0]);
|
|
240
240
|
this._queues[1].push.apply(this._queues[1], queue._queues[1]);
|
|
241
241
|
this._pureQueue.push.apply(this._pureQueue, queue._pureQueue);
|
|
242
|
+
queue._queues[0].length = 0;
|
|
243
|
+
queue._queues[1].length = 0;
|
|
244
|
+
queue._pureQueue.length = 0;
|
|
242
245
|
for (let i = 0; i < queue._children.length; i++) {
|
|
243
246
|
const og = this._children.find((c) => c._cloned === queue._children[i]._cloned);
|
|
244
247
|
if (og)
|
|
@@ -271,6 +274,7 @@ var Transition = class _Transition {
|
|
|
271
274
|
(async function() {
|
|
272
275
|
let temp, value;
|
|
273
276
|
while (!(temp = result.next(value)).done) {
|
|
277
|
+
transition2 = ActiveTransition;
|
|
274
278
|
if (temp.value instanceof Promise) {
|
|
275
279
|
transition2._promises.add(temp.value);
|
|
276
280
|
try {
|
|
@@ -316,7 +320,11 @@ function transition(fn) {
|
|
|
316
320
|
let t = new Transition();
|
|
317
321
|
queueMicrotask(() => t.runTransition(() => fn((fn2) => t.runTransition(fn2))));
|
|
318
322
|
}
|
|
319
|
-
function cloneGraph(node
|
|
323
|
+
function cloneGraph(node) {
|
|
324
|
+
if (node._optimistic) {
|
|
325
|
+
ActiveTransition.addOptimistic(node._optimistic);
|
|
326
|
+
return node;
|
|
327
|
+
}
|
|
320
328
|
if (node._transition) {
|
|
321
329
|
if (node._transition !== ActiveTransition) {
|
|
322
330
|
mergeTransitions(node._transition, ActiveTransition);
|
|
@@ -330,20 +338,19 @@ function cloneGraph(node, optimistic) {
|
|
|
330
338
|
_nextSibling: null,
|
|
331
339
|
_observers: null,
|
|
332
340
|
_sources: node._sources ? [...node._sources] : null,
|
|
333
|
-
_cloned: node
|
|
334
|
-
_optimistic: !!optimistic
|
|
341
|
+
_cloned: node
|
|
335
342
|
});
|
|
336
343
|
delete clone._prevValue;
|
|
337
344
|
ActiveTransition._sources.set(node, clone);
|
|
338
345
|
node._transition = ActiveTransition;
|
|
339
|
-
if (
|
|
346
|
+
if (node._sources) {
|
|
340
347
|
for (let i = 0; i < node._sources.length; i++)
|
|
341
348
|
node._sources[i]._observers.push(clone);
|
|
342
349
|
}
|
|
343
350
|
if (node._observers) {
|
|
344
351
|
clone._observers = [];
|
|
345
352
|
for (let i = 0, length = node._observers.length; i < length; i++) {
|
|
346
|
-
!node._observers[i]._cloned && clone._observers.push(cloneGraph(node._observers[i]
|
|
353
|
+
!node._observers[i]._cloned && clone._observers.push(cloneGraph(node._observers[i]));
|
|
347
354
|
}
|
|
348
355
|
}
|
|
349
356
|
return clone;
|
|
@@ -455,12 +462,6 @@ function finishTransition(transition2) {
|
|
|
455
462
|
}
|
|
456
463
|
if (clone._sources)
|
|
457
464
|
replaceSourceObservers(clone, transition2);
|
|
458
|
-
if (clone._optimistic) {
|
|
459
|
-
clone.dispose();
|
|
460
|
-
clone.emptyDisposal();
|
|
461
|
-
delete source._transition;
|
|
462
|
-
continue;
|
|
463
|
-
}
|
|
464
465
|
if (clone._updated || clone._state === STATE_DISPOSED) {
|
|
465
466
|
source.dispose(clone._state === STATE_DISPOSED);
|
|
466
467
|
source.emptyDisposal();
|
|
@@ -659,7 +660,7 @@ var Computation = class extends Owner {
|
|
|
659
660
|
_forceNotify = false;
|
|
660
661
|
_transition;
|
|
661
662
|
_cloned;
|
|
662
|
-
_optimistic
|
|
663
|
+
_optimistic;
|
|
663
664
|
constructor(initialValue, compute2, options) {
|
|
664
665
|
super(options?.id, compute2 === null);
|
|
665
666
|
this._compute = compute2;
|
|
@@ -750,7 +751,7 @@ var Computation = class extends Owner {
|
|
|
750
751
|
const changedFlagsMask = this._stateFlags ^ flags, changedFlags = changedFlagsMask & flags;
|
|
751
752
|
this._stateFlags = flags;
|
|
752
753
|
this._time = clock + 1;
|
|
753
|
-
if (this._observers) {
|
|
754
|
+
if (this._observers && !(this._optimistic && ActiveTransition)) {
|
|
754
755
|
for (let i = 0; i < this._observers.length; i++) {
|
|
755
756
|
if (valueChanged) {
|
|
756
757
|
this._observers[i]._notify(STATE_DIRTY);
|
|
@@ -769,7 +770,7 @@ var Computation = class extends Owner {
|
|
|
769
770
|
return;
|
|
770
771
|
this._forceNotify = !!skipQueue;
|
|
771
772
|
this._state = state;
|
|
772
|
-
if (this._observers) {
|
|
773
|
+
if (this._observers && !(this._optimistic && ActiveTransition)) {
|
|
773
774
|
for (let i = 0; i < this._observers.length; i++) {
|
|
774
775
|
this._observers[i]._notify(STATE_CHECK, skipQueue);
|
|
775
776
|
}
|
|
@@ -784,7 +785,7 @@ var Computation = class extends Owner {
|
|
|
784
785
|
_notifyFlags(mask, newFlags2) {
|
|
785
786
|
if (this._state >= STATE_DIRTY)
|
|
786
787
|
return;
|
|
787
|
-
if (mask & this._handlerMask) {
|
|
788
|
+
if (mask & this._handlerMask || this._optimistic && ActiveTransition) {
|
|
788
789
|
this._notify(STATE_DIRTY);
|
|
789
790
|
return;
|
|
790
791
|
}
|
|
@@ -964,7 +965,7 @@ function isPending(fn, loadingValue) {
|
|
|
964
965
|
return pendingCheck(fn, loadingValue);
|
|
965
966
|
const c = new Computation(void 0, () => pendingCheck(fn, loadingValue));
|
|
966
967
|
c._handlerMask |= LOADING_BIT;
|
|
967
|
-
return c.
|
|
968
|
+
return c.wait();
|
|
968
969
|
}
|
|
969
970
|
function latest(fn, fallback) {
|
|
970
971
|
const argLength = arguments.length;
|
|
@@ -1167,7 +1168,13 @@ var FirewallComputation = class extends Computation {
|
|
|
1167
1168
|
this._forceNotify = !!skipQueue;
|
|
1168
1169
|
}
|
|
1169
1170
|
_run() {
|
|
1171
|
+
const prevFlags = this._stateFlags;
|
|
1170
1172
|
this._state !== STATE_CLEAN && runTop(this);
|
|
1173
|
+
if (ActiveTransition && this._optimistic && (this._stateFlags !== prevFlags || this._stateFlags !== this._optimistic.flags)) {
|
|
1174
|
+
getQueue(this).notify(this, LOADING_BIT | ERROR_BIT, this._stateFlags);
|
|
1175
|
+
this._optimistic.flags = this._stateFlags;
|
|
1176
|
+
this._stateFlags = prevFlags;
|
|
1177
|
+
}
|
|
1171
1178
|
}
|
|
1172
1179
|
};
|
|
1173
1180
|
function runTop(node) {
|
|
@@ -1362,15 +1369,19 @@ function resolve(fn) {
|
|
|
1362
1369
|
});
|
|
1363
1370
|
}
|
|
1364
1371
|
function createOptimistic(first, second, third) {
|
|
1365
|
-
const node = typeof first === "function" ? new Computation(second,
|
|
1366
|
-
|
|
1372
|
+
const node = typeof first === "function" ? new Computation(second, (prev) => {
|
|
1373
|
+
const res = first(prev);
|
|
1374
|
+
if (node._optimistic._transition)
|
|
1375
|
+
return prev;
|
|
1376
|
+
return res;
|
|
1377
|
+
}, third) : new Computation(first, null, second);
|
|
1378
|
+
node._optimistic = () => node.write(first);
|
|
1367
1379
|
function write(v) {
|
|
1368
1380
|
if (!ActiveTransition)
|
|
1369
1381
|
throw new Error("createOptimistic can only be updated inside a transition");
|
|
1370
|
-
ActiveTransition.addOptimistic(
|
|
1371
|
-
cloneGraph(node, true);
|
|
1382
|
+
ActiveTransition.addOptimistic(node._optimistic);
|
|
1372
1383
|
queueMicrotask(() => {
|
|
1373
|
-
if (
|
|
1384
|
+
if (node._optimistic._transition) {
|
|
1374
1385
|
node._updateIfNecessary();
|
|
1375
1386
|
node.write(v);
|
|
1376
1387
|
}
|
|
@@ -1847,7 +1858,12 @@ function deep(store) {
|
|
|
1847
1858
|
// src/store/optimistic.ts
|
|
1848
1859
|
function createOptimisticStore(first, second, options) {
|
|
1849
1860
|
const derived = typeof first === "function";
|
|
1850
|
-
const { store, node } = derived ? createProjectionInternal(
|
|
1861
|
+
const { store, node } = derived ? createProjectionInternal((draft) => {
|
|
1862
|
+
const res = first(draft);
|
|
1863
|
+
if (reset._transition)
|
|
1864
|
+
return draft;
|
|
1865
|
+
return res;
|
|
1866
|
+
}, second, options) : createProjectionInternal(() => {
|
|
1851
1867
|
}, first);
|
|
1852
1868
|
const reset = () => storeSetter(
|
|
1853
1869
|
store,
|
|
@@ -1861,9 +1877,9 @@ function createOptimisticStore(first, second, options) {
|
|
|
1861
1877
|
if (!ActiveTransition)
|
|
1862
1878
|
throw new Error("createOptimisticStore can only be updated inside a transition");
|
|
1863
1879
|
ActiveTransition.addOptimistic(reset);
|
|
1864
|
-
cloneGraph(node, true);
|
|
1865
1880
|
queueMicrotask(() => reset._transition && storeSetter(store, v));
|
|
1866
1881
|
};
|
|
1882
|
+
node._optimistic = reset;
|
|
1867
1883
|
return [store, write];
|
|
1868
1884
|
}
|
|
1869
1885
|
|