@solidjs/signals 0.0.7 → 0.0.9
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 +272 -107
- package/dist/node.cjs +557 -389
- package/dist/prod.js +549 -389
- package/dist/types/core/constants.d.ts +1 -2
- package/dist/types/core/core.d.ts +14 -13
- package/dist/types/core/effect.d.ts +12 -4
- package/dist/types/core/error.d.ts +3 -0
- package/dist/types/core/flags.d.ts +3 -0
- package/dist/types/core/index.d.ts +2 -2
- package/dist/types/core/scheduler.d.ts +0 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/map.d.ts +9 -1
- package/dist/types/signals.d.ts +24 -3
- package/dist/types/store/index.d.ts +2 -1
- package/dist/types/store/projection.d.ts +6 -0
- package/dist/types/store/store.d.ts +0 -6
- package/package.json +1 -1
|
@@ -7,8 +7,7 @@
|
|
|
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
|
|
11
|
-
export declare const STATE_DISPOSED = 4;
|
|
10
|
+
export declare const STATE_DISPOSED = 3;
|
|
12
11
|
export declare const EFFECT_PURE = 0;
|
|
13
12
|
export declare const EFFECT_RENDER = 1;
|
|
14
13
|
export declare const EFFECT_USER = 2;
|
|
@@ -42,7 +42,7 @@ interface SourceType {
|
|
|
42
42
|
}
|
|
43
43
|
interface ObserverType {
|
|
44
44
|
_sources: SourceType[] | null;
|
|
45
|
-
_notify: (state: number) => void;
|
|
45
|
+
_notify: (state: number, skipQueue?: boolean) => void;
|
|
46
46
|
_handlerMask: Flags;
|
|
47
47
|
_notifyFlags: (mask: Flags, newFlags: Flags) => void;
|
|
48
48
|
_time: number;
|
|
@@ -51,6 +51,7 @@ interface ObserverType {
|
|
|
51
51
|
* Returns the current observer.
|
|
52
52
|
*/
|
|
53
53
|
export declare function getObserver(): ObserverType | null;
|
|
54
|
+
export declare function getClock(): number;
|
|
54
55
|
export declare function incrementClock(): void;
|
|
55
56
|
export declare const UNCHANGED: unique symbol;
|
|
56
57
|
export type UNCHANGED = typeof UNCHANGED;
|
|
@@ -58,6 +59,7 @@ export declare class Computation<T = any> extends Owner implements SourceType, O
|
|
|
58
59
|
_sources: SourceType[] | null;
|
|
59
60
|
_observers: ObserverType[] | null;
|
|
60
61
|
_value: T | undefined;
|
|
62
|
+
_error: unknown;
|
|
61
63
|
_compute: null | ((p?: T) => T);
|
|
62
64
|
_name: string | undefined;
|
|
63
65
|
_equals: false | ((a: T, b: T) => boolean);
|
|
@@ -66,9 +68,9 @@ export declare class Computation<T = any> extends Owner implements SourceType, O
|
|
|
66
68
|
_stateFlags: number;
|
|
67
69
|
/** Which flags raised by sources are handled, vs. being passed through. */
|
|
68
70
|
_handlerMask: number;
|
|
69
|
-
_error: Computation<boolean> | null;
|
|
70
71
|
_loading: Computation<boolean> | null;
|
|
71
72
|
_time: number;
|
|
73
|
+
_forceNotify: boolean;
|
|
72
74
|
constructor(initialValue: T | undefined, compute: null | ((p?: T) => T), options?: SignalOptions<T>);
|
|
73
75
|
_read(): T;
|
|
74
76
|
/**
|
|
@@ -92,17 +94,12 @@ export declare class Computation<T = any> extends Owner implements SourceType, O
|
|
|
92
94
|
* loading state changes
|
|
93
95
|
*/
|
|
94
96
|
loading(): boolean;
|
|
95
|
-
/**
|
|
96
|
-
* Return true if the computation is the computation threw an error
|
|
97
|
-
* Triggers re-execution of the computation when the error state changes
|
|
98
|
-
*/
|
|
99
|
-
error(): boolean;
|
|
100
97
|
/** Update the computation with a new value. */
|
|
101
98
|
write(value: T | ((currentValue: T) => T) | UNCHANGED, flags?: number, raw?: boolean): T;
|
|
102
99
|
/**
|
|
103
100
|
* Set the current node's state, and recursively mark all of this node's observers as STATE_CHECK
|
|
104
101
|
*/
|
|
105
|
-
_notify(state: number): void;
|
|
102
|
+
_notify(state: number, skipQueue?: boolean): void;
|
|
106
103
|
/**
|
|
107
104
|
* Notify the computation that one of its sources has changed flags.
|
|
108
105
|
*
|
|
@@ -144,14 +141,18 @@ export declare function untrack<T>(fn: () => T): T;
|
|
|
144
141
|
*/
|
|
145
142
|
export declare function hasUpdated(fn: () => any): boolean;
|
|
146
143
|
/**
|
|
147
|
-
* Returns true if the given function contains async signals
|
|
144
|
+
* Returns true if the given function contains async signals are out of date.
|
|
145
|
+
*/
|
|
146
|
+
export declare function isStale(fn: () => any): boolean;
|
|
147
|
+
/**
|
|
148
|
+
* Attempts to resolve value of expression synchronously returning the last resolved value for any async computation.
|
|
148
149
|
*/
|
|
149
|
-
export declare function
|
|
150
|
-
export declare function
|
|
150
|
+
export declare function latest<T>(fn: () => T): T;
|
|
151
|
+
export declare function catchError(fn: () => void): unknown | undefined;
|
|
151
152
|
/**
|
|
152
153
|
* A convenient wrapper that calls `compute` with the `owner` and `observer` and is guaranteed
|
|
153
154
|
* to reset the global context after the computation is finished even if an error is thrown.
|
|
154
155
|
*/
|
|
155
|
-
export declare function compute<T>(owner: Owner | null,
|
|
156
|
-
export declare function compute<T>(owner: Owner | null,
|
|
156
|
+
export declare function compute<T>(owner: Owner | null, fn: (val: T) => T, observer: Computation<T>): T;
|
|
157
|
+
export declare function compute<T>(owner: Owner | null, fn: (val: undefined) => T, observer: null): T;
|
|
157
158
|
export {};
|
|
@@ -7,16 +7,19 @@ import { type IQueue } from "./scheduler.js";
|
|
|
7
7
|
* sources and recompute
|
|
8
8
|
*/
|
|
9
9
|
export declare class Effect<T = any> extends Computation<T> {
|
|
10
|
-
_effect: (val: T, prev: T | undefined) => void;
|
|
10
|
+
_effect: (val: T, prev: T | undefined) => void | (() => void);
|
|
11
|
+
_onerror: ((err: unknown) => void | (() => void)) | undefined;
|
|
12
|
+
_cleanup: (() => void) | undefined;
|
|
11
13
|
_modified: boolean;
|
|
12
14
|
_prevValue: T | undefined;
|
|
13
15
|
_type: typeof EFFECT_RENDER | typeof EFFECT_USER;
|
|
14
16
|
_queue: IQueue;
|
|
15
|
-
constructor(initialValue: T, compute: () => T, effect: (val: T, prev: T | undefined) => void, options?: SignalOptions<T> & {
|
|
17
|
+
constructor(initialValue: T, compute: (val?: T) => T, effect: (val: T, prev: T | undefined) => void | (() => void), error?: (err: unknown) => void | (() => void), options?: SignalOptions<T> & {
|
|
16
18
|
render?: boolean;
|
|
19
|
+
defer?: boolean;
|
|
17
20
|
});
|
|
18
21
|
write(value: T, flags?: number): T;
|
|
19
|
-
_notify(state: number): void;
|
|
22
|
+
_notify(state: number, skipQueue?: boolean): void;
|
|
20
23
|
_setError(error: unknown): void;
|
|
21
24
|
_disposeNode(): void;
|
|
22
25
|
_runEffect(): void;
|
|
@@ -24,5 +27,10 @@ export declare class Effect<T = any> extends Computation<T> {
|
|
|
24
27
|
export declare class EagerComputation<T = any> extends Computation<T> {
|
|
25
28
|
_queue: IQueue;
|
|
26
29
|
constructor(initialValue: T, compute: () => T, options?: SignalOptions<T>);
|
|
27
|
-
_notify(state: number): void;
|
|
30
|
+
_notify(state: number, skipQueue?: boolean): void;
|
|
31
|
+
}
|
|
32
|
+
export declare class ProjectionComputation extends Computation {
|
|
33
|
+
_queue: IQueue;
|
|
34
|
+
constructor(compute: () => void);
|
|
35
|
+
_notify(state: number, skipQueue?: boolean): void;
|
|
28
36
|
}
|
|
@@ -6,6 +6,9 @@ export declare class NoOwnerError extends Error {
|
|
|
6
6
|
export declare class ContextNotFoundError extends Error {
|
|
7
7
|
constructor();
|
|
8
8
|
}
|
|
9
|
+
export declare class EffectError extends Error {
|
|
10
|
+
constructor(effect: Function, cause: unknown);
|
|
11
|
+
}
|
|
9
12
|
export interface ErrorHandler {
|
|
10
13
|
(error: unknown): void;
|
|
11
14
|
}
|
|
@@ -5,4 +5,7 @@ export declare const ERROR: unique symbol;
|
|
|
5
5
|
export declare const LOADING_OFFSET = 1;
|
|
6
6
|
export declare const LOADING_BIT: number;
|
|
7
7
|
export declare const LOADING: unique symbol;
|
|
8
|
+
export declare const UNINITIALIZED_OFFSET = 2;
|
|
9
|
+
export declare const UNINITIALIZED_BIT: number;
|
|
10
|
+
export declare const UNINITIALIZED: unique symbol;
|
|
8
11
|
export declare const DEFAULT_FLAGS: number;
|
|
@@ -1,8 +1,8 @@
|
|
|
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, getObserver, isEqual, untrack, hasUpdated,
|
|
3
|
+
export { Computation, getObserver, isEqual, untrack, getClock, hasUpdated, isStale, latest, catchError, UNCHANGED, compute, type SignalOptions } from "./core.js";
|
|
4
4
|
export { Effect, EagerComputation } from "./effect.js";
|
|
5
|
-
export { flushSync, createBoundary,
|
|
5
|
+
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";
|
|
@@ -23,5 +23,4 @@ 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;
|
|
27
26
|
export declare function createBoundary<T>(fn: () => T, queue: IQueue): T;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -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,
|
|
1
|
+
export { Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, createContext, flatten, flushSync, createBoundary, getContext, setContext, hasContext, getOwner, onCleanup, getObserver, isEqual, untrack, hasUpdated, isStale, latest, catchError, createSuspense, SUPPORTS_PROXY } from "./core/index.js";
|
|
2
2
|
export type { ErrorHandler, SignalOptions, Context, ContextRecord, Disposable, IQueue } from "./core/index.js";
|
|
3
|
-
export { mapArray, type Maybe } from "./map.js";
|
|
3
|
+
export { mapArray, repeat, type Maybe } from "./map.js";
|
|
4
4
|
export * from "./signals.js";
|
|
5
5
|
export * from "./store/index.js";
|
package/dist/types/map.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export type Maybe<T> = T | void | null | undefined | false;
|
|
|
3
3
|
/**
|
|
4
4
|
* Reactively transforms an array with a callback function - underlying helper for the `<For>` control flow
|
|
5
5
|
*
|
|
6
|
-
* similar to `Array.prototype.map`, but gets the value and index as
|
|
6
|
+
* similar to `Array.prototype.map`, but gets the value and index as accessors, transforms only values that changed and returns an accessor and reactively tracks changes to the list.
|
|
7
7
|
*
|
|
8
8
|
* @description https://docs.solidjs.com/reference/reactive-utilities/map-array
|
|
9
9
|
*/
|
|
@@ -11,3 +11,11 @@ export declare function mapArray<Item, MappedItem>(list: Accessor<Maybe<readonly
|
|
|
11
11
|
keyed?: boolean | ((item: Item) => any);
|
|
12
12
|
fallback?: Accessor<any>;
|
|
13
13
|
}): Accessor<MappedItem[]>;
|
|
14
|
+
/**
|
|
15
|
+
* Reactively repeats a callback function the count provided - underlying helper for the `<Repeat>` control flow
|
|
16
|
+
*
|
|
17
|
+
* @description https://docs.solidjs.com/reference/reactive-utilities/repeat
|
|
18
|
+
*/
|
|
19
|
+
export declare function repeat(count: Accessor<number>, map: (index: number) => any, options?: {
|
|
20
|
+
fallback?: Accessor<any>;
|
|
21
|
+
}): Accessor<any[]>;
|
package/dist/types/signals.d.ts
CHANGED
|
@@ -87,14 +87,15 @@ export declare function createAsync<T>(compute: (prev?: T) => Promise<T> | Async
|
|
|
87
87
|
* ): void;
|
|
88
88
|
* ```
|
|
89
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
|
|
90
|
+
* @param effect a function that receives the new value and is used to perform side effects, return a cleanup function to run on disposal
|
|
91
|
+
* @param error an optional function that receives an error if thrown during the computation
|
|
91
92
|
* @param value an optional initial value for the computation; if set, fn will never receive undefined as first argument
|
|
92
93
|
* @param options allows to set a name in dev mode for debugging purposes
|
|
93
94
|
*
|
|
94
95
|
* @description https://docs.solidjs.com/reference/basic-reactivity/create-effect
|
|
95
96
|
*/
|
|
96
|
-
export declare function createEffect<Next>(compute: ComputeFunction<undefined | NoInfer<Next>, Next>, effect: EffectFunction<NoInfer<Next>, Next
|
|
97
|
-
export declare function createEffect<Next, Init = Next>(compute: ComputeFunction<Init | Next, Next>, effect: EffectFunction<Next, Next>, value: Init, options?: EffectOptions): void;
|
|
97
|
+
export declare function createEffect<Next>(compute: ComputeFunction<undefined | NoInfer<Next>, Next>, effect: EffectFunction<NoInfer<Next>, Next>, error?: (err: unknown) => void): void;
|
|
98
|
+
export declare function createEffect<Next, Init = Next>(compute: ComputeFunction<Init | Next, Next>, effect: EffectFunction<Next, Next>, error: (err: unknown) => void | undefined, value: Init, options?: EffectOptions): void;
|
|
98
99
|
/**
|
|
99
100
|
* Creates a reactive computation that runs during the render phase as DOM elements are created and updated but not necessarily connected
|
|
100
101
|
* ```typescript
|
|
@@ -139,3 +140,23 @@ export declare function runWithOwner<T>(owner: Owner | null, run: () => T): T |
|
|
|
139
140
|
* @description https://docs.solidjs.com/reference/reactive-utilities/catch-error
|
|
140
141
|
*/
|
|
141
142
|
export declare function createErrorBoundary<T, U>(fn: () => T, fallback: (error: unknown, reset: () => void) => U): Accessor<T | U>;
|
|
143
|
+
/**
|
|
144
|
+
* Returns a promise of the resolved value of a reactive expression
|
|
145
|
+
* @param fn a reactive expression to resolve
|
|
146
|
+
*/
|
|
147
|
+
export declare function resolve<T>(fn: () => T): Promise<T>;
|
|
148
|
+
/**
|
|
149
|
+
* Creates a reactive computation that runs after the render phase with flexible tracking
|
|
150
|
+
* ```typescript
|
|
151
|
+
* export function createReaction(
|
|
152
|
+
* effect: () => void,
|
|
153
|
+
* options?: { name?: string }
|
|
154
|
+
* ): (fn: () => void) => void;
|
|
155
|
+
* ```
|
|
156
|
+
* @param effect a function that is called when tracked function is invalidated.
|
|
157
|
+
* @param error an optional function that receives an error if thrown during tracking
|
|
158
|
+
* @param options allows to set a name in dev mode for debugging purposes
|
|
159
|
+
*
|
|
160
|
+
* @description https://docs.solidjs.com/reference/secondary-primitives/create-reaction
|
|
161
|
+
*/
|
|
162
|
+
export declare function createReaction(effect: () => (() => void) | void, error?: (err: unknown) => (() => void) | void, options?: EffectOptions): (tracking: () => void) => void;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export type { Store, StoreSetter, StoreNode, NotWrappable, SolidStore } from "./store.js";
|
|
2
2
|
export type { Merge, Omit } from "./utilities.js";
|
|
3
|
-
export { unwrap, isWrappable, createStore,
|
|
3
|
+
export { unwrap, isWrappable, createStore, $RAW, $TRACK, $PROXY, $TARGET } from "./store.js";
|
|
4
|
+
export { createProjection } from "./projection.js";
|
|
4
5
|
export { reconcile } from "./reconcile.js";
|
|
5
6
|
export { merge, omit } from "./utilities.js";
|
|
@@ -32,9 +32,3 @@ export declare function isWrappable<T>(obj: T | NotWrappable): obj is T;
|
|
|
32
32
|
export declare function unwrap<T>(item: T, deep?: boolean, set?: Set<unknown>): T;
|
|
33
33
|
export declare function createStore<T extends object = {}>(store: T | Store<T>): [get: Store<T>, set: StoreSetter<T>];
|
|
34
34
|
export declare function createStore<T extends object = {}>(fn: (store: T) => void, store: T | Store<T>): [get: Store<T>, set: StoreSetter<T>];
|
|
35
|
-
/**
|
|
36
|
-
* Creates a mutable derived value
|
|
37
|
-
*
|
|
38
|
-
* @see {@link https://github.com/solidjs/x-reactivity#createprojection}
|
|
39
|
-
*/
|
|
40
|
-
export declare function createProjection<T extends Object>(fn: (draft: T) => void, initialValue?: T): Readonly<T>;
|