@solidjs/signals 0.0.3 → 0.0.5

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.
@@ -7,7 +7,8 @@
7
7
  export declare const STATE_CLEAN = 0;
8
8
  export declare const STATE_CHECK = 1;
9
9
  export declare const STATE_DIRTY = 2;
10
- export declare const STATE_DISPOSED = 3;
10
+ export declare const STATE_UNINITIALIZED = 3;
11
+ export declare const STATE_DISPOSED = 4;
11
12
  export declare const EFFECT_PURE = 0;
12
13
  export declare const EFFECT_RENDER = 1;
13
14
  export declare const EFFECT_USER = 2;
@@ -6,3 +6,4 @@ export { flushSync, createBoundary, type IQueue, Queue } from "./scheduler.js";
6
6
  export { createSuspense } from "./suspense.js";
7
7
  export { SUPPORTS_PROXY } from "./constants.js";
8
8
  export * from "./flags.js";
9
+ export { flatten } from "./utils.js";
@@ -85,6 +85,11 @@ export declare function setContext<T>(context: Context<T>, value?: T, owner?: Ow
85
85
  */
86
86
  export declare function hasContext(context: Context<any>, owner?: Owner | null): boolean;
87
87
  /**
88
- * Runs the given function when the parent owner computation is being disposed.
88
+ * Runs an effect once before the reactive scope is disposed
89
+ * @param fn an effect that should run only once on cleanup
90
+ *
91
+ * @returns the same {@link fn} function that was passed in
92
+ *
93
+ * @description https://docs.solidjs.com/reference/lifecycle/on-cleanup
89
94
  */
90
- export declare function onCleanup(disposable: Disposable): void;
95
+ export declare function onCleanup(fn: Disposable): Disposable;
@@ -23,4 +23,5 @@ export declare const globalQueue: Queue;
23
23
  * the queue synchronously to get the latest updates by calling `flushSync()`.
24
24
  */
25
25
  export declare function flushSync(): void;
26
+ export declare function queueTask(fn: () => void): void;
26
27
  export declare function createBoundary<T>(fn: () => T, queue: IQueue): T;
@@ -1,5 +1,5 @@
1
1
  import { Computation } from "./core.js";
2
- import type { Effect } from "./effect.js";
2
+ import { type Effect } from "./effect.js";
3
3
  import { Queue } from "./scheduler.js";
4
4
  export declare class SuspenseQueue extends Queue {
5
5
  _nodes: Set<Effect>;
@@ -0,0 +1,5 @@
1
+ export declare function isUndefined(value: any): value is undefined;
2
+ export declare function flatten(children: any, options?: {
3
+ skipNonRendered?: boolean;
4
+ doNotUnwrap?: boolean;
5
+ }): any;
@@ -1,4 +1,4 @@
1
- export { Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, createContext, flushSync, createBoundary, getContext, setContext, hasContext, getOwner, onCleanup, getObserver, isEqual, untrack, hasUpdated, isPending, latest, 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, 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, type Maybe } from "./map.js";
4
4
  export * from "./signals.js";
@@ -9,5 +9,5 @@ export type Maybe<T> = T | void | null | undefined | false;
9
9
  */
10
10
  export declare function mapArray<Item, MappedItem>(list: Accessor<Maybe<readonly Item[]>>, map: (value: Accessor<Item>, index: Accessor<number>) => MappedItem, options?: {
11
11
  keyed?: boolean | ((item: Item) => any);
12
- fallback: Accessor<any>;
12
+ fallback?: Accessor<any>;
13
13
  }): Accessor<MappedItem[]>;
@@ -8,6 +8,15 @@ export type Setter<in out T> = {
8
8
  <U extends T>(value: Exclude<U, Function> | ((prev: T) => U)): U;
9
9
  };
10
10
  export type Signal<T> = [get: Accessor<T>, set: Setter<T>];
11
+ export type ComputeFunction<Prev, Next extends Prev = Prev> = (v: Prev) => Next;
12
+ export type EffectFunction<Prev, Next extends Prev = Prev> = (v: Next, p?: Prev) => (() => void) | void;
13
+ export interface EffectOptions {
14
+ name?: string;
15
+ }
16
+ export interface MemoOptions<T> extends EffectOptions {
17
+ equals?: false | ((prev: T, next: T) => boolean);
18
+ }
19
+ export type NoInfer<T extends any> = [T][T extends any ? 0 : never];
11
20
  /**
12
21
  * Creates a simple reactive state with a getter and setter
13
22
  * ```typescript
@@ -33,31 +42,85 @@ export type Signal<T> = [get: Accessor<T>, set: Setter<T>];
33
42
  */
34
43
  export declare function createSignal<T>(): Signal<T | undefined>;
35
44
  export declare function createSignal<T>(value: Exclude<T, Function>, options?: SignalOptions<T>): Signal<T>;
36
- export declare function createSignal<T>(fn: (prev?: T) => T, initialValue?: T, options?: SignalOptions<T>): Signal<T>;
37
- export declare function createAsync<T>(fn: (prev?: T) => Promise<T> | AsyncIterable<T> | T, initial?: T, options?: SignalOptions<T>): Accessor<T>;
45
+ export declare function createSignal<T>(fn: ComputeFunction<T>, initialValue?: T, options?: SignalOptions<T>): Signal<T>;
38
46
  /**
39
- * Creates a new computation whose value is computed and returned by the given function. The given
40
- * compute function is _only_ re-run when one of it's dependencies are updated. Dependencies are
41
- * are all signals that are read during execution.
47
+ * Creates a readonly derived reactive memoized signal
48
+ * ```typescript
49
+ * export function createMemo<T>(
50
+ * compute: (v: T) => T,
51
+ * value?: T,
52
+ * options?: { name?: string, equals?: false | ((prev: T, next: T) => boolean) }
53
+ * ): () => T;
54
+ * ```
55
+ * @param compute a function that receives its previous or the initial value, if set, and returns a new value used to react on a computation
56
+ * @param value an optional initial value for the computation; if set, fn will never receive undefined as first argument
57
+ * @param options allows to set a name in dev mode for debugging purposes and use a custom comparison function in equals
58
+ *
59
+ * @description https://docs.solidjs.com/reference/basic-reactivity/create-memo
42
60
  */
43
- export declare function createMemo<T>(compute: (prev?: T) => T, initialValue?: T, options?: SignalOptions<T>): Accessor<T>;
61
+ export declare function createMemo<Next extends Prev, Prev = Next>(compute: ComputeFunction<undefined | NoInfer<Prev>, Next>): Accessor<Next>;
62
+ export declare function createMemo<Next extends Prev, Init = Next, Prev = Next>(compute: ComputeFunction<Init | Prev, Next>, value: Init, options?: MemoOptions<Next>): Accessor<Next>;
44
63
  /**
45
- * Invokes the given function each time any of the signals that are read inside are updated
46
- * (i.e., their value changes). The effect is immediately invoked on initialization.
64
+ * Creates a readonly derived async reactive memoized signal
65
+ * ```typescript
66
+ * export function createAsync<T>(
67
+ * compute: (v: T) => Promise<T> | T,
68
+ * value?: T,
69
+ * options?: { name?: string, equals?: false | ((prev: T, next: T) => boolean) }
70
+ * ): () => T;
71
+ * ```
72
+ * @param compute a function that receives its previous or the initial value, if set, and returns a new value used to react on a computation
73
+ * @param value an optional initial value for the computation; if set, fn will never receive undefined as first argument
74
+ * @param options allows to set a name in dev mode for debugging purposes and use a custom comparison function in equals
75
+ *
76
+ * @description https://docs.solidjs.com/reference/basic-reactivity/create-async
47
77
  */
48
- export declare function createEffect<T>(compute: () => T, effect: (v: T) => (() => void) | void, initialValue?: T, options?: {
49
- name?: string;
50
- }): void;
78
+ export declare function createAsync<T>(compute: (prev?: T) => Promise<T> | AsyncIterable<T> | T, value?: T, options?: MemoOptions<T>): Accessor<T>;
51
79
  /**
52
- * Invokes the given function each time any of the signals that are read inside are updated
53
- * (i.e., their value changes). The effect is immediately invoked on initialization.
80
+ * Creates a reactive effect that runs after the render phase
81
+ * ```typescript
82
+ * export function createEffect<T>(
83
+ * compute: (prev: T) => T,
84
+ * effect: (v: T, prev: T) => (() => void) | void,
85
+ * value?: T,
86
+ * options?: { name?: string }
87
+ * ): void;
88
+ * ```
89
+ * @param compute a function that receives its previous or the initial value, if set, and returns a new value used to react on a computation
90
+ * @param effect a function that receives the new value and is used to perform side effects
91
+ * @param value an optional initial value for the computation; if set, fn will never receive undefined as first argument
92
+ * @param options allows to set a name in dev mode for debugging purposes
93
+ *
94
+ * @description https://docs.solidjs.com/reference/basic-reactivity/create-effect
54
95
  */
55
- export declare function createRenderEffect<T>(compute: () => T, effect: (v: T) => (() => void) | void, initialValue?: T, options?: {
56
- name?: string;
57
- }): void;
96
+ export declare function createEffect<Next>(compute: ComputeFunction<undefined | NoInfer<Next>, Next>, effect: EffectFunction<NoInfer<Next>, Next>): void;
97
+ export declare function createEffect<Next, Init = Next>(compute: ComputeFunction<Init | Next, Next>, effect: EffectFunction<Next, Next>, value: Init, options?: EffectOptions): void;
98
+ /**
99
+ * Creates a reactive computation that runs during the render phase as DOM elements are created and updated but not necessarily connected
100
+ * ```typescript
101
+ * export function createRenderEffect<T>(
102
+ * compute: (prev: T) => T,
103
+ * effect: (v: T, prev: T) => (() => void) | void,
104
+ * value?: T,
105
+ * options?: { name?: string }
106
+ * ): void;
107
+ * ```
108
+ * @param compute a function that receives its previous or the initial value, if set, and returns a new value used to react on a computation
109
+ * @param effect a function that receives the new value and is used to perform side effects
110
+ * @param value an optional initial value for the computation; if set, fn will never receive undefined as first argument
111
+ * @param options allows to set a name in dev mode for debugging purposes
112
+ *
113
+ * @description https://docs.solidjs.com/reference/secondary-primitives/create-render-effect
114
+ */
115
+ export declare function createRenderEffect<Next>(compute: ComputeFunction<undefined | NoInfer<Next>, Next>, effect: EffectFunction<NoInfer<Next>, Next>): void;
116
+ export declare function createRenderEffect<Next, Init = Next>(compute: ComputeFunction<Init | Next, Next>, effect: EffectFunction<Next, Next>, value: Init, options?: EffectOptions): void;
58
117
  /**
59
- * Creates a computation root which is given a `dispose()` function to dispose of all inner
60
- * computations.
118
+ * Creates a new non-tracked reactive context with manual disposal
119
+ *
120
+ * @param fn a function in which the reactive state is scoped
121
+ * @returns the output of `fn`.
122
+ *
123
+ * @description https://docs.solidjs.com/reference/reactive-utilities/create-root
61
124
  */
62
125
  export declare function createRoot<T>(init: ((dispose: () => void) => T) | (() => T)): T;
63
126
  /**
@@ -67,7 +130,12 @@ export declare function createRoot<T>(init: ((dispose: () => void) => T) | (() =
67
130
  */
68
131
  export declare function runWithOwner<T>(owner: Owner | null, run: () => T): T | undefined;
69
132
  /**
70
- * Runs the given function when an error is thrown in a child owner. If the error is thrown again
71
- * inside the error handler, it will trigger the next available parent owner handler.
133
+ * Runs an effect whenever an error is thrown within the context of the child scopes
134
+ * @param fn boundary for the error
135
+ * @param handler an error handler that receives the error
136
+ *
137
+ * * If the error is thrown again inside the error handler, it will trigger the next available parent handler
138
+ *
139
+ * @description https://docs.solidjs.com/reference/reactive-utilities/catch-error
72
140
  */
73
- export declare function catchError<T>(fn: () => T, handler: (error: unknown) => void): void;
141
+ export declare function catchError<T>(fn: () => T, handler: (error: unknown) => void): T | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidjs/signals",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",
@@ -1 +0,0 @@
1
- export declare function isUndefined(value: any): value is undefined;