@solidjs/signals 0.3.2 → 0.4.0
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 +612 -492
- package/dist/node.cjs +711 -584
- package/dist/prod.js +698 -577
- package/dist/types/{core/boundaries.d.ts → boundaries.d.ts} +6 -3
- package/dist/types/core/core.d.ts +4 -5
- package/dist/types/core/effect.d.ts +4 -3
- package/dist/types/core/error.d.ts +0 -7
- package/dist/types/core/index.d.ts +4 -6
- package/dist/types/core/scheduler.d.ts +7 -7
- package/dist/types/index.d.ts +3 -2
- package/dist/types/signals.d.ts +43 -3
- package/dist/types/store/index.d.ts +2 -2
- package/dist/types/store/projection.d.ts +1 -2
- package/dist/types/store/reconcile.d.ts +1 -1
- package/dist/types/store/store.d.ts +14 -16
- package/dist/types/store/utils.d.ts +7 -0
- package/package.json +1 -1
- package/dist/types/core/utils.d.ts +0 -4
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { Computation } from "./core.js";
|
|
2
|
-
import {
|
|
3
|
-
import { Queue } from "./scheduler.js";
|
|
1
|
+
import { Computation, Queue } from "./core/index.js";
|
|
2
|
+
import type { Effect } from "./core/index.js";
|
|
4
3
|
export declare class CollectionQueue extends Queue {
|
|
5
4
|
_collectionType: number;
|
|
6
5
|
_nodes: Set<Effect>;
|
|
@@ -16,3 +15,7 @@ export declare enum BoundaryMode {
|
|
|
16
15
|
export declare function createBoundary<T>(fn: () => T, condition: () => BoundaryMode): () => T | undefined;
|
|
17
16
|
export declare function createSuspense(fn: () => any, fallback: () => any): () => any;
|
|
18
17
|
export declare function createErrorBoundary<U>(fn: () => any, fallback: (error: unknown, reset: () => void) => U): () => any;
|
|
18
|
+
export declare function flatten(children: any, options?: {
|
|
19
|
+
skipNonRendered?: boolean;
|
|
20
|
+
doNotUnwrap?: boolean;
|
|
21
|
+
}): any;
|
|
@@ -29,8 +29,10 @@
|
|
|
29
29
|
import { type Flags } from "./flags.js";
|
|
30
30
|
import { Owner } from "./owner.js";
|
|
31
31
|
export interface SignalOptions<T> {
|
|
32
|
+
id?: string;
|
|
32
33
|
name?: string;
|
|
33
34
|
equals?: ((prev: T, next: T) => boolean) | false;
|
|
35
|
+
pureWrite?: boolean;
|
|
34
36
|
unobserved?: () => void;
|
|
35
37
|
}
|
|
36
38
|
interface SourceType {
|
|
@@ -62,6 +64,7 @@ export declare class Computation<T = any> extends Owner implements SourceType, O
|
|
|
62
64
|
_name: string | undefined;
|
|
63
65
|
_equals: false | ((a: T, b: T) => boolean);
|
|
64
66
|
_unobserved: (() => void) | undefined;
|
|
67
|
+
_pureWrite: boolean;
|
|
65
68
|
/** Whether the computation is an error or has ancestors that are unresolved */
|
|
66
69
|
_stateFlags: number;
|
|
67
70
|
/** Which flags raised by sources are handled, vs. being passed through. */
|
|
@@ -130,7 +133,7 @@ export declare function untrack<T>(fn: () => T): T;
|
|
|
130
133
|
*/
|
|
131
134
|
export declare function hasUpdated(fn: () => any): boolean;
|
|
132
135
|
/**
|
|
133
|
-
* Returns an accessor that is true if the given function contains async signals are out of date.
|
|
136
|
+
* Returns an accessor that is true if the given function contains async signals that are out of date.
|
|
134
137
|
*/
|
|
135
138
|
export declare function isPending(fn: () => any): boolean;
|
|
136
139
|
export declare function isPending(fn: () => any, loadingValue: boolean): boolean;
|
|
@@ -151,8 +154,4 @@ export declare function runWithObserver<T>(observer: Computation, run: () => T):
|
|
|
151
154
|
*/
|
|
152
155
|
export declare function compute<T>(owner: Owner | null, fn: (val: T) => T, observer: Computation<T>): T;
|
|
153
156
|
export declare function compute<T>(owner: Owner | null, fn: (val: undefined) => T, observer: null): T;
|
|
154
|
-
export declare function flatten(children: any, options?: {
|
|
155
|
-
skipNonRendered?: boolean;
|
|
156
|
-
doNotUnwrap?: boolean;
|
|
157
|
-
}): any;
|
|
158
157
|
export {};
|
|
@@ -7,7 +7,7 @@ import { Computation, type SignalOptions } from "./core.js";
|
|
|
7
7
|
*/
|
|
8
8
|
export declare class Effect<T = any> extends Computation<T> {
|
|
9
9
|
_effect: (val: T, prev: T | undefined) => void | (() => void);
|
|
10
|
-
_onerror: ((err: unknown) => void
|
|
10
|
+
_onerror: ((err: unknown, cleanup: () => void) => void) | undefined;
|
|
11
11
|
_cleanup: (() => void) | undefined;
|
|
12
12
|
_modified: boolean;
|
|
13
13
|
_prevValue: T | undefined;
|
|
@@ -20,7 +20,7 @@ export declare class Effect<T = any> extends Computation<T> {
|
|
|
20
20
|
_notify(state: number, skipQueue?: boolean): void;
|
|
21
21
|
_setError(error: unknown): void;
|
|
22
22
|
_disposeNode(): void;
|
|
23
|
-
_runEffect(): void;
|
|
23
|
+
_runEffect(type: number): void;
|
|
24
24
|
}
|
|
25
25
|
export declare class EagerComputation<T = any> extends Computation<T> {
|
|
26
26
|
constructor(initialValue: T, compute: () => T, options?: SignalOptions<T> & {
|
|
@@ -28,7 +28,8 @@ export declare class EagerComputation<T = any> extends Computation<T> {
|
|
|
28
28
|
});
|
|
29
29
|
_notify(state: number, skipQueue?: boolean): void;
|
|
30
30
|
}
|
|
31
|
-
export declare class
|
|
31
|
+
export declare class FirewallComputation extends Computation {
|
|
32
|
+
firewall: boolean;
|
|
32
33
|
constructor(compute: () => void);
|
|
33
34
|
_notify(state: number, skipQueue?: boolean): void;
|
|
34
35
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Owner } from "./owner.js";
|
|
2
1
|
export declare class NotReadyError extends Error {
|
|
3
2
|
}
|
|
4
3
|
export declare class NoOwnerError extends Error {
|
|
@@ -7,9 +6,3 @@ export declare class NoOwnerError extends Error {
|
|
|
7
6
|
export declare class ContextNotFoundError extends Error {
|
|
8
7
|
constructor();
|
|
9
8
|
}
|
|
10
|
-
export declare class EffectError extends Error {
|
|
11
|
-
constructor(effect: Function, cause: unknown);
|
|
12
|
-
}
|
|
13
|
-
export interface ErrorHandler {
|
|
14
|
-
(error: unknown, node: Owner): void;
|
|
15
|
-
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
export { ContextNotFoundError, NoOwnerError, NotReadyError
|
|
1
|
+
export { ContextNotFoundError, NoOwnerError, NotReadyError } 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, isPending, latest,
|
|
3
|
+
export { Computation, getObserver, isEqual, untrack, hasUpdated, isPending, latest, UNCHANGED, compute, runWithObserver, type SignalOptions } from "./core.js";
|
|
4
4
|
export { Effect, EagerComputation } from "./effect.js";
|
|
5
|
-
export {
|
|
6
|
-
export
|
|
7
|
-
export { SUPPORTS_PROXY } from "./constants.js";
|
|
8
|
-
export { tryCatch, type TryCatchResult } from "./utils.js";
|
|
5
|
+
export { flush, Queue, incrementClock, getClock, type IQueue } from "./scheduler.js";
|
|
6
|
+
export * from "./constants.js";
|
|
9
7
|
export * from "./flags.js";
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import type { Computation } from "./core.js";
|
|
2
|
-
import type { Effect } from "./effect.js";
|
|
3
1
|
export declare function getClock(): number;
|
|
4
2
|
export declare function incrementClock(): void;
|
|
3
|
+
type QueueCallback = (type: number) => void;
|
|
5
4
|
export interface IQueue {
|
|
6
|
-
enqueue
|
|
5
|
+
enqueue(type: number, fn: QueueCallback): void;
|
|
7
6
|
run(type: number): boolean | void;
|
|
8
7
|
flush(): void;
|
|
9
8
|
addChild(child: IQueue): void;
|
|
@@ -15,10 +14,10 @@ export interface IQueue {
|
|
|
15
14
|
export declare class Queue implements IQueue {
|
|
16
15
|
_parent: IQueue | null;
|
|
17
16
|
_running: boolean;
|
|
18
|
-
_queues: [
|
|
17
|
+
_queues: [QueueCallback[], QueueCallback[]];
|
|
19
18
|
_children: IQueue[];
|
|
20
19
|
created: number;
|
|
21
|
-
enqueue
|
|
20
|
+
enqueue(type: number, fn: QueueCallback): void;
|
|
22
21
|
run(type: number): void;
|
|
23
22
|
flush(): void;
|
|
24
23
|
addChild(child: IQueue): void;
|
|
@@ -28,6 +27,7 @@ export declare class Queue implements IQueue {
|
|
|
28
27
|
export declare const globalQueue: Queue;
|
|
29
28
|
/**
|
|
30
29
|
* By default, changes are batched on the microtask queue which is an async process. You can flush
|
|
31
|
-
* the queue synchronously to get the latest updates by calling `
|
|
30
|
+
* the queue synchronously to get the latest updates by calling `flush()`.
|
|
32
31
|
*/
|
|
33
|
-
export declare function
|
|
32
|
+
export declare function flush(): void;
|
|
33
|
+
export {};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export { Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, createContext,
|
|
2
|
-
export type {
|
|
1
|
+
export { Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, createContext, flush, getContext, setContext, hasContext, getOwner, onCleanup, getObserver, isEqual, untrack, hasUpdated, isPending, latest, runWithObserver, SUPPORTS_PROXY } from "./core/index.js";
|
|
2
|
+
export type { SignalOptions, 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";
|
|
6
|
+
export { createSuspense, createErrorBoundary, createBoundary, flatten, type BoundaryMode } from "./boundaries.js";
|
package/dist/types/signals.d.ts
CHANGED
|
@@ -10,6 +10,10 @@ export type Setter<in out T> = {
|
|
|
10
10
|
export type Signal<T> = [get: Accessor<T>, set: Setter<T>];
|
|
11
11
|
export type ComputeFunction<Prev, Next extends Prev = Prev> = (v: Prev) => Next;
|
|
12
12
|
export type EffectFunction<Prev, Next extends Prev = Prev> = (v: Next, p?: Prev) => (() => void) | void;
|
|
13
|
+
export type EffectBundle<Prev, Next extends Prev = Prev> = {
|
|
14
|
+
effect: EffectFunction<Prev, Next>;
|
|
15
|
+
error: (err: unknown, cleanup: () => void) => void;
|
|
16
|
+
};
|
|
13
17
|
export interface EffectOptions {
|
|
14
18
|
name?: string;
|
|
15
19
|
defer?: boolean;
|
|
@@ -77,7 +81,9 @@ export declare function createMemo<Next extends Prev, Init = Next, Prev = Next>(
|
|
|
77
81
|
*
|
|
78
82
|
* @description https://docs.solidjs.com/reference/basic-reactivity/create-async
|
|
79
83
|
*/
|
|
80
|
-
export declare function createAsync<T>(compute: (prev
|
|
84
|
+
export declare function createAsync<T>(compute: (prev: T | undefined, refreshing: boolean) => Promise<T> | AsyncIterable<T> | T, value?: T, options?: MemoOptions<T>): Accessor<T> & {
|
|
85
|
+
refresh: () => void;
|
|
86
|
+
};
|
|
81
87
|
/**
|
|
82
88
|
* Creates a reactive effect that runs after the render phase
|
|
83
89
|
* ```typescript
|
|
@@ -96,8 +102,8 @@ export declare function createAsync<T>(compute: (prev?: T) => Promise<T> | Async
|
|
|
96
102
|
*
|
|
97
103
|
* @description https://docs.solidjs.com/reference/basic-reactivity/create-effect
|
|
98
104
|
*/
|
|
99
|
-
export declare function createEffect<Next>(compute: ComputeFunction<undefined | NoInfer<Next>, Next>, effect: EffectFunction<NoInfer<Next>, Next
|
|
100
|
-
export declare function createEffect<Next, Init = Next>(compute: ComputeFunction<Init | Next, Next>, effect: EffectFunction<Next, Next
|
|
105
|
+
export declare function createEffect<Next>(compute: ComputeFunction<undefined | NoInfer<Next>, Next>, effect: EffectFunction<NoInfer<Next>, Next> | EffectBundle<NoInfer<Next>, Next>): void;
|
|
106
|
+
export declare function createEffect<Next, Init = Next>(compute: ComputeFunction<Init | Next, Next>, effect: EffectFunction<Next, Next> | EffectBundle<Next, Next>, value: Init, options?: EffectOptions): void;
|
|
101
107
|
/**
|
|
102
108
|
* Creates a reactive computation that runs during the render phase as DOM elements are created and updated but not necessarily connected
|
|
103
109
|
* ```typescript
|
|
@@ -140,3 +146,37 @@ export declare function runWithOwner<T>(owner: Owner | null, run: () => T): T;
|
|
|
140
146
|
* @param fn a reactive expression to resolve
|
|
141
147
|
*/
|
|
142
148
|
export declare function resolve<T>(fn: () => T): Promise<T>;
|
|
149
|
+
/**
|
|
150
|
+
* Runs the given function and returns a tuple with the result or an error.
|
|
151
|
+
* If the function throws an error, it will be caught and returned as the first element of the tuple.
|
|
152
|
+
* If the function returns a promise, it will resolve to a tuple with the result or an error.
|
|
153
|
+
*
|
|
154
|
+
* @param fn The function to run.
|
|
155
|
+
* @returns A tuple with either [undefined, result] or [error].
|
|
156
|
+
*
|
|
157
|
+
* @description https://docs.solidjs.com/reference/reactive-utilities/try-catch
|
|
158
|
+
*/
|
|
159
|
+
export type TryCatchResult<T, E> = [undefined, T] | [E];
|
|
160
|
+
export declare function tryCatch<T, E = Error>(fn: () => Promise<T>): Promise<TryCatchResult<T, E>>;
|
|
161
|
+
export declare function tryCatch<T, E = Error>(fn: () => T): TryCatchResult<T, E>;
|
|
162
|
+
/**
|
|
163
|
+
* Runs the given function in a transition scope, allowing for batch updates and optimizations.
|
|
164
|
+
* This is useful for grouping multiple state updates together to avoid unnecessary re-renders.
|
|
165
|
+
*
|
|
166
|
+
* @param fn A function that receives a resume function to continue the transition.
|
|
167
|
+
* The resume function can be called with another function to continue the transition.
|
|
168
|
+
*
|
|
169
|
+
* @description https://docs.solidjs.com/reference/advanced-reactivity/transition
|
|
170
|
+
*/
|
|
171
|
+
export declare function transition(fn: (resume: (fn: () => any | Promise<any>) => void) => any | Promise<any>): void;
|
|
172
|
+
/**
|
|
173
|
+
* Creates an optimistic signal that can be used to optimistically update a value
|
|
174
|
+
* and then revert it back to the previous value at end of transition.
|
|
175
|
+
*
|
|
176
|
+
* @param initial The initial value of the signal.
|
|
177
|
+
* @param compute An optional function to compute the next value based on the previous value and change.
|
|
178
|
+
* @param options Optional signal options.
|
|
179
|
+
*
|
|
180
|
+
* @returns A tuple containing an accessor for the current value and a setter function to apply changes.
|
|
181
|
+
*/
|
|
182
|
+
export declare function createOptimistic<T, U>(initial: T, compute?: (prev: T, change: U) => void, options?: SignalOptions<T>): [Accessor<T>, (v: U) => void];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type { Store, StoreSetter, StoreNode, NotWrappable, SolidStore } from "./store.js";
|
|
2
2
|
export type { Merge, Omit } from "./utils.js";
|
|
3
|
-
export {
|
|
3
|
+
export { isWrappable, createStore, deep, $TRACK, $PROXY, $TARGET } from "./store.js";
|
|
4
4
|
export { createProjection } from "./projection.js";
|
|
5
5
|
export { reconcile } from "./reconcile.js";
|
|
6
|
-
export { merge, omit } from "./utils.js";
|
|
6
|
+
export { snapshot, merge, omit } from "./utils.js";
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { type Store
|
|
1
|
+
import { type Store } from "./store.js";
|
|
2
2
|
/**
|
|
3
3
|
* Creates a mutable derived value
|
|
4
4
|
*
|
|
5
5
|
* @see {@link https://github.com/solidjs/x-reactivity#createprojection}
|
|
6
6
|
*/
|
|
7
7
|
export declare function createProjection<T extends Object>(fn: (draft: T) => void, initialValue?: T): Store<T>;
|
|
8
|
-
export declare function wrapProjection<T>(fn: (draft: T) => void, store: Store<T>, setStore: StoreSetter<T>): [Store<T>, StoreSetter<T>];
|
|
@@ -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), all?: boolean): (state: U) => void;
|
|
@@ -3,33 +3,31 @@ export type Store<T> = Readonly<T>;
|
|
|
3
3
|
export type StoreSetter<T> = (fn: (state: T) => void) => void;
|
|
4
4
|
type DataNode = Computation<any>;
|
|
5
5
|
type DataNodes = Record<PropertyKey, DataNode>;
|
|
6
|
-
declare const $
|
|
7
|
-
export declare const STORE_VALUE = "v", STORE_NODE = "n", STORE_HAS = "h";
|
|
8
|
-
export { $PROXY, $TRACK, $RAW, $TARGET };
|
|
6
|
+
export declare const $TRACK: unique symbol, $DEEP: unique symbol, $TARGET: unique symbol, $PROXY: unique symbol, $DELETED: unique symbol;
|
|
7
|
+
export declare const STORE_VALUE = "v", STORE_OVERRIDE = "o", STORE_NODE = "n", STORE_HAS = "h", STORE_WRAP = "w", STORE_LOOKUP = "l";
|
|
9
8
|
export type StoreNode = {
|
|
9
|
+
[$PROXY]: any;
|
|
10
10
|
[STORE_VALUE]: Record<PropertyKey, any>;
|
|
11
|
+
[STORE_OVERRIDE]?: Record<PropertyKey, any>;
|
|
11
12
|
[STORE_NODE]?: DataNodes;
|
|
12
13
|
[STORE_HAS]?: DataNodes;
|
|
14
|
+
[STORE_WRAP]?: (value: any, target?: StoreNode) => any;
|
|
15
|
+
[STORE_LOOKUP]?: WeakMap<any, any>;
|
|
13
16
|
};
|
|
14
17
|
export declare namespace SolidStore {
|
|
15
18
|
interface Unwrappable {
|
|
16
19
|
}
|
|
17
20
|
}
|
|
18
21
|
export type NotWrappable = string | number | bigint | symbol | boolean | Function | null | undefined | SolidStore.Unwrappable[keyof SolidStore.Unwrappable];
|
|
19
|
-
export declare function
|
|
22
|
+
export declare function createStoreProxy<T extends object>(value: T, traps?: ProxyHandler<StoreNode>, extend?: Record<PropertyKey, any>): any;
|
|
23
|
+
export declare const storeLookup: WeakMap<object, any>;
|
|
24
|
+
export declare function wrap<T extends Record<PropertyKey, any>>(value: T, target?: StoreNode): T;
|
|
20
25
|
export declare function isWrappable<T>(obj: T | NotWrappable): obj is T;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
* ```js
|
|
26
|
-
* const initial = {z...};
|
|
27
|
-
* const [state, setState] = createStore(initial);
|
|
28
|
-
* initial === state; // => false
|
|
29
|
-
* initial === unwrap(state); // => true
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
export declare function unwrap<T>(item: T, deep?: boolean, set?: Set<unknown>): T;
|
|
26
|
+
export declare function getKeys(source: Record<PropertyKey, any>, override: Record<PropertyKey, any> | undefined, enumerable?: boolean): PropertyKey[];
|
|
27
|
+
export declare function getPropertyDescriptor(source: Record<PropertyKey, any>, override: Record<PropertyKey, any> | undefined, property: PropertyKey): PropertyDescriptor | undefined;
|
|
28
|
+
export declare const storeTraps: ProxyHandler<StoreNode>;
|
|
29
|
+
export declare function storeSetter<T extends object>(store: Store<T>, fn: (draft: T) => void): void;
|
|
33
30
|
export declare function createStore<T extends object = {}>(store: T | Store<T>): [get: Store<T>, set: StoreSetter<T>];
|
|
34
31
|
export declare function createStore<T extends object = {}>(fn: (store: T) => void, store: T | Store<T>): [get: Store<T>, set: StoreSetter<T>];
|
|
35
32
|
export declare function deep<T extends object>(store: Store<T>): Store<any>;
|
|
33
|
+
export {};
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a non reactive copy of the store object.
|
|
3
|
+
* It will attempt to preserver the original reference unless the value has been modified.
|
|
4
|
+
* @param item store proxy object
|
|
5
|
+
*/
|
|
6
|
+
export declare function snapshot<T>(item: T): T;
|
|
7
|
+
export declare function snapshot<T>(item: T, map?: Map<unknown, unknown>, lookup?: WeakMap<any, any>): T;
|
|
1
8
|
type DistributeOverride<T, F> = T extends undefined ? F : T;
|
|
2
9
|
type Override<T, U> = T extends any ? U extends any ? {
|
|
3
10
|
[K in keyof T]: K extends keyof U ? DistributeOverride<U[K], T[K]> : T[K];
|
package/package.json
CHANGED
|
@@ -1,4 +0,0 @@
|
|
|
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>;
|