@solidjs/signals 0.2.5 → 0.3.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.
@@ -0,0 +1,17 @@
1
+ import { Computation } from "./core.js";
2
+ import { type Effect } from "./effect.js";
3
+ import { Queue } from "./scheduler.js";
4
+ export declare class CollectionQueue extends Queue {
5
+ _collectionType: number;
6
+ _nodes: Set<Effect>;
7
+ _disabled: Computation<boolean>;
8
+ constructor(type: number);
9
+ notify(node: Effect, type: number, flags: number): boolean;
10
+ }
11
+ export declare enum BoundaryMode {
12
+ VISIBLE = "visible",
13
+ HIDDEN = "hidden"
14
+ }
15
+ export declare function createBoundary<T>(fn: () => T, condition: () => BoundaryMode): () => T | undefined;
16
+ export declare function createSuspense(fn: () => any, fallback: () => any): () => any;
17
+ export declare function createErrorBoundary<U>(fn: () => any, fallback: (error: unknown, reset: () => void) => U): () => any;
@@ -28,7 +28,6 @@
28
28
  */
29
29
  import { type Flags } from "./flags.js";
30
30
  import { Owner } from "./owner.js";
31
- import { type IQueue } from "./scheduler.js";
32
31
  export interface SignalOptions<T> {
33
32
  name?: string;
34
33
  equals?: ((prev: T, next: T) => boolean) | false;
@@ -67,7 +66,6 @@ export declare class Computation<T = any> extends Owner implements SourceType, O
67
66
  _stateFlags: number;
68
67
  /** Which flags raised by sources are handled, vs. being passed through. */
69
68
  _handlerMask: number;
70
- _loading: Computation<boolean> | null;
71
69
  _time: number;
72
70
  _forceNotify: boolean;
73
71
  constructor(initialValue: T | undefined, compute: null | ((p?: T) => T), options?: SignalOptions<T>);
@@ -85,14 +83,6 @@ export declare class Computation<T = any> extends Owner implements SourceType, O
85
83
  * before continuing
86
84
  */
87
85
  wait(): T;
88
- /**
89
- * Return true if the computation is the value is dependent on an unresolved promise
90
- * Triggers re-execution of the computation when the loading state changes
91
- *
92
- * This is useful especially when effects want to re-execute when a computation's
93
- * loading state changes
94
- */
95
- loading(): boolean;
96
86
  /** Update the computation with a new value. */
97
87
  write(value: T | ((currentValue: T) => T) | UNCHANGED, flags?: number, raw?: boolean): T;
98
88
  /**
@@ -140,7 +130,7 @@ export declare function untrack<T>(fn: () => T): T;
140
130
  */
141
131
  export declare function hasUpdated(fn: () => any): boolean;
142
132
  /**
143
- * Returns true if the given function contains async signals are out of date.
133
+ * Returns an accessor that is true if the given function contains async signals are out of date.
144
134
  */
145
135
  export declare function isPending(fn: () => any): boolean;
146
136
  export declare function isPending(fn: () => any, loadingValue: boolean): boolean;
@@ -149,7 +139,6 @@ export declare function isPending(fn: () => any, loadingValue: boolean): boolean
149
139
  */
150
140
  export declare function latest<T>(fn: () => T): T;
151
141
  export declare function latest<T, U>(fn: () => T, fallback: U): T | U;
152
- export declare function catchError(fn: () => void): unknown | undefined;
153
142
  /**
154
143
  * Runs the given function in the given observer.
155
144
  *
@@ -166,5 +155,4 @@ export declare function flatten(children: any, options?: {
166
155
  skipNonRendered?: boolean;
167
156
  doNotUnwrap?: boolean;
168
157
  }): any;
169
- export declare function createBoundary<T>(fn: () => T, queue: IQueue): T;
170
158
  export {};
@@ -1,8 +1,9 @@
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, isPending, latest, flatten, catchError, UNCHANGED, compute, runWithObserver, type SignalOptions } from "./core.js";
3
+ export { Computation, getObserver, isEqual, untrack, hasUpdated, isPending, latest, flatten, UNCHANGED, compute, runWithObserver, type SignalOptions } from "./core.js";
4
4
  export { Effect, EagerComputation } from "./effect.js";
5
- export { flushSync, getClock, incrementClock, type IQueue, Queue } from "./scheduler.js";
6
- export { createSuspense } from "./suspense.js";
5
+ export { flushSync, type IQueue, Queue } from "./scheduler.js";
6
+ export { createSuspense, createErrorBoundary, createBoundary, type BoundaryMode } from "./boundaries.js";
7
7
  export { SUPPORTS_PROXY } from "./constants.js";
8
+ export { tryCatch, type TryCatchResult } from "./utils.js";
8
9
  export * from "./flags.js";
@@ -27,7 +27,6 @@
27
27
  *
28
28
  * Note that the owner tree is largely orthogonal to the reactivity tree, and is much closer to the component tree.
29
29
  */
30
- import { type ErrorHandler } from "./error.js";
31
30
  import { type IQueue } from "./scheduler.js";
32
31
  export type ContextRecord = Record<string | symbol, unknown>;
33
32
  export interface Disposable {
@@ -45,14 +44,15 @@ export declare class Owner {
45
44
  _state: number;
46
45
  _disposal: Disposable | Disposable[] | null;
47
46
  _context: ContextRecord;
48
- _handlers: ErrorHandler[] | null;
49
47
  _queue: IQueue;
50
- constructor(signal?: boolean);
48
+ _childCount: number;
49
+ id: string | null;
50
+ constructor(id?: string | null, skipAppend?: boolean);
51
51
  append(child: Owner): void;
52
52
  dispose(this: Owner, self?: boolean): void;
53
53
  _disposeNode(): void;
54
54
  emptyDisposal(): void;
55
- handleError(error: unknown): void;
55
+ getNextChildId(): string;
56
56
  }
57
57
  export interface Context<T> {
58
58
  readonly id: symbol;
@@ -9,17 +9,21 @@ export interface IQueue {
9
9
  addChild(child: IQueue): void;
10
10
  removeChild(child: IQueue): void;
11
11
  created: number;
12
+ notify(...args: any[]): boolean;
13
+ _parent: IQueue | null;
12
14
  }
13
15
  export declare class Queue implements IQueue {
16
+ _parent: IQueue | null;
14
17
  _running: boolean;
15
18
  _queues: [Computation[], Effect[], Effect[]];
16
19
  _children: IQueue[];
17
20
  created: number;
18
21
  enqueue<T extends Computation | Effect>(type: number, node: T): void;
19
- run(type: number): true | undefined;
22
+ run(type: number): boolean | undefined;
20
23
  flush(): void;
21
24
  addChild(child: IQueue): void;
22
25
  removeChild(child: IQueue): void;
26
+ notify(...args: any[]): boolean;
23
27
  }
24
28
  export declare const globalQueue: Queue;
25
29
  /**
@@ -1 +1,4 @@
1
1
  export declare function isUndefined(value: any): value is undefined;
2
+ export type TryCatchResult<T, E> = [undefined, T] | [E];
3
+ export declare function tryCatch<T, E = Error>(fn: () => Promise<T>): Promise<TryCatchResult<T, E>>;
4
+ export declare function tryCatch<T, E = Error>(fn: () => T): TryCatchResult<T, E>;
@@ -1,5 +1,5 @@
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
- export type { ErrorHandler, SignalOptions, Context, ContextRecord, Disposable, IQueue } from "./core/index.js";
1
+ export { Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, createContext, flatten, flushSync, getContext, setContext, hasContext, getOwner, onCleanup, getObserver, isEqual, untrack, hasUpdated, isPending, latest, tryCatch, runWithObserver, createErrorBoundary, createSuspense, createBoundary, SUPPORTS_PROXY } from "./core/index.js";
2
+ export type { ErrorHandler, SignalOptions, BoundaryMode, TryCatchResult, Context, ContextRecord, Disposable, IQueue } from "./core/index.js";
3
3
  export { mapArray, repeat, type Maybe } from "./map.js";
4
4
  export * from "./signals.js";
5
5
  export * from "./store/index.js";
@@ -125,7 +125,9 @@ export declare function createRenderEffect<Next, Init = Next>(compute: ComputeFu
125
125
  *
126
126
  * @description https://docs.solidjs.com/reference/reactive-utilities/create-root
127
127
  */
128
- export declare function createRoot<T>(init: ((dispose: () => void) => T) | (() => T)): T;
128
+ export declare function createRoot<T>(init: ((dispose: () => void) => T) | (() => T), options?: {
129
+ id: string;
130
+ }): T;
129
131
  /**
130
132
  * Runs the given function in the given owner to move ownership of nested primitives and cleanups.
131
133
  * This method untracks the current scope.
@@ -133,16 +135,6 @@ export declare function createRoot<T>(init: ((dispose: () => void) => T) | (() =
133
135
  * Warning: Usually there are simpler ways of modeling a problem that avoid using this function
134
136
  */
135
137
  export declare function runWithOwner<T>(owner: Owner | null, run: () => T): T;
136
- /**
137
- * Switches to fallback whenever an error is thrown within the context of the child scopes
138
- * @param fn boundary for the error
139
- * @param fallback an error handler that receives the error
140
- *
141
- * * If the error is thrown again inside the error handler, it will trigger the next available parent handler
142
- *
143
- * @description https://docs.solidjs.com/reference/reactive-utilities/catch-error
144
- */
145
- export declare function createErrorBoundary<T, U>(fn: () => T, fallback: (error: unknown, reset: () => void) => U): Accessor<T | U>;
146
138
  /**
147
139
  * Returns a promise of the resolved value of a reactive expression
148
140
  * @param fn a reactive expression to resolve
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidjs/signals",
3
- "version": "0.2.5",
3
+ "version": "0.3.1",
4
4
  "description": "",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",
@@ -1,11 +0,0 @@
1
- import { Computation } from "./core.js";
2
- import { type Effect } from "./effect.js";
3
- import { Queue } from "./scheduler.js";
4
- export declare class SuspenseQueue extends Queue {
5
- _nodes: Set<Effect>;
6
- _fallback: boolean;
7
- _signal: Computation<boolean>;
8
- run(type: number): true | undefined;
9
- _update(node: Effect): void;
10
- }
11
- export declare function createSuspense(fn: () => any, fallback: () => any): () => any;