@solidjs/signals 0.0.2 → 0.0.4
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 +101 -63
- package/dist/node.cjs +271 -239
- package/dist/prod.js +270 -239
- 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/index.d.ts +1 -1
- package/dist/types/map.d.ts +5 -4
- package/dist/types/signals.d.ts +110 -30
- package/dist/types/store/index.d.ts +1 -1
- package/dist/types/store/reconcile.d.ts +1 -1
- package/package.json +7 -2
|
@@ -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;
|
|
@@ -4,4 +4,5 @@ export { Computation, getObserver, isEqual, untrack, hasUpdated, isPending, late
|
|
|
4
4
|
export { Effect, EagerComputation } from "./effect.js";
|
|
5
5
|
export { flushSync, createBoundary, type IQueue, Queue } from "./scheduler.js";
|
|
6
6
|
export { createSuspense } from "./suspense.js";
|
|
7
|
+
export { SUPPORTS_PROXY } from "./constants.js";
|
|
7
8
|
export * from "./flags.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
|
|
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;
|
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 } from "./core/index.js";
|
|
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";
|
|
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
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type { Accessor } from "./signals.js";
|
|
2
2
|
export type Maybe<T> = T | void | null | undefined | false;
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
* updates.
|
|
4
|
+
* Reactively transforms an array with a callback function - underlying helper for the `<For>` control flow
|
|
6
5
|
*
|
|
7
|
-
*
|
|
6
|
+
* similar to `Array.prototype.map`, but gets the value and index as accessos, transforms only values that changed and returns an accessor and reactively tracks changes to the list.
|
|
7
|
+
*
|
|
8
|
+
* @description https://docs.solidjs.com/reference/reactive-utilities/map-array
|
|
8
9
|
*/
|
|
9
10
|
export declare function mapArray<Item, MappedItem>(list: Accessor<Maybe<readonly Item[]>>, map: (value: Accessor<Item>, index: Accessor<number>) => MappedItem, options?: {
|
|
10
11
|
keyed?: boolean | ((item: Item) => any);
|
|
11
|
-
|
|
12
|
+
fallback?: Accessor<any>;
|
|
12
13
|
}): Accessor<MappedItem[]>;
|
package/dist/types/signals.d.ts
CHANGED
|
@@ -1,46 +1,126 @@
|
|
|
1
1
|
import type { SignalOptions } from "./core/index.js";
|
|
2
2
|
import { Owner } from "./core/index.js";
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
(value:
|
|
3
|
+
export type Accessor<T> = () => T;
|
|
4
|
+
export type Setter<in out T> = {
|
|
5
|
+
<U extends T>(...args: undefined extends T ? [] : [value: Exclude<U, Function> | ((prev: T) => U)]): undefined extends T ? undefined : U;
|
|
6
|
+
<U extends T>(value: (prev: T) => U): U;
|
|
7
|
+
<U extends T>(value: Exclude<U, Function>): U;
|
|
8
|
+
<U extends T>(value: Exclude<U, Function> | ((prev: T) => U)): U;
|
|
9
|
+
};
|
|
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;
|
|
8
15
|
}
|
|
9
|
-
export interface
|
|
10
|
-
(
|
|
16
|
+
export interface MemoOptions<T> extends EffectOptions {
|
|
17
|
+
equals?: false | ((prev: T, next: T) => boolean);
|
|
11
18
|
}
|
|
12
|
-
export type
|
|
19
|
+
export type NoInfer<T extends any> = [T][T extends any ? 0 : never];
|
|
13
20
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
21
|
+
* Creates a simple reactive state with a getter and setter
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const [state: Accessor<T>, setState: Setter<T>] = createSignal<T>(
|
|
24
|
+
* value: T,
|
|
25
|
+
* options?: { name?: string, equals?: false | ((prev: T, next: T) => boolean) }
|
|
26
|
+
* )
|
|
27
|
+
* ```
|
|
28
|
+
* @param value initial value of the state; if empty, the state's type will automatically extended with undefined; otherwise you need to extend the type manually if you want setting to undefined not be an error
|
|
29
|
+
* @param options optional object with a name for debugging purposes and equals, a comparator function for the previous and next value to allow fine-grained control over the reactivity
|
|
30
|
+
*
|
|
31
|
+
* @returns ```typescript
|
|
32
|
+
* [state: Accessor<T>, setState: Setter<T>]
|
|
33
|
+
* ```
|
|
34
|
+
* * the Accessor is a function that returns the current value and registers each call to the reactive root
|
|
35
|
+
* * the Setter is a function that allows directly setting or mutating the value:
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const [count, setCount] = createSignal(0);
|
|
38
|
+
* setCount(count => count + 1);
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @description https://docs.solidjs.com/reference/basic-reactivity/create-signal
|
|
17
42
|
*/
|
|
18
|
-
export declare function createSignal<T>(
|
|
19
|
-
export declare function createSignal<T>(
|
|
20
|
-
export declare function
|
|
43
|
+
export declare function createSignal<T>(): Signal<T | undefined>;
|
|
44
|
+
export declare function createSignal<T>(value: Exclude<T, Function>, options?: SignalOptions<T>): Signal<T>;
|
|
45
|
+
export declare function createSignal<T>(fn: ComputeFunction<T>, initialValue?: T, options?: SignalOptions<T>): Signal<T>;
|
|
21
46
|
/**
|
|
22
|
-
* Creates a
|
|
23
|
-
*
|
|
24
|
-
*
|
|
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
|
|
25
60
|
*/
|
|
26
|
-
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>;
|
|
27
63
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
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
|
|
30
77
|
*/
|
|
31
|
-
export declare function
|
|
32
|
-
name?: string;
|
|
33
|
-
}): void;
|
|
78
|
+
export declare function createAsync<T>(compute: (prev?: T) => Promise<T> | AsyncIterable<T> | T, value?: T, options?: MemoOptions<T>): Accessor<T>;
|
|
34
79
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
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
|
|
37
95
|
*/
|
|
38
|
-
export declare function
|
|
39
|
-
|
|
40
|
-
}): 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;
|
|
41
98
|
/**
|
|
42
|
-
* Creates a computation
|
|
43
|
-
*
|
|
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;
|
|
117
|
+
/**
|
|
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
|
|
44
124
|
*/
|
|
45
125
|
export declare function createRoot<T>(init: ((dispose: () => void) => T) | (() => T)): T;
|
|
46
126
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { Store, StoreSetter, StoreNode, NotWrappable } from "./store.js";
|
|
1
|
+
export type { Store, StoreSetter, StoreNode, NotWrappable, SolidStore } from "./store.js";
|
|
2
2
|
export type { Merge, Omit } from "./utilities.js";
|
|
3
3
|
export { unwrap, isWrappable, createStore, createProjection, $RAW, $TRACK, $PROXY, $TARGET } from "./store.js";
|
|
4
4
|
export { reconcile } from "./reconcile.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function reconcile<T extends U, U>(value: T, key: string | ((item: NonNullable<any>) => any)): (state: U) =>
|
|
1
|
+
export declare function reconcile<T extends U, U>(value: T, key: string | ((item: NonNullable<any>) => any)): (state: U) => T;
|
package/package.json
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solidjs/signals",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "",
|
|
5
|
-
"
|
|
5
|
+
"author": "Ryan Carniato",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/solidjs/signals"
|
|
10
|
+
},
|
|
6
11
|
"type": "module",
|
|
7
12
|
"main": "dist/node.cjs",
|
|
8
13
|
"module": "dist/prod.js",
|