@solidjs/signals 0.2.0 → 0.2.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 CHANGED
@@ -658,22 +658,34 @@ function hasUpdated(fn) {
658
658
  updateCheck = current;
659
659
  }
660
660
  }
661
- function isStale(fn) {
661
+ function isPending(fn, loadingValue) {
662
+ const argLength = arguments.length;
662
663
  const current = staleCheck;
663
664
  staleCheck = { _value: false };
664
665
  try {
665
666
  latest(fn);
666
667
  return staleCheck._value;
668
+ } catch (err) {
669
+ if (!(err instanceof NotReadyError))
670
+ return false;
671
+ if (argLength > 1)
672
+ return loadingValue;
673
+ throw err;
667
674
  } finally {
668
675
  staleCheck = current;
669
676
  }
670
677
  }
671
- function latest(fn) {
678
+ function latest(fn, fallback) {
679
+ const argLength = arguments.length;
672
680
  const prevFlags = newFlags;
673
681
  const prevNotStale = notStale;
674
682
  notStale = false;
675
683
  try {
676
684
  return fn();
685
+ } catch (err) {
686
+ if (argLength > 1 && err instanceof NotReadyError)
687
+ return fallback;
688
+ throw err;
677
689
  } finally {
678
690
  newFlags = prevFlags;
679
691
  notStale = prevNotStale;
@@ -697,7 +709,10 @@ function runWithObserver(observer, run) {
697
709
  return compute(observer, run, observer);
698
710
  } catch (error) {
699
711
  if (error instanceof NotReadyError) {
700
- observer.write(UNCHANGED, newFlags | LOADING_BIT | observer._stateFlags & UNINITIALIZED_BIT);
712
+ observer.write(
713
+ UNCHANGED,
714
+ newFlags | LOADING_BIT | observer._stateFlags & UNINITIALIZED_BIT
715
+ );
701
716
  } else {
702
717
  observer._setError(error);
703
718
  }
@@ -1741,4 +1756,4 @@ function compare(key, a, b) {
1741
1756
  return key ? key(a) === key(b) : true;
1742
1757
  }
1743
1758
 
1744
- export { $PROXY, $RAW, $TARGET, $TRACK, Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, SUPPORTS_PROXY, catchError, createAsync, createBoundary, createContext, createEffect, createErrorBoundary, createMemo, createProjection, createRenderEffect, createRoot, createSignal, createStore, createSuspense, flatten, flushSync, getContext, getObserver, getOwner, hasContext, hasUpdated, isEqual, isStale, isWrappable, latest, mapArray, merge, omit, onCleanup, reconcile, repeat, resolve, runWithObserver, runWithOwner, setContext, untrack, unwrap };
1759
+ export { $PROXY, $RAW, $TARGET, $TRACK, Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, SUPPORTS_PROXY, catchError, createAsync, createBoundary, createContext, createEffect, createErrorBoundary, createMemo, createProjection, createRenderEffect, createRoot, createSignal, createStore, createSuspense, flatten, flushSync, getContext, getObserver, getOwner, hasContext, hasUpdated, isEqual, isPending, isWrappable, latest, mapArray, merge, omit, onCleanup, reconcile, repeat, resolve, runWithObserver, runWithOwner, setContext, untrack, unwrap };
package/dist/node.cjs CHANGED
@@ -655,22 +655,34 @@ function hasUpdated(fn) {
655
655
  updateCheck = current;
656
656
  }
657
657
  }
658
- function isStale(fn) {
658
+ function isPending(fn, loadingValue) {
659
+ const argLength = arguments.length;
659
660
  const current = staleCheck;
660
661
  staleCheck = { e: false };
661
662
  try {
662
663
  latest(fn);
663
664
  return staleCheck.e;
665
+ } catch (err) {
666
+ if (!(err instanceof NotReadyError))
667
+ return false;
668
+ if (argLength > 1)
669
+ return loadingValue;
670
+ throw err;
664
671
  } finally {
665
672
  staleCheck = current;
666
673
  }
667
674
  }
668
- function latest(fn) {
675
+ function latest(fn, fallback) {
676
+ const argLength = arguments.length;
669
677
  const prevFlags = newFlags;
670
678
  const prevNotStale = notStale;
671
679
  notStale = false;
672
680
  try {
673
681
  return fn();
682
+ } catch (err) {
683
+ if (argLength > 1 && err instanceof NotReadyError)
684
+ return fallback;
685
+ throw err;
674
686
  } finally {
675
687
  newFlags = prevFlags;
676
688
  notStale = prevNotStale;
@@ -694,7 +706,10 @@ function runWithObserver(observer, run) {
694
706
  return compute(observer, run, observer);
695
707
  } catch (error) {
696
708
  if (error instanceof NotReadyError) {
697
- observer.write(UNCHANGED, newFlags | LOADING_BIT | observer.d & UNINITIALIZED_BIT);
709
+ observer.write(
710
+ UNCHANGED,
711
+ newFlags | LOADING_BIT | observer.d & UNINITIALIZED_BIT
712
+ );
698
713
  } else {
699
714
  observer.F(error);
700
715
  }
@@ -1773,7 +1788,7 @@ exports.getOwner = getOwner;
1773
1788
  exports.hasContext = hasContext;
1774
1789
  exports.hasUpdated = hasUpdated;
1775
1790
  exports.isEqual = isEqual;
1776
- exports.isStale = isStale;
1791
+ exports.isPending = isPending;
1777
1792
  exports.isWrappable = isWrappable;
1778
1793
  exports.latest = latest;
1779
1794
  exports.mapArray = mapArray;
package/dist/prod.js CHANGED
@@ -651,22 +651,34 @@ function hasUpdated(fn) {
651
651
  updateCheck = current;
652
652
  }
653
653
  }
654
- function isStale(fn) {
654
+ function isPending(fn, loadingValue) {
655
+ const argLength = arguments.length;
655
656
  const current = staleCheck;
656
657
  staleCheck = { e: false };
657
658
  try {
658
659
  latest(fn);
659
660
  return staleCheck.e;
661
+ } catch (err) {
662
+ if (!(err instanceof NotReadyError))
663
+ return false;
664
+ if (argLength > 1)
665
+ return loadingValue;
666
+ throw err;
660
667
  } finally {
661
668
  staleCheck = current;
662
669
  }
663
670
  }
664
- function latest(fn) {
671
+ function latest(fn, fallback) {
672
+ const argLength = arguments.length;
665
673
  const prevFlags = newFlags;
666
674
  const prevNotStale = notStale;
667
675
  notStale = false;
668
676
  try {
669
677
  return fn();
678
+ } catch (err) {
679
+ if (argLength > 1 && err instanceof NotReadyError)
680
+ return fallback;
681
+ throw err;
670
682
  } finally {
671
683
  newFlags = prevFlags;
672
684
  notStale = prevNotStale;
@@ -690,7 +702,10 @@ function runWithObserver(observer, run) {
690
702
  return compute(observer, run, observer);
691
703
  } catch (error) {
692
704
  if (error instanceof NotReadyError) {
693
- observer.write(UNCHANGED, newFlags | LOADING_BIT | observer.d & UNINITIALIZED_BIT);
705
+ observer.write(
706
+ UNCHANGED,
707
+ newFlags | LOADING_BIT | observer.d & UNINITIALIZED_BIT
708
+ );
694
709
  } else {
695
710
  observer.F(error);
696
711
  }
@@ -1728,4 +1743,4 @@ function compare(key, a, b) {
1728
1743
  return key ? key(a) === key(b) : true;
1729
1744
  }
1730
1745
 
1731
- export { $PROXY, $RAW, $TARGET, $TRACK, Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, SUPPORTS_PROXY, catchError, createAsync, createBoundary, createContext, createEffect, createErrorBoundary, createMemo, createProjection, createRenderEffect, createRoot, createSignal, createStore, createSuspense, flatten, flushSync, getContext, getObserver, getOwner, hasContext, hasUpdated, isEqual, isStale, isWrappable, latest, mapArray, merge, omit, onCleanup, reconcile, repeat, resolve, runWithObserver, runWithOwner, setContext, untrack, unwrap };
1746
+ export { $PROXY, $RAW, $TARGET, $TRACK, Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, SUPPORTS_PROXY, catchError, createAsync, createBoundary, createContext, createEffect, createErrorBoundary, createMemo, createProjection, createRenderEffect, createRoot, createSignal, createStore, createSuspense, flatten, flushSync, getContext, getObserver, getOwner, hasContext, hasUpdated, isEqual, isPending, isWrappable, latest, mapArray, merge, omit, onCleanup, reconcile, repeat, resolve, runWithObserver, runWithOwner, setContext, untrack, unwrap };
@@ -142,14 +142,16 @@ export declare function hasUpdated(fn: () => any): boolean;
142
142
  /**
143
143
  * Returns true if the given function contains async signals are out of date.
144
144
  */
145
- export declare function isStale(fn: () => any): boolean;
145
+ export declare function isPending(fn: () => any): boolean;
146
+ export declare function isPending(fn: () => any, loadingValue: boolean): boolean;
146
147
  /**
147
148
  * Attempts to resolve value of expression synchronously returning the last resolved value for any async computation.
148
149
  */
149
150
  export declare function latest<T>(fn: () => T): T;
151
+ export declare function latest<T, U>(fn: () => T, fallback: U): T | U;
150
152
  export declare function catchError(fn: () => void): unknown | undefined;
151
153
  /**
152
- * Runs the given function in the given observer so that tracking, error handling and cleanups continue to work.
154
+ * Runs the given function in the given observer.
153
155
  *
154
156
  * Warning: Usually there are simpler ways of modeling a problem that avoid using this function
155
157
  */
@@ -1,6 +1,6 @@
1
1
  export { ContextNotFoundError, NoOwnerError, NotReadyError, type ErrorHandler } from "./error.js";
2
2
  export { Owner, createContext, getContext, setContext, hasContext, getOwner, onCleanup, type Context, type ContextRecord, type Disposable } from "./owner.js";
3
- export { Computation, createBoundary, getObserver, isEqual, untrack, hasUpdated, isStale, latest, catchError, UNCHANGED, compute, runWithObserver, type SignalOptions } from "./core.js";
3
+ export { Computation, createBoundary, getObserver, isEqual, untrack, hasUpdated, isPending, latest, catchError, UNCHANGED, compute, runWithObserver, type SignalOptions } from "./core.js";
4
4
  export { Effect, EagerComputation } from "./effect.js";
5
5
  export { flushSync, getClock, incrementClock, type IQueue, Queue } from "./scheduler.js";
6
6
  export { createSuspense } from "./suspense.js";
@@ -1,4 +1,4 @@
1
- export { Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, createContext, flatten, flushSync, createBoundary, getContext, setContext, hasContext, getOwner, onCleanup, getObserver, isEqual, untrack, hasUpdated, isStale, latest, catchError, runWithObserver, createSuspense, SUPPORTS_PROXY } from "./core/index.js";
1
+ export { Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, createContext, flatten, flushSync, createBoundary, getContext, setContext, hasContext, getOwner, onCleanup, getObserver, isEqual, untrack, hasUpdated, isPending, latest, catchError, runWithObserver, createSuspense, SUPPORTS_PROXY } from "./core/index.js";
2
2
  export type { ErrorHandler, SignalOptions, Context, ContextRecord, Disposable, IQueue } from "./core/index.js";
3
3
  export { mapArray, repeat, type Maybe } from "./map.js";
4
4
  export * from "./signals.js";
@@ -127,7 +127,8 @@ export declare function createRenderEffect<Next, Init = Next>(compute: ComputeFu
127
127
  */
128
128
  export declare function createRoot<T>(init: ((dispose: () => void) => T) | (() => T)): T;
129
129
  /**
130
- * Runs the given function in the given owner so that error handling and cleanups continue to work.
130
+ * Runs the given function in the given owner to move ownership of nested primitives and cleanups.
131
+ * This method untracks the current scope.
131
132
  *
132
133
  * Warning: Usually there are simpler ways of modeling a problem that avoid using this function
133
134
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidjs/signals",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",