@solidjs/signals 0.8.4 → 0.8.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 CHANGED
@@ -248,8 +248,10 @@ class GlobalQueue extends Queue {
248
248
  notify(node, mask, flags) {
249
249
  if (mask & STATUS_PENDING) {
250
250
  if (flags & STATUS_PENDING) {
251
- if (activeTransition && !activeTransition.asyncNodes.includes(node._error.cause))
251
+ if (activeTransition && !activeTransition.asyncNodes.includes(node._error.cause)) {
252
252
  activeTransition.asyncNodes.push(node._error.cause);
253
+ schedule();
254
+ }
253
255
  }
254
256
  return true;
255
257
  }
@@ -335,16 +337,19 @@ function notifySubs(node) {
335
337
  }
336
338
  }
337
339
  function recompute(el, create = false) {
338
- deleteFromHeap(el, el._flags & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue);
339
- if (el._pendingValue !== NOT_PENDING || el._pendingFirstChild || el._pendingDisposal)
340
- disposeChildren(el);
341
- else {
342
- markDisposal(el);
343
- globalQueue._pendingNodes.push(el);
344
- el._pendingDisposal = el._disposal;
345
- el._pendingFirstChild = el._firstChild;
346
- el._disposal = null;
347
- el._firstChild = null;
340
+ const honoraryOptimistic = el._type && el._transition != activeTransition;
341
+ if (!create) {
342
+ if (el._transition && activeTransition !== el._transition && !honoraryOptimistic)
343
+ globalQueue.initTransition(el);
344
+ deleteFromHeap(el, el._flags & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue);
345
+ if (el._transition) disposeChildren(el);
346
+ else {
347
+ markDisposal(el);
348
+ el._pendingDisposal = el._disposal;
349
+ el._pendingFirstChild = el._firstChild;
350
+ el._disposal = null;
351
+ el._firstChild = null;
352
+ }
348
353
  }
349
354
  const oldcontext = context;
350
355
  context = el;
@@ -371,32 +376,32 @@ function recompute(el, create = false) {
371
376
  }
372
377
  el._flags = REACTIVE_NONE;
373
378
  context = oldcontext;
374
- const depsTail = el._depsTail;
375
- let toRemove = depsTail !== null ? depsTail._nextDep : el._deps;
376
- if (toRemove !== null) {
377
- do {
378
- toRemove = unlinkSubs(toRemove);
379
- } while (toRemove !== null);
380
- if (depsTail !== null) depsTail._nextDep = null;
381
- else el._deps = null;
379
+ if (!(el._statusFlags & STATUS_PENDING)) {
380
+ const depsTail = el._depsTail;
381
+ let toRemove = depsTail !== null ? depsTail._nextDep : el._deps;
382
+ if (toRemove !== null) {
383
+ do {
384
+ toRemove = unlinkSubs(toRemove);
385
+ } while (toRemove !== null);
386
+ if (depsTail !== null) depsTail._nextDep = null;
387
+ else el._deps = null;
388
+ }
382
389
  }
383
390
  const valueChanged =
384
391
  !el._equals ||
385
392
  !el._equals(
386
- el._pendingValue === NOT_PENDING || el._optimistic ? el._value : el._pendingValue,
393
+ el._pendingValue === NOT_PENDING || el._optimistic || honoraryOptimistic
394
+ ? el._value
395
+ : el._pendingValue,
387
396
  value
388
397
  );
389
398
  const statusFlagsChanged = el._statusFlags !== prevStatusFlags || el._error !== prevError;
390
399
  el._notifyQueue?.(statusFlagsChanged, prevStatusFlags);
391
400
  if (valueChanged || statusFlagsChanged) {
392
401
  if (valueChanged) {
393
- if (create || el._optimistic || (el._type && el._transition != activeTransition))
394
- el._value = value;
395
- else {
396
- if (el._pendingValue === NOT_PENDING) globalQueue._pendingNodes.push(el);
397
- el._pendingValue = value;
398
- }
399
- if (el._pendingSignal) el._pendingSignal._set(value);
402
+ if (create || el._optimistic || honoraryOptimistic) el._value = value;
403
+ else el._pendingValue = value;
404
+ if (el._pendingSignal) el._pendingSignal._pendingValue = value;
400
405
  }
401
406
  for (let s = el._subs; s !== null; s = s._nextSub) {
402
407
  const queue = s._sub._flags & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue;
@@ -408,8 +413,14 @@ function recompute(el, create = false) {
408
413
  insertIntoHeapHeight(s._sub, s._sub._flags & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue);
409
414
  }
410
415
  }
411
- if (el._type && el._transition && activeTransition !== el._transition)
412
- runInTransition(el, recompute);
416
+ if (
417
+ (!create || el._statusFlags & STATUS_PENDING) &&
418
+ !el._optimistic &&
419
+ !honoraryOptimistic &&
420
+ !el._transition
421
+ )
422
+ globalQueue._pendingNodes.push(el);
423
+ if (el._transition && honoraryOptimistic) runInTransition(el, recompute);
413
424
  }
414
425
  function updateIfNecessary(el) {
415
426
  if (el._flags & REACTIVE_CHECK) {
@@ -441,7 +452,7 @@ function unlinkSubs(link) {
441
452
  dep._subs = nextSub;
442
453
  if (nextSub === null) {
443
454
  dep._unobserved?.();
444
- dep._fn && unobserved(dep);
455
+ dep._fn && !dep._preventAutoDisposal && unobserved(dep);
445
456
  }
446
457
  }
447
458
  return nextDep;
@@ -453,7 +464,7 @@ function unobserved(el) {
453
464
  dep = unlinkSubs(dep);
454
465
  }
455
466
  el._deps = null;
456
- runDisposal(el);
467
+ disposeChildren(el, true);
457
468
  }
458
469
  function link(dep, sub) {
459
470
  const prevDep = sub._depsTail;
@@ -593,7 +604,8 @@ function computed(fn, initialValue, options) {
593
604
  _time: clock,
594
605
  _pendingValue: NOT_PENDING,
595
606
  _pendingDisposal: null,
596
- _pendingFirstChild: null
607
+ _pendingFirstChild: null,
608
+ _transition: null
597
609
  };
598
610
  if (options?._internal) Object.assign(self, options._internal);
599
611
  self._name = options?.name ?? "computed";
@@ -708,6 +720,7 @@ function read(el) {
708
720
  let c = context;
709
721
  if (c?._root) c = c._parentComputed;
710
722
  if (c && tracking && !pendingCheck && !pendingValueCheck) {
723
+ if (el._fn && el._flags & REACTIVE_DISPOSED) recompute(el);
711
724
  link(el, c);
712
725
  const owner = el._firewall || el;
713
726
  if (owner._fn) {
@@ -747,9 +760,9 @@ function read(el) {
747
760
  pendingValueCheck = true;
748
761
  }
749
762
  }
750
- if (el._statusFlags & STATUS_PENDING) {
763
+ if (el._statusFlags & STATUS_PENDING && !pendingCheck) {
751
764
  if ((c && !stale) || el._statusFlags & STATUS_UNINITIALIZED) throw el._error;
752
- else if (c && stale && !pendingCheck) {
765
+ else if (c && stale) {
753
766
  setStatusFlags(c, c._statusFlags | 1, el._error);
754
767
  }
755
768
  }
@@ -874,7 +887,7 @@ function pending(fn) {
874
887
  pendingValueCheck = prevLatest;
875
888
  }
876
889
  }
877
- function isPending(fn, loadingValue) {
890
+ function isPending(fn) {
878
891
  const current = pendingCheck;
879
892
  pendingCheck = { _value: false };
880
893
  try {
@@ -882,7 +895,6 @@ function isPending(fn, loadingValue) {
882
895
  return pendingCheck._value;
883
896
  } catch (err) {
884
897
  if (!(err instanceof NotReadyError)) return false;
885
- if (loadingValue !== undefined) return loadingValue;
886
898
  throw err;
887
899
  } finally {
888
900
  pendingCheck = current;
@@ -1944,6 +1956,7 @@ function boundaryComputed(fn, propagationMask) {
1944
1956
  }
1945
1957
  });
1946
1958
  node._propagationMask = propagationMask;
1959
+ node._preventAutoDisposal = true;
1947
1960
  return node;
1948
1961
  }
1949
1962
  function createBoundChildren(owner, fn, queue, mask) {