@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.
- package/dist/dev.js +153 -55
- package/dist/node.cjs +306 -212
- package/dist/prod.js +303 -212
- package/dist/types/core/constants.d.ts +2 -1
- package/dist/types/core/index.d.ts +1 -0
- package/dist/types/core/owner.d.ts +7 -2
- package/dist/types/core/scheduler.d.ts +1 -0
- package/dist/types/core/suspense.d.ts +1 -1
- package/dist/types/core/utils.d.ts +5 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/map.d.ts +1 -1
- package/dist/types/signals.d.ts +89 -21
- package/package.json +1 -1
- package/dist/types/utils.d.ts +0 -1
|
@@ -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
|
|
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;
|
|
@@ -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
|
|
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(
|
|
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;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -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";
|
package/dist/types/map.d.ts
CHANGED
|
@@ -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
|
|
12
|
+
fallback?: Accessor<any>;
|
|
13
13
|
}): Accessor<MappedItem[]>;
|
package/dist/types/signals.d.ts
CHANGED
|
@@ -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:
|
|
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
|
|
40
|
-
*
|
|
41
|
-
*
|
|
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<
|
|
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
|
-
*
|
|
46
|
-
*
|
|
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
|
|
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
|
-
*
|
|
53
|
-
*
|
|
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
|
|
56
|
-
|
|
57
|
-
|
|
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
|
|
60
|
-
*
|
|
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
|
|
71
|
-
*
|
|
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):
|
|
141
|
+
export declare function catchError<T>(fn: () => T, handler: (error: unknown) => void): T | undefined;
|
package/package.json
CHANGED
package/dist/types/utils.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isUndefined(value: any): value is undefined;
|