@solidjs/signals 0.7.1 → 0.7.2
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 +31 -19
- package/dist/node.cjs +287 -275
- package/dist/prod.js +287 -275
- 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,9 @@ 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
|
+
return node;
|
|
320
326
|
if (node._transition) {
|
|
321
327
|
if (node._transition !== ActiveTransition) {
|
|
322
328
|
mergeTransitions(node._transition, ActiveTransition);
|
|
@@ -330,20 +336,19 @@ function cloneGraph(node, optimistic) {
|
|
|
330
336
|
_nextSibling: null,
|
|
331
337
|
_observers: null,
|
|
332
338
|
_sources: node._sources ? [...node._sources] : null,
|
|
333
|
-
_cloned: node
|
|
334
|
-
_optimistic: !!optimistic
|
|
339
|
+
_cloned: node
|
|
335
340
|
});
|
|
336
341
|
delete clone._prevValue;
|
|
337
342
|
ActiveTransition._sources.set(node, clone);
|
|
338
343
|
node._transition = ActiveTransition;
|
|
339
|
-
if (
|
|
344
|
+
if (node._sources) {
|
|
340
345
|
for (let i = 0; i < node._sources.length; i++)
|
|
341
346
|
node._sources[i]._observers.push(clone);
|
|
342
347
|
}
|
|
343
348
|
if (node._observers) {
|
|
344
349
|
clone._observers = [];
|
|
345
350
|
for (let i = 0, length = node._observers.length; i < length; i++) {
|
|
346
|
-
!node._observers[i]._cloned && clone._observers.push(cloneGraph(node._observers[i]
|
|
351
|
+
!node._observers[i]._cloned && clone._observers.push(cloneGraph(node._observers[i]));
|
|
347
352
|
}
|
|
348
353
|
}
|
|
349
354
|
return clone;
|
|
@@ -455,12 +460,6 @@ function finishTransition(transition2) {
|
|
|
455
460
|
}
|
|
456
461
|
if (clone._sources)
|
|
457
462
|
replaceSourceObservers(clone, transition2);
|
|
458
|
-
if (clone._optimistic) {
|
|
459
|
-
clone.dispose();
|
|
460
|
-
clone.emptyDisposal();
|
|
461
|
-
delete source._transition;
|
|
462
|
-
continue;
|
|
463
|
-
}
|
|
464
463
|
if (clone._updated || clone._state === STATE_DISPOSED) {
|
|
465
464
|
source.dispose(clone._state === STATE_DISPOSED);
|
|
466
465
|
source.emptyDisposal();
|
|
@@ -750,7 +749,7 @@ var Computation = class extends Owner {
|
|
|
750
749
|
const changedFlagsMask = this._stateFlags ^ flags, changedFlags = changedFlagsMask & flags;
|
|
751
750
|
this._stateFlags = flags;
|
|
752
751
|
this._time = clock + 1;
|
|
753
|
-
if (this._observers) {
|
|
752
|
+
if (this._observers && !(this._optimistic && ActiveTransition)) {
|
|
754
753
|
for (let i = 0; i < this._observers.length; i++) {
|
|
755
754
|
if (valueChanged) {
|
|
756
755
|
this._observers[i]._notify(STATE_DIRTY);
|
|
@@ -769,7 +768,7 @@ var Computation = class extends Owner {
|
|
|
769
768
|
return;
|
|
770
769
|
this._forceNotify = !!skipQueue;
|
|
771
770
|
this._state = state;
|
|
772
|
-
if (this._observers) {
|
|
771
|
+
if (this._observers && !(this._optimistic && ActiveTransition)) {
|
|
773
772
|
for (let i = 0; i < this._observers.length; i++) {
|
|
774
773
|
this._observers[i]._notify(STATE_CHECK, skipQueue);
|
|
775
774
|
}
|
|
@@ -784,7 +783,7 @@ var Computation = class extends Owner {
|
|
|
784
783
|
_notifyFlags(mask, newFlags2) {
|
|
785
784
|
if (this._state >= STATE_DIRTY)
|
|
786
785
|
return;
|
|
787
|
-
if (mask & this._handlerMask) {
|
|
786
|
+
if (mask & this._handlerMask || this._optimistic && ActiveTransition) {
|
|
788
787
|
this._notify(STATE_DIRTY);
|
|
789
788
|
return;
|
|
790
789
|
}
|
|
@@ -1167,7 +1166,10 @@ var FirewallComputation = class extends Computation {
|
|
|
1167
1166
|
this._forceNotify = !!skipQueue;
|
|
1168
1167
|
}
|
|
1169
1168
|
_run() {
|
|
1169
|
+
const prevFlags = this._stateFlags;
|
|
1170
1170
|
this._state !== STATE_CLEAN && runTop(this);
|
|
1171
|
+
if (ActiveTransition && this._optimistic && this._stateFlags !== prevFlags)
|
|
1172
|
+
getQueue(this).notify(this, LOADING_BIT | ERROR_BIT, this._stateFlags);
|
|
1171
1173
|
}
|
|
1172
1174
|
};
|
|
1173
1175
|
function runTop(node) {
|
|
@@ -1362,13 +1364,18 @@ function resolve(fn) {
|
|
|
1362
1364
|
});
|
|
1363
1365
|
}
|
|
1364
1366
|
function createOptimistic(first, second, third) {
|
|
1365
|
-
const node = typeof first === "function" ? new Computation(second,
|
|
1367
|
+
const node = typeof first === "function" ? new Computation(second, (prev) => {
|
|
1368
|
+
const res = first(prev);
|
|
1369
|
+
if (reset._transition)
|
|
1370
|
+
return prev;
|
|
1371
|
+
return res;
|
|
1372
|
+
}, third) : new Computation(first, null, second);
|
|
1373
|
+
node._optimistic = true;
|
|
1366
1374
|
const reset = () => node.write(first);
|
|
1367
1375
|
function write(v) {
|
|
1368
1376
|
if (!ActiveTransition)
|
|
1369
1377
|
throw new Error("createOptimistic can only be updated inside a transition");
|
|
1370
1378
|
ActiveTransition.addOptimistic(reset);
|
|
1371
|
-
cloneGraph(node, true);
|
|
1372
1379
|
queueMicrotask(() => {
|
|
1373
1380
|
if (reset._transition) {
|
|
1374
1381
|
node._updateIfNecessary();
|
|
@@ -1847,8 +1854,14 @@ function deep(store) {
|
|
|
1847
1854
|
// src/store/optimistic.ts
|
|
1848
1855
|
function createOptimisticStore(first, second, options) {
|
|
1849
1856
|
const derived = typeof first === "function";
|
|
1850
|
-
const { store, node } = derived ? createProjectionInternal(
|
|
1857
|
+
const { store, node } = derived ? createProjectionInternal((draft) => {
|
|
1858
|
+
const res = first(draft);
|
|
1859
|
+
if (reset._transition)
|
|
1860
|
+
return draft;
|
|
1861
|
+
return res;
|
|
1862
|
+
}, second, options) : createProjectionInternal(() => {
|
|
1851
1863
|
}, first);
|
|
1864
|
+
node._optimistic = true;
|
|
1852
1865
|
const reset = () => storeSetter(
|
|
1853
1866
|
store,
|
|
1854
1867
|
reconcile(
|
|
@@ -1861,7 +1874,6 @@ function createOptimisticStore(first, second, options) {
|
|
|
1861
1874
|
if (!ActiveTransition)
|
|
1862
1875
|
throw new Error("createOptimisticStore can only be updated inside a transition");
|
|
1863
1876
|
ActiveTransition.addOptimistic(reset);
|
|
1864
|
-
cloneGraph(node, true);
|
|
1865
1877
|
queueMicrotask(() => reset._transition && storeSetter(store, v));
|
|
1866
1878
|
};
|
|
1867
1879
|
return [store, write];
|