@solidjs/signals 0.2.0 → 0.2.1

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,32 @@ 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 (argLength > 1 && err instanceof NotReadyError)
670
+ return !!loadingValue;
671
+ throw err;
667
672
  } finally {
668
673
  staleCheck = current;
669
674
  }
670
675
  }
671
- function latest(fn) {
676
+ function latest(fn, fallback) {
677
+ const argLength = arguments.length;
672
678
  const prevFlags = newFlags;
673
679
  const prevNotStale = notStale;
674
680
  notStale = false;
675
681
  try {
676
682
  return fn();
683
+ } catch (err) {
684
+ if (argLength > 1 && err instanceof NotReadyError)
685
+ return fallback;
686
+ throw err;
677
687
  } finally {
678
688
  newFlags = prevFlags;
679
689
  notStale = prevNotStale;
@@ -697,7 +707,10 @@ function runWithObserver(observer, run) {
697
707
  return compute(observer, run, observer);
698
708
  } catch (error) {
699
709
  if (error instanceof NotReadyError) {
700
- observer.write(UNCHANGED, newFlags | LOADING_BIT | observer._stateFlags & UNINITIALIZED_BIT);
710
+ observer.write(
711
+ UNCHANGED,
712
+ newFlags | LOADING_BIT | observer._stateFlags & UNINITIALIZED_BIT
713
+ );
701
714
  } else {
702
715
  observer._setError(error);
703
716
  }
@@ -1741,4 +1754,4 @@ function compare(key, a, b) {
1741
1754
  return key ? key(a) === key(b) : true;
1742
1755
  }
1743
1756
 
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 };
1757
+ 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,32 @@ 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 (argLength > 1 && err instanceof NotReadyError)
667
+ return !!loadingValue;
668
+ throw err;
664
669
  } finally {
665
670
  staleCheck = current;
666
671
  }
667
672
  }
668
- function latest(fn) {
673
+ function latest(fn, fallback) {
674
+ const argLength = arguments.length;
669
675
  const prevFlags = newFlags;
670
676
  const prevNotStale = notStale;
671
677
  notStale = false;
672
678
  try {
673
679
  return fn();
680
+ } catch (err) {
681
+ if (argLength > 1 && err instanceof NotReadyError)
682
+ return fallback;
683
+ throw err;
674
684
  } finally {
675
685
  newFlags = prevFlags;
676
686
  notStale = prevNotStale;
@@ -694,7 +704,10 @@ function runWithObserver(observer, run) {
694
704
  return compute(observer, run, observer);
695
705
  } catch (error) {
696
706
  if (error instanceof NotReadyError) {
697
- observer.write(UNCHANGED, newFlags | LOADING_BIT | observer.d & UNINITIALIZED_BIT);
707
+ observer.write(
708
+ UNCHANGED,
709
+ newFlags | LOADING_BIT | observer.d & UNINITIALIZED_BIT
710
+ );
698
711
  } else {
699
712
  observer.F(error);
700
713
  }
@@ -1773,7 +1786,7 @@ exports.getOwner = getOwner;
1773
1786
  exports.hasContext = hasContext;
1774
1787
  exports.hasUpdated = hasUpdated;
1775
1788
  exports.isEqual = isEqual;
1776
- exports.isStale = isStale;
1789
+ exports.isPending = isPending;
1777
1790
  exports.isWrappable = isWrappable;
1778
1791
  exports.latest = latest;
1779
1792
  exports.mapArray = mapArray;
package/dist/prod.js CHANGED
@@ -651,22 +651,32 @@ 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 (argLength > 1 && err instanceof NotReadyError)
663
+ return !!loadingValue;
664
+ throw err;
660
665
  } finally {
661
666
  staleCheck = current;
662
667
  }
663
668
  }
664
- function latest(fn) {
669
+ function latest(fn, fallback) {
670
+ const argLength = arguments.length;
665
671
  const prevFlags = newFlags;
666
672
  const prevNotStale = notStale;
667
673
  notStale = false;
668
674
  try {
669
675
  return fn();
676
+ } catch (err) {
677
+ if (argLength > 1 && err instanceof NotReadyError)
678
+ return fallback;
679
+ throw err;
670
680
  } finally {
671
681
  newFlags = prevFlags;
672
682
  notStale = prevNotStale;
@@ -690,7 +700,10 @@ function runWithObserver(observer, run) {
690
700
  return compute(observer, run, observer);
691
701
  } catch (error) {
692
702
  if (error instanceof NotReadyError) {
693
- observer.write(UNCHANGED, newFlags | LOADING_BIT | observer.d & UNINITIALIZED_BIT);
703
+ observer.write(
704
+ UNCHANGED,
705
+ newFlags | LOADING_BIT | observer.d & UNINITIALIZED_BIT
706
+ );
694
707
  } else {
695
708
  observer.F(error);
696
709
  }
@@ -1728,4 +1741,4 @@ function compare(key, a, b) {
1728
1741
  return key ? key(a) === key(b) : true;
1729
1742
  }
1730
1743
 
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 };
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, 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.1",
4
4
  "description": "",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",