@solidjs/signals 0.7.2 → 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 CHANGED
@@ -321,8 +321,10 @@ function transition(fn) {
321
321
  queueMicrotask(() => t.runTransition(() => fn((fn2) => t.runTransition(fn2))));
322
322
  }
323
323
  function cloneGraph(node) {
324
- if (node._optimistic)
324
+ if (node._optimistic) {
325
+ ActiveTransition.addOptimistic(node._optimistic);
325
326
  return node;
327
+ }
326
328
  if (node._transition) {
327
329
  if (node._transition !== ActiveTransition) {
328
330
  mergeTransitions(node._transition, ActiveTransition);
@@ -658,7 +660,7 @@ var Computation = class extends Owner {
658
660
  _forceNotify = false;
659
661
  _transition;
660
662
  _cloned;
661
- _optimistic = false;
663
+ _optimistic;
662
664
  constructor(initialValue, compute2, options) {
663
665
  super(options?.id, compute2 === null);
664
666
  this._compute = compute2;
@@ -963,7 +965,7 @@ function isPending(fn, loadingValue) {
963
965
  return pendingCheck(fn, loadingValue);
964
966
  const c = new Computation(void 0, () => pendingCheck(fn, loadingValue));
965
967
  c._handlerMask |= LOADING_BIT;
966
- return c.read();
968
+ return c.wait();
967
969
  }
968
970
  function latest(fn, fallback) {
969
971
  const argLength = arguments.length;
@@ -1168,8 +1170,11 @@ var FirewallComputation = class extends Computation {
1168
1170
  _run() {
1169
1171
  const prevFlags = this._stateFlags;
1170
1172
  this._state !== STATE_CLEAN && runTop(this);
1171
- if (ActiveTransition && this._optimistic && this._stateFlags !== prevFlags)
1173
+ if (ActiveTransition && this._optimistic && (this._stateFlags !== prevFlags || this._stateFlags !== this._optimistic.flags)) {
1172
1174
  getQueue(this).notify(this, LOADING_BIT | ERROR_BIT, this._stateFlags);
1175
+ this._optimistic.flags = this._stateFlags;
1176
+ this._stateFlags = prevFlags;
1177
+ }
1173
1178
  }
1174
1179
  };
1175
1180
  function runTop(node) {
@@ -1366,18 +1371,17 @@ function resolve(fn) {
1366
1371
  function createOptimistic(first, second, third) {
1367
1372
  const node = typeof first === "function" ? new Computation(second, (prev) => {
1368
1373
  const res = first(prev);
1369
- if (reset._transition)
1374
+ if (node._optimistic._transition)
1370
1375
  return prev;
1371
1376
  return res;
1372
1377
  }, third) : new Computation(first, null, second);
1373
- node._optimistic = true;
1374
- const reset = () => node.write(first);
1378
+ node._optimistic = () => node.write(first);
1375
1379
  function write(v) {
1376
1380
  if (!ActiveTransition)
1377
1381
  throw new Error("createOptimistic can only be updated inside a transition");
1378
- ActiveTransition.addOptimistic(reset);
1382
+ ActiveTransition.addOptimistic(node._optimistic);
1379
1383
  queueMicrotask(() => {
1380
- if (reset._transition) {
1384
+ if (node._optimistic._transition) {
1381
1385
  node._updateIfNecessary();
1382
1386
  node.write(v);
1383
1387
  }
@@ -1861,7 +1865,6 @@ function createOptimisticStore(first, second, options) {
1861
1865
  return res;
1862
1866
  }, second, options) : createProjectionInternal(() => {
1863
1867
  }, first);
1864
- node._optimistic = true;
1865
1868
  const reset = () => storeSetter(
1866
1869
  store,
1867
1870
  reconcile(
@@ -1876,6 +1879,7 @@ function createOptimisticStore(first, second, options) {
1876
1879
  ActiveTransition.addOptimistic(reset);
1877
1880
  queueMicrotask(() => reset._transition && storeSetter(store, v));
1878
1881
  };
1882
+ node._optimistic = reset;
1879
1883
  return [store, write];
1880
1884
  }
1881
1885