@solidjs/signals 2.0.0-beta.14 → 2.0.0-beta.16
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/README.md +2 -3
- package/dist/dev.js +966 -550
- package/dist/node.cjs +2153 -1821
- package/dist/prod.js +1848 -1530
- package/dist/types/boundaries.d.ts +3 -3
- package/dist/types/core/async.d.ts +1 -0
- package/dist/types/core/core.d.ts +27 -15
- package/dist/types/core/dev.d.ts +10 -2
- package/dist/types/core/effect.d.ts +1 -3
- package/dist/types/core/graph.d.ts +1 -1
- package/dist/types/core/index.d.ts +2 -2
- package/dist/types/core/invariants.d.ts +49 -0
- package/dist/types/core/scheduler.d.ts +8 -0
- package/dist/types/core/types.d.ts +19 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/signals.d.ts +39 -2
- package/dist/types/store/projection.d.ts +4 -4
- package/dist/types/store/store.d.ts +29 -1
- package/dist/types-cjs/boundaries.d.cts +3 -3
- package/dist/types-cjs/core/async.d.cts +1 -0
- package/dist/types-cjs/core/core.d.cts +27 -15
- package/dist/types-cjs/core/dev.d.cts +10 -2
- package/dist/types-cjs/core/effect.d.cts +1 -3
- package/dist/types-cjs/core/graph.d.cts +1 -1
- package/dist/types-cjs/core/index.d.cts +2 -2
- package/dist/types-cjs/core/invariants.d.cts +49 -0
- package/dist/types-cjs/core/scheduler.d.cts +8 -0
- package/dist/types-cjs/core/types.d.cts +19 -0
- package/dist/types-cjs/index.d.cts +1 -1
- package/dist/types-cjs/signals.d.cts +39 -2
- package/dist/types-cjs/store/projection.d.cts +4 -4
- package/dist/types-cjs/store/store.d.cts +29 -1
- package/package.json +1 -1
- package/dist/types/src/boundaries.d.ts +0 -173
- package/dist/types/src/core/action.d.ts +0 -35
- package/dist/types/src/core/async.d.ts +0 -6
- package/dist/types/src/core/constants.d.ts +0 -51
- package/dist/types/src/core/context.d.ts +0 -36
- package/dist/types/src/core/core.d.ts +0 -174
- package/dist/types/src/core/dev.d.ts +0 -49
- package/dist/types/src/core/effect.d.ts +0 -32
- package/dist/types/src/core/error.d.ts +0 -38
- package/dist/types/src/core/external.d.ts +0 -45
- package/dist/types/src/core/graph.d.ts +0 -5
- package/dist/types/src/core/heap.d.ts +0 -14
- package/dist/types/src/core/index.d.ts +0 -12
- package/dist/types/src/core/lanes.d.ts +0 -54
- package/dist/types/src/core/owner.d.ts +0 -116
- package/dist/types/src/core/scheduler.d.ts +0 -122
- package/dist/types/src/core/types.d.ts +0 -85
- package/dist/types/src/index.d.ts +0 -9
- package/dist/types/src/map.d.ts +0 -53
- package/dist/types/src/signals.d.ts +0 -512
- package/dist/types/src/store/index.d.ts +0 -9
- package/dist/types/src/store/optimistic.d.ts +0 -45
- package/dist/types/src/store/projection.d.ts +0 -66
- package/dist/types/src/store/reconcile.d.ts +0 -23
- package/dist/types/src/store/store.d.ts +0 -125
- package/dist/types/src/store/storePath.d.ts +0 -58
- package/dist/types/src/store/utils.d.ts +0 -114
- package/dist/types-cjs/src/boundaries.d.cts +0 -173
- package/dist/types-cjs/src/core/action.d.cts +0 -35
- package/dist/types-cjs/src/core/async.d.cts +0 -6
- package/dist/types-cjs/src/core/constants.d.cts +0 -51
- package/dist/types-cjs/src/core/context.d.cts +0 -36
- package/dist/types-cjs/src/core/core.d.cts +0 -174
- package/dist/types-cjs/src/core/dev.d.cts +0 -49
- package/dist/types-cjs/src/core/effect.d.cts +0 -32
- package/dist/types-cjs/src/core/error.d.cts +0 -38
- package/dist/types-cjs/src/core/external.d.cts +0 -45
- package/dist/types-cjs/src/core/graph.d.cts +0 -5
- package/dist/types-cjs/src/core/heap.d.cts +0 -14
- package/dist/types-cjs/src/core/index.d.cts +0 -12
- package/dist/types-cjs/src/core/lanes.d.cts +0 -54
- package/dist/types-cjs/src/core/owner.d.cts +0 -116
- package/dist/types-cjs/src/core/scheduler.d.cts +0 -122
- package/dist/types-cjs/src/core/types.d.cts +0 -85
- package/dist/types-cjs/src/index.d.cts +0 -9
- package/dist/types-cjs/src/map.d.cts +0 -53
- package/dist/types-cjs/src/signals.d.cts +0 -512
- package/dist/types-cjs/src/store/index.d.cts +0 -9
- package/dist/types-cjs/src/store/optimistic.d.cts +0 -45
- package/dist/types-cjs/src/store/projection.d.cts +0 -66
- package/dist/types-cjs/src/store/reconcile.d.cts +0 -23
- package/dist/types-cjs/src/store/store.d.cts +0 -125
- package/dist/types-cjs/src/store/storePath.d.cts +0 -58
- package/dist/types-cjs/src/store/utils.d.cts +0 -114
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import type { NOT_PENDING } from "./constants.js";
|
|
2
|
-
import type { OptimisticLane } from "./lanes.js";
|
|
3
|
-
import type { IQueue, Transition } from "./scheduler.js";
|
|
4
|
-
export interface Disposable {
|
|
5
|
-
(): void;
|
|
6
|
-
}
|
|
7
|
-
export interface Link {
|
|
8
|
-
_dep: Signal<unknown> | Computed<unknown>;
|
|
9
|
-
_sub: Computed<unknown>;
|
|
10
|
-
_nextDep: Link | null;
|
|
11
|
-
_prevSub: Link | null;
|
|
12
|
-
_nextSub: Link | null;
|
|
13
|
-
}
|
|
14
|
-
export interface NodeOptions<T> {
|
|
15
|
-
id?: string;
|
|
16
|
-
name?: string;
|
|
17
|
-
transparent?: boolean;
|
|
18
|
-
equals?: ((prev: T, next: T) => boolean) | false;
|
|
19
|
-
ownedWrite?: boolean;
|
|
20
|
-
/** Exclude this signal from snapshot capture (internal — not part of public API) */
|
|
21
|
-
_noSnapshot?: boolean;
|
|
22
|
-
unobserved?: () => void;
|
|
23
|
-
lazy?: boolean;
|
|
24
|
-
sync?: boolean;
|
|
25
|
-
}
|
|
26
|
-
export interface RawSignal<T> {
|
|
27
|
-
_subs: Link | null;
|
|
28
|
-
_subsTail: Link | null;
|
|
29
|
-
_value: T;
|
|
30
|
-
_snapshotValue?: any;
|
|
31
|
-
_name?: string;
|
|
32
|
-
_equals: false | ((a: T, b: T) => boolean);
|
|
33
|
-
_config: number;
|
|
34
|
-
_unobserved?: () => void;
|
|
35
|
-
_time: number;
|
|
36
|
-
_transition: Transition | null;
|
|
37
|
-
_pendingValue: T | typeof NOT_PENDING;
|
|
38
|
-
_overrideValue?: T | typeof NOT_PENDING;
|
|
39
|
-
_optimisticLane?: OptimisticLane;
|
|
40
|
-
_pendingSignal?: Signal<boolean>;
|
|
41
|
-
_latestValueComputed?: Computed<T>;
|
|
42
|
-
_parentSource?: Signal<any> | Computed<any>;
|
|
43
|
-
}
|
|
44
|
-
export interface FirewallSignal<T> extends RawSignal<T> {
|
|
45
|
-
_firewall: Computed<any>;
|
|
46
|
-
_nextChild: FirewallSignal<unknown> | null;
|
|
47
|
-
}
|
|
48
|
-
export type Signal<T> = RawSignal<T> | FirewallSignal<T>;
|
|
49
|
-
export interface Owner {
|
|
50
|
-
id?: string;
|
|
51
|
-
_config: number;
|
|
52
|
-
_snapshotScope?: boolean;
|
|
53
|
-
_disposal: Disposable | Disposable[] | null;
|
|
54
|
-
_parent: Owner | null;
|
|
55
|
-
_context: Record<symbol | string, unknown>;
|
|
56
|
-
_childCount: number;
|
|
57
|
-
_queue: IQueue;
|
|
58
|
-
_firstChild: Owner | null;
|
|
59
|
-
_nextSibling: Owner | null;
|
|
60
|
-
_prevSibling: Owner | null;
|
|
61
|
-
_pendingDisposal: Disposable | Disposable[] | null;
|
|
62
|
-
_pendingFirstChild: Owner | null;
|
|
63
|
-
}
|
|
64
|
-
export interface Computed<T> extends RawSignal<T>, Owner {
|
|
65
|
-
_deps: Link | null;
|
|
66
|
-
_depsTail: Link | null;
|
|
67
|
-
_flags: number;
|
|
68
|
-
_blocked?: boolean;
|
|
69
|
-
_pendingSource?: Computed<any>;
|
|
70
|
-
_pendingSources?: Set<Computed<any>>;
|
|
71
|
-
_error?: unknown;
|
|
72
|
-
_statusFlags: number;
|
|
73
|
-
_height: number;
|
|
74
|
-
_nextHeap: Computed<any> | undefined;
|
|
75
|
-
_prevHeap: Computed<any>;
|
|
76
|
-
_fn: (prev?: T) => T;
|
|
77
|
-
_inFlight: PromiseLike<T> | AsyncIterable<T> | null;
|
|
78
|
-
_child: FirewallSignal<any> | null;
|
|
79
|
-
_notifyStatus?: (status?: number, error?: any) => void;
|
|
80
|
-
}
|
|
81
|
-
export interface Root extends Owner {
|
|
82
|
-
_root: true;
|
|
83
|
-
_parentComputed: Computed<any> | null;
|
|
84
|
-
dispose(self?: boolean): void;
|
|
85
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export { $REFRESH, ContextNotFoundError, NoOwnerError, NotReadyError, action, createContext, createOwner, createRoot, runWithOwner, flush, getNextChildId, peekNextChildId, getContext, setContext, getOwner, isDisposed, getObserver, isEqual, untrack, isPending, latest, isRefreshing, refresh, SUPPORTS_PROXY, setSnapshotCapture, markSnapshotScope, releaseSnapshotScope, clearSnapshots, enforceLoadingBoundary, enableExternalSource } from "./core/index.js";
|
|
2
|
-
import { type Dev } from "./core/index.js";
|
|
3
|
-
export declare const DEV: Dev | undefined;
|
|
4
|
-
export type { Owner, Context, ContextRecord, IQueue, ExternalSourceFactory, ExternalSource, ExternalSourceConfig, Refreshable, Dev, DevHooks, DiagnosticCapture, DiagnosticCode, DiagnosticEvent, DiagnosticKind, Diagnostics, DiagnosticSeverity } from "./core/index.js";
|
|
5
|
-
export { createSignal, createMemo, createEffect, createRenderEffect, createTrackedEffect, createReaction, createOptimistic, resolve, onSettled, onCleanup } from "./signals.js";
|
|
6
|
-
export type { Accessor, SourceAccessor, Setter, Signal, ComputeFunction, EffectFunction, EffectBundle, EffectOptions, SignalOptions, MemoOptions, NoInfer } from "./signals.js";
|
|
7
|
-
export { mapArray, repeat, type Maybe } from "./map.js";
|
|
8
|
-
export * from "./store/index.js";
|
|
9
|
-
export { createLoadingBoundary, createErrorBoundary, createRevealOrder, flatten, type RevealOrder } from "./boundaries.js";
|
package/dist/types/src/map.d.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { type Accessor } from "./signals.js";
|
|
2
|
-
export type Maybe<T> = T | void | null | undefined | false;
|
|
3
|
-
/**
|
|
4
|
-
* Reactively maps an array, reusing the previously-mapped value for unchanged
|
|
5
|
-
* items. The callback receives `(value, index)` as accessors so individual
|
|
6
|
-
* items and indexes can be subscribed to without re-running the mapper.
|
|
7
|
-
*
|
|
8
|
-
* This is the underlying helper that powers `<For>`. App code should use
|
|
9
|
-
* `<For>` directly; reach for `mapArray` when implementing custom list
|
|
10
|
-
* components.
|
|
11
|
-
*
|
|
12
|
-
* - `options.keyed` — `true` (default for primitives) compares by identity;
|
|
13
|
-
* `false` falls back to index-only mapping; pass a function `(item) => key`
|
|
14
|
-
* for stable identity by extracted key.
|
|
15
|
-
* - `options.fallback` — accessor returning a value to show when the input is
|
|
16
|
-
* empty.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```ts
|
|
20
|
-
* const view = mapArray(
|
|
21
|
-
* items,
|
|
22
|
-
* (item, index) => `${index()}: ${item().label}`,
|
|
23
|
-
* { fallback: () => "no items" }
|
|
24
|
-
* );
|
|
25
|
-
* ```
|
|
26
|
-
*
|
|
27
|
-
* @description https://docs.solidjs.com/reference/reactive-utilities/map-array
|
|
28
|
-
*/
|
|
29
|
-
export declare function mapArray<Item, MappedItem>(list: Accessor<Maybe<readonly Item[]>>, map: (value: Accessor<Item>, index: Accessor<number>) => MappedItem, options?: {
|
|
30
|
-
keyed?: boolean | ((item: Item) => any);
|
|
31
|
-
fallback?: Accessor<any>;
|
|
32
|
-
name?: string;
|
|
33
|
-
}): Accessor<MappedItem[]>;
|
|
34
|
-
/**
|
|
35
|
-
* Reactively renders a callback `count` times, reusing previously-rendered
|
|
36
|
-
* entries when only the count changes. Underlying helper for `<Repeat>`.
|
|
37
|
-
*
|
|
38
|
-
* - `options.from` — start index (default `0`); useful for offset/windowed
|
|
39
|
-
* rendering.
|
|
40
|
-
* - `options.fallback` — accessor returning a value to show when count is `0`.
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* ```ts
|
|
44
|
-
* const view = repeat(count, i => `Item ${i}`, { fallback: () => "empty" });
|
|
45
|
-
* ```
|
|
46
|
-
*
|
|
47
|
-
* @description https://docs.solidjs.com/reference/reactive-utilities/repeat
|
|
48
|
-
*/
|
|
49
|
-
export declare function repeat(count: Accessor<number>, map: (index: number) => any, options?: {
|
|
50
|
-
from?: Accessor<number | undefined>;
|
|
51
|
-
fallback?: Accessor<any>;
|
|
52
|
-
name?: string;
|
|
53
|
-
}): Accessor<any[]>;
|
|
@@ -1,512 +0,0 @@
|
|
|
1
|
-
import type { Disposable, Refreshable } from "./core/index.js";
|
|
2
|
-
/**
|
|
3
|
-
* Low-level reactive-cleanup primitive. Registers a callback that runs when
|
|
4
|
-
* the surrounding owner is disposed.
|
|
5
|
-
*
|
|
6
|
-
* **In 2.0 user code this is rare.** The two cases where you might reach for
|
|
7
|
-
* it have better-shaped tools:
|
|
8
|
-
*
|
|
9
|
-
* - **Component lifecycle (mount/unmount, listeners, intervals):** use
|
|
10
|
-
* {@link onSettled} and **return** a cleanup function. Setup and teardown
|
|
11
|
-
* stay paired in one block. This replaces the 1.x `onMount` + `onCleanup`
|
|
12
|
-
* pairing.
|
|
13
|
-
* - **Cleanup tied to an effect run:** `onCleanup` does not belong in
|
|
14
|
-
* `createEffect`'s apply phase. If a compute phase genuinely needs per-run
|
|
15
|
-
* teardown, that's usually a sign the work should be a memo/projection
|
|
16
|
-
* instead, or moved to `onSettled` if it's lifecycle-shaped.
|
|
17
|
-
*
|
|
18
|
-
* Where `onCleanup` is the right tool is **library / custom-primitive
|
|
19
|
-
* internals** — coordinating disposal inside a `createRoot` body, or wiring
|
|
20
|
-
* cleanup to a captured owner via `runWithOwner` from a custom factory.
|
|
21
|
-
* Application code rarely needs to write any of those shapes directly.
|
|
22
|
-
*
|
|
23
|
-
* Must be called inside an owner. Calling outside an owner is a no-op (with a
|
|
24
|
-
* dev-mode warning).
|
|
25
|
-
*
|
|
26
|
-
* Cannot be used inside `createTrackedEffect` or `onSettled` — return a
|
|
27
|
-
* cleanup function from the callback body instead.
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* ```ts
|
|
31
|
-
* // Library shape: thread a resource's disposal into a *captured* owner
|
|
32
|
-
* // from a factory that has no settle-phase setup of its own. `onSettled`
|
|
33
|
-
* // would queue a callback we don't need; `onCleanup` is the leaner
|
|
34
|
-
* // primitive when the only job is "register disposal on this owner".
|
|
35
|
-
* function bindToOwner<T extends { dispose(): void }>(owner: Owner, resource: T): T {
|
|
36
|
-
* runWithOwner(owner, () => onCleanup(() => resource.dispose()));
|
|
37
|
-
* return resource;
|
|
38
|
-
* }
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
export declare function onCleanup(fn: Disposable): Disposable;
|
|
42
|
-
/**
|
|
43
|
-
* A zero-arg getter for a reactive value. Calling it inside a tracking scope
|
|
44
|
-
* (memo, effect compute, JSX expression) subscribes the scope to changes.
|
|
45
|
-
*
|
|
46
|
-
* Reading outside any tracking scope simply returns the current value without
|
|
47
|
-
* creating a subscription.
|
|
48
|
-
*/
|
|
49
|
-
export type Accessor<T> = () => T;
|
|
50
|
-
export type SourceAccessor<T> = Refreshable<Accessor<T>>;
|
|
51
|
-
export declare function accessor<T>(node: any): SourceAccessor<T>;
|
|
52
|
-
/**
|
|
53
|
-
* A signal setter. Accepts either a new value or an updater `(prev) => next`.
|
|
54
|
-
*
|
|
55
|
-
* If the type permits `undefined`, `setState()` (no args) clears to `undefined`.
|
|
56
|
-
*
|
|
57
|
-
* To store a function as the value itself (rather than as an updater), wrap it
|
|
58
|
-
* with an updater: `setHandler(() => myHandler)`.
|
|
59
|
-
*/
|
|
60
|
-
export type Setter<in out T> = {
|
|
61
|
-
<U extends T>(...args: undefined extends T ? [] : [value: Exclude<U, Function> | ((prev: T) => U)]): undefined extends T ? undefined : U;
|
|
62
|
-
<U extends T>(value: (prev: T) => U): U;
|
|
63
|
-
<U extends T>(value: Exclude<U, Function>): U;
|
|
64
|
-
<U extends T>(value: Exclude<U, Function> | ((prev: T) => U)): U;
|
|
65
|
-
};
|
|
66
|
-
/** A `[get, set]` pair returned from `createSignal` / `createOptimistic`. */
|
|
67
|
-
export type Signal<T> = [get: SourceAccessor<T>, set: Setter<T>];
|
|
68
|
-
export type ComputeFunction<Prev, Next extends Prev = Prev> = (v: Prev) => PromiseLike<Next> | AsyncIterable<Next> | Next;
|
|
69
|
-
export type EffectFunction<Prev, Next extends Prev = Prev> = (v: Next, p?: Prev) => (() => void) | void;
|
|
70
|
-
export type EffectBundle<Prev, Next extends Prev = Prev> = {
|
|
71
|
-
effect: EffectFunction<Prev, Next>;
|
|
72
|
-
error: (err: unknown, cleanup: () => void) => void;
|
|
73
|
-
};
|
|
74
|
-
/** Options shared by every effect primitive. */
|
|
75
|
-
interface BaseEffectOptions {
|
|
76
|
-
/** Debug name (dev mode only) */
|
|
77
|
-
name?: string;
|
|
78
|
-
}
|
|
79
|
-
/** Options for effect primitives that support deferring/scheduling their initial run (`createEffect`, `createRenderEffect`, `createReaction`). */
|
|
80
|
-
export interface EffectOptions extends BaseEffectOptions {
|
|
81
|
-
/** When true, defers the initial effect execution until the next change */
|
|
82
|
-
defer?: boolean;
|
|
83
|
-
/**
|
|
84
|
-
* When true, enqueues the initial effect callback through the effect queue instead of running
|
|
85
|
-
* it synchronously at creation. Lets the initial run participate in transitions -- if any
|
|
86
|
-
* source throws `NotReadyError` during the compute phase, the callback is held until the
|
|
87
|
-
* transition settles.
|
|
88
|
-
*
|
|
89
|
-
* Primarily for render effects that need transition-aware initial mounts (e.g. the root
|
|
90
|
-
* `insert()` in `render()`).
|
|
91
|
-
*/
|
|
92
|
-
schedule?: boolean;
|
|
93
|
-
/**
|
|
94
|
-
* Advanced. When true, asserts the compute function returns synchronous
|
|
95
|
-
* values only (never `PromiseLike` / `AsyncIterable`). Skips the
|
|
96
|
-
* async-shape probe in `recompute` for a small fixed-cost win per run.
|
|
97
|
-
* Intended for compiler emissions (`_$effect`) and library code that
|
|
98
|
-
* provably returns sync values. Returning a Promise or async iterable
|
|
99
|
-
* from a `sync: true` effect is undefined behavior — the value will be
|
|
100
|
-
* stored as-is and never awaited.
|
|
101
|
-
*/
|
|
102
|
-
sync?: boolean;
|
|
103
|
-
}
|
|
104
|
-
/** Options for plain signals created with `createSignal(value)` or `createOptimistic(value)`. */
|
|
105
|
-
export interface SignalOptions<T> {
|
|
106
|
-
/** Debug name (dev mode only) */
|
|
107
|
-
name?: string;
|
|
108
|
-
/**
|
|
109
|
-
* Custom equality function, or `false` to always notify subscribers.
|
|
110
|
-
* Defaults to reference equality (`isEqual`). Pass a comparator (e.g.
|
|
111
|
-
* `(a, b) => a.id === b.id`) for value-based equality, or `false` to
|
|
112
|
-
* notify on every write regardless of equality.
|
|
113
|
-
*/
|
|
114
|
-
equals?: false | ((prev: T, next: T) => boolean);
|
|
115
|
-
/** Suppress dev-mode warnings when writing inside an owned scope */
|
|
116
|
-
ownedWrite?: boolean;
|
|
117
|
-
/** Callback invoked when the signal loses all subscribers */
|
|
118
|
-
unobserved?: () => void;
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Options for read-only memos created with `createMemo`.
|
|
122
|
-
* Also used in combination with `SignalOptions` for writable memos
|
|
123
|
-
* (`createSignal(fn)` / `createOptimistic(fn)`).
|
|
124
|
-
*/
|
|
125
|
-
export interface MemoOptions<T> {
|
|
126
|
-
/** Stable identifier for the owner hierarchy */
|
|
127
|
-
id?: string;
|
|
128
|
-
/** Debug name (dev mode only) */
|
|
129
|
-
name?: string;
|
|
130
|
-
/** When true, the owner is invisible to the ID scheme -- inherits parent ID and doesn't consume a childCount slot */
|
|
131
|
-
transparent?: boolean;
|
|
132
|
-
/**
|
|
133
|
-
* Custom equality function, or `false` to always notify subscribers.
|
|
134
|
-
* Defaults to reference equality (`isEqual`). Pass a comparator (e.g.
|
|
135
|
-
* `(a, b) => a.id === b.id`) for value-based equality, or `false` to
|
|
136
|
-
* notify on every recompute regardless of equality.
|
|
137
|
-
*/
|
|
138
|
-
equals?: false | ((prev: T, next: T) => boolean);
|
|
139
|
-
/** Callback invoked when the computed loses all subscribers */
|
|
140
|
-
unobserved?: () => void;
|
|
141
|
-
/**
|
|
142
|
-
* When true, defers the initial computation until the value is first read,
|
|
143
|
-
* **and** opts the memo into autodisposal — once it has no remaining
|
|
144
|
-
* subscribers it is torn down and recomputed from scratch on the next read.
|
|
145
|
-
* Use it for compute-on-demand values that should not retain state across
|
|
146
|
-
* idle periods. Non-lazy owned memos live for their owner's lifetime and
|
|
147
|
-
* never autodispose.
|
|
148
|
-
*/
|
|
149
|
-
lazy?: boolean;
|
|
150
|
-
/**
|
|
151
|
-
* Advanced. When true, asserts the compute function returns synchronous
|
|
152
|
-
* values only (never `PromiseLike` / `AsyncIterable`). Skips the
|
|
153
|
-
* async-shape probe in `recompute` for a small fixed-cost win per run.
|
|
154
|
-
* Intended for compiler emissions (`_$memo`) and library code that
|
|
155
|
-
* provably returns sync values. Returning a Promise or async iterable
|
|
156
|
-
* from a `sync: true` memo is undefined behavior — the value will be
|
|
157
|
-
* stored as-is and never awaited.
|
|
158
|
-
*/
|
|
159
|
-
sync?: boolean;
|
|
160
|
-
}
|
|
161
|
-
export type NoInfer<T extends any> = [T][T extends any ? 0 : never];
|
|
162
|
-
/**
|
|
163
|
-
* Creates a simple reactive state with a getter and setter.
|
|
164
|
-
*
|
|
165
|
-
* When called with a plain value, creates a signal with `SignalOptions` (name, equals, ownedWrite, unobserved).
|
|
166
|
-
* When called with a function, creates a writable memo with `SignalOptions & MemoOptions` (adds id, lazy).
|
|
167
|
-
*
|
|
168
|
-
* ```typescript
|
|
169
|
-
* // Plain signal
|
|
170
|
-
* const [state, setState] = createSignal<T>(value, options?: SignalOptions<T>);
|
|
171
|
-
* // Writable memo (function overload)
|
|
172
|
-
* const [state, setState] = createSignal<T>(fn, initialValue?, options?: SignalOptions<T> & MemoOptions<T>);
|
|
173
|
-
* ```
|
|
174
|
-
* @param value initial value of the state; if empty, the state's type will automatically extended with undefined
|
|
175
|
-
* @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
|
|
176
|
-
*
|
|
177
|
-
* @returns `[state: Accessor<T>, setState: Setter<T>]`
|
|
178
|
-
*
|
|
179
|
-
* @example
|
|
180
|
-
* ```ts
|
|
181
|
-
* const [count, setCount] = createSignal(0);
|
|
182
|
-
*
|
|
183
|
-
* count(); // 0
|
|
184
|
-
* setCount(1); // explicit value
|
|
185
|
-
* setCount(c => c + 1); // updater
|
|
186
|
-
* ```
|
|
187
|
-
*
|
|
188
|
-
* @example
|
|
189
|
-
* ```ts
|
|
190
|
-
* // Writable memo: starts as `fn()`, can be locally overwritten by setter.
|
|
191
|
-
* const [user, setUser] = createSignal(() => fetchUser(userId()));
|
|
192
|
-
*
|
|
193
|
-
* setUser({ ...user(), name: "Alice" }); // optimistic local edit
|
|
194
|
-
* ```
|
|
195
|
-
*
|
|
196
|
-
* @description https://docs.solidjs.com/reference/basic-reactivity/create-signal
|
|
197
|
-
*/
|
|
198
|
-
export declare function createSignal<T>(): Signal<T | undefined>;
|
|
199
|
-
export declare function createSignal<T>(value: Exclude<T, Function>, options?: SignalOptions<T>): Signal<T>;
|
|
200
|
-
export declare function createSignal<T>(fn: ComputeFunction<T>, options?: SignalOptions<T> & MemoOptions<T>): Signal<T>;
|
|
201
|
-
/**
|
|
202
|
-
* Creates a readonly derived reactive memoized signal.
|
|
203
|
-
*
|
|
204
|
-
* ```typescript
|
|
205
|
-
* const value = createMemo<T>(compute, options?: MemoOptions<T>);
|
|
206
|
-
* ```
|
|
207
|
-
* @param compute a function that receives its previous value and returns a new value used to react on a computation
|
|
208
|
-
* @param options `MemoOptions` -- id, name, equals, unobserved, lazy
|
|
209
|
-
*
|
|
210
|
-
* @example
|
|
211
|
-
* ```ts
|
|
212
|
-
* const [first, setFirst] = createSignal("Ada");
|
|
213
|
-
* const [last, setLast] = createSignal("Lovelace");
|
|
214
|
-
*
|
|
215
|
-
* const fullName = createMemo(() => `${first()} ${last()}`);
|
|
216
|
-
*
|
|
217
|
-
* fullName(); // "Ada Lovelace"
|
|
218
|
-
* ```
|
|
219
|
-
*
|
|
220
|
-
* @example
|
|
221
|
-
* ```ts
|
|
222
|
-
* // Async memo — reads surface as pending inside <Loading>
|
|
223
|
-
* const user = createMemo(async () => {
|
|
224
|
-
* const res = await fetch(`/users/${id()}`);
|
|
225
|
-
* return res.json();
|
|
226
|
-
* });
|
|
227
|
-
* ```
|
|
228
|
-
*
|
|
229
|
-
* @description https://docs.solidjs.com/reference/basic-reactivity/create-memo
|
|
230
|
-
*/
|
|
231
|
-
export declare function createMemo<T>(compute: ComputeFunction<undefined | NoInfer<T>, T>, options?: MemoOptions<T>): SourceAccessor<T>;
|
|
232
|
-
/**
|
|
233
|
-
* Creates a reactive effect with **separate compute and effect phases**.
|
|
234
|
-
*
|
|
235
|
-
* - `compute(prev)` runs reactively — *put all reactive reads here*. The
|
|
236
|
-
* returned value is passed to `effect` and is also the new "previous" value
|
|
237
|
-
* for the next run.
|
|
238
|
-
* - `effect(next, prev?)` runs imperatively (untracked) after the queue
|
|
239
|
-
* flushes. *Put DOM writes / fetch / logging / subscriptions here.* It may
|
|
240
|
-
* return a cleanup function which runs before the next effect or on
|
|
241
|
-
* disposal.
|
|
242
|
-
*
|
|
243
|
-
* Reactive reads inside `effect` will *not* re-trigger this effect — that's
|
|
244
|
-
* intentional. If you need a single-phase tracked effect, use
|
|
245
|
-
* `createTrackedEffect` (with the tradeoffs noted there).
|
|
246
|
-
*
|
|
247
|
-
* Pass an `EffectBundle` (`{ effect, error }`) instead of a plain function to
|
|
248
|
-
* intercept errors thrown from the compute or effect phases.
|
|
249
|
-
*
|
|
250
|
-
* ```typescript
|
|
251
|
-
* createEffect<T>(compute, effectFn | { effect, error }, options?: EffectOptions);
|
|
252
|
-
* ```
|
|
253
|
-
* @param compute a function that receives its previous value and returns a new value used to react on a computation
|
|
254
|
-
* @param effectFn a function that receives the new value and is used to perform side effects (return a cleanup function), or an `EffectBundle` with `effect` and `error` handlers
|
|
255
|
-
* @param options `EffectOptions` -- name, defer, schedule
|
|
256
|
-
*
|
|
257
|
-
* @example
|
|
258
|
-
* ```ts
|
|
259
|
-
* const [count, setCount] = createSignal(0);
|
|
260
|
-
*
|
|
261
|
-
* createEffect(
|
|
262
|
-
* () => count(), // compute: tracks `count`
|
|
263
|
-
* value => console.log(value) // effect: side effect
|
|
264
|
-
* );
|
|
265
|
-
*
|
|
266
|
-
* setCount(1); // logs 1 after the next flush
|
|
267
|
-
* ```
|
|
268
|
-
*
|
|
269
|
-
* @example
|
|
270
|
-
* ```ts
|
|
271
|
-
* createEffect(
|
|
272
|
-
* () => userId(),
|
|
273
|
-
* id => {
|
|
274
|
-
* const ctrl = new AbortController();
|
|
275
|
-
* fetch(`/users/${id}`, { signal: ctrl.signal });
|
|
276
|
-
* return () => ctrl.abort(); // cleanup before next run / disposal
|
|
277
|
-
* }
|
|
278
|
-
* );
|
|
279
|
-
* ```
|
|
280
|
-
*
|
|
281
|
-
* @description https://docs.solidjs.com/reference/basic-reactivity/create-effect
|
|
282
|
-
*/
|
|
283
|
-
export declare function createEffect<T>(compute: ComputeFunction<undefined | NoInfer<T>, T>, effectFn: EffectFunction<NoInfer<T>, T> | EffectBundle<NoInfer<T>, T>, options?: EffectOptions): void;
|
|
284
|
-
/**
|
|
285
|
-
* @deprecated `createEffect(compute)` (single argument) is no longer supported.
|
|
286
|
-
* Pass a separate effect function as the second argument:
|
|
287
|
-
* `createEffect(compute, effect)`. See [MISSING_EFFECT_FN].
|
|
288
|
-
*
|
|
289
|
-
* - For a side effect that reacts to changes, split the work:
|
|
290
|
-
* `createEffect(() => signal(), value => doWork(value))`.
|
|
291
|
-
* - For a derived value, use `createMemo(() => signal())`.
|
|
292
|
-
* - For a one-shot side effect at construction time, just call the function.
|
|
293
|
-
*/
|
|
294
|
-
export declare function createEffect<T>(compute: ComputeFunction<undefined | NoInfer<T>, T>): never;
|
|
295
|
-
/**
|
|
296
|
-
* Creates a reactive computation that runs during the render phase as DOM elements
|
|
297
|
-
* are created and updated but not necessarily connected.
|
|
298
|
-
*
|
|
299
|
-
* Same compute / effect split as `createEffect`, but scheduled inside the render
|
|
300
|
-
* queue rather than after it. Reach for this only when authoring renderer
|
|
301
|
-
* plumbing (custom DOM bindings, JSX-generated `insert()` / `spread()` calls).
|
|
302
|
-
* App code should use `createEffect`.
|
|
303
|
-
*
|
|
304
|
-
* ```typescript
|
|
305
|
-
* createRenderEffect<T>(compute, effectFn, options?: EffectOptions);
|
|
306
|
-
* ```
|
|
307
|
-
* @param compute a function that receives its previous value and returns a new value used to react on a computation
|
|
308
|
-
* @param effectFn a function that receives the new value and is used to perform side effects
|
|
309
|
-
* @param options `EffectOptions` -- name, defer, schedule
|
|
310
|
-
*
|
|
311
|
-
* @example
|
|
312
|
-
* ```ts
|
|
313
|
-
* // Custom directive: bind an element's textContent to a reactive source.
|
|
314
|
-
* function bindText(el: HTMLElement, source: () => string) {
|
|
315
|
-
* createRenderEffect(
|
|
316
|
-
* () => source(),
|
|
317
|
-
* value => { el.textContent = value; }
|
|
318
|
-
* );
|
|
319
|
-
* }
|
|
320
|
-
* ```
|
|
321
|
-
*
|
|
322
|
-
* @description https://docs.solidjs.com/reference/secondary-primitives/create-render-effect
|
|
323
|
-
*/
|
|
324
|
-
export declare function createRenderEffect<T>(compute: ComputeFunction<undefined | NoInfer<T>, T>, effectFn: EffectFunction<NoInfer<T>, T>, options?: EffectOptions): void;
|
|
325
|
-
/**
|
|
326
|
-
* Creates a tracked reactive effect where dependency tracking and side effects happen
|
|
327
|
-
* in the same scope.
|
|
328
|
-
*
|
|
329
|
-
* WARNING: Because tracking and effects happen in the same scope, this primitive
|
|
330
|
-
* may run multiple times for a single change or show tearing (reading inconsistent
|
|
331
|
-
* state). Use only when dynamic subscription patterns require same-scope tracking.
|
|
332
|
-
*
|
|
333
|
-
* ```typescript
|
|
334
|
-
* createTrackedEffect(compute, options?: { name?: string });
|
|
335
|
-
* ```
|
|
336
|
-
* @param compute a function that contains reactive reads to track and returns an optional cleanup function to run on disposal or before next execution
|
|
337
|
-
* @param options -- name
|
|
338
|
-
*
|
|
339
|
-
* @example
|
|
340
|
-
* ```ts
|
|
341
|
-
* createTrackedEffect(() => {
|
|
342
|
-
* const target = focusedNode();
|
|
343
|
-
* if (!target) return;
|
|
344
|
-
*
|
|
345
|
-
* const handler = () => log(target.value());
|
|
346
|
-
* target.on("change", handler);
|
|
347
|
-
*
|
|
348
|
-
* return () => target.off("change", handler);
|
|
349
|
-
* });
|
|
350
|
-
* ```
|
|
351
|
-
*
|
|
352
|
-
* @description https://docs.solidjs.com/reference/secondary-primitives/create-tracked-effect
|
|
353
|
-
*/
|
|
354
|
-
export declare function createTrackedEffect(compute: () => void | (() => void), options?: BaseEffectOptions): void;
|
|
355
|
-
/**
|
|
356
|
-
* Creates a reactive computation that runs after the render phase with flexible tracking.
|
|
357
|
-
*
|
|
358
|
-
* ```typescript
|
|
359
|
-
* const track = createReaction(effectFn, options?: EffectOptions);
|
|
360
|
-
* track(() => { // reactive reads });
|
|
361
|
-
* ```
|
|
362
|
-
* @param effectFn a function (or `EffectBundle`) that is called when tracked function is invalidated
|
|
363
|
-
* @param options `EffectOptions` -- name, defer
|
|
364
|
-
*
|
|
365
|
-
* @example
|
|
366
|
-
* ```ts
|
|
367
|
-
* const [count, setCount] = createSignal(0);
|
|
368
|
-
*
|
|
369
|
-
* const track = createReaction(() => {
|
|
370
|
-
* console.log("count changed once, re-arm to listen again");
|
|
371
|
-
* track(() => count()); // re-arm
|
|
372
|
-
* });
|
|
373
|
-
*
|
|
374
|
-
* track(() => count()); // initial arm
|
|
375
|
-
*
|
|
376
|
-
* setCount(1); // logs once, reaction re-armed for next change
|
|
377
|
-
* ```
|
|
378
|
-
*
|
|
379
|
-
* @description https://docs.solidjs.com/reference/secondary-primitives/create-reaction
|
|
380
|
-
*/
|
|
381
|
-
export declare function createReaction(effectFn: EffectFunction<undefined> | EffectBundle<undefined>, options?: EffectOptions): (tracking: () => void) => void;
|
|
382
|
-
/**
|
|
383
|
-
* Awaits a reactive expression and returns its first fully-settled value as a
|
|
384
|
-
* `Promise`. Pending async reads (`createMemo` returning a promise, etc.) are
|
|
385
|
-
* waited on; once the expression returns synchronously without `NotReadyError`
|
|
386
|
-
* the promise resolves with that value.
|
|
387
|
-
*
|
|
388
|
-
* Must be called *outside* a tracking scope — it doesn't subscribe, it just
|
|
389
|
-
* resolves the current value once.
|
|
390
|
-
*
|
|
391
|
-
* @example
|
|
392
|
-
* ```ts
|
|
393
|
-
* const user = createMemo(() => fetch(`/users/${id()}`).then(r => r.json()));
|
|
394
|
-
*
|
|
395
|
-
* // outside any reactive scope
|
|
396
|
-
* const initial = await resolve(() => user());
|
|
397
|
-
* ```
|
|
398
|
-
*
|
|
399
|
-
* @param fn a reactive expression to resolve
|
|
400
|
-
*/
|
|
401
|
-
export declare function resolve<T>(fn: () => T): Promise<T>;
|
|
402
|
-
/**
|
|
403
|
-
* Creates an optimistic signal that can be used to optimistically update a value
|
|
404
|
-
* and then revert it back to the previous value at end of transition.
|
|
405
|
-
*
|
|
406
|
-
* When called with a plain value, creates an optimistic signal with `SignalOptions` (name, equals, ownedWrite, unobserved).
|
|
407
|
-
* When called with a function, creates a writable optimistic memo with `SignalOptions & MemoOptions` (adds id, lazy).
|
|
408
|
-
*
|
|
409
|
-
* ```typescript
|
|
410
|
-
* // Plain optimistic signal
|
|
411
|
-
* const [state, setState] = createOptimistic<T>(value, options?: SignalOptions<T>);
|
|
412
|
-
* // Writable optimistic memo (function overload)
|
|
413
|
-
* const [state, setState] = createOptimistic<T>(fn, options?: SignalOptions<T> & MemoOptions<T>);
|
|
414
|
-
* ```
|
|
415
|
-
* @param value initial value of the signal; if empty, the signal's type will automatically extended with undefined
|
|
416
|
-
* @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
|
|
417
|
-
*
|
|
418
|
-
* @returns `[state: Accessor<T>, setState: Setter<T>]`
|
|
419
|
-
*
|
|
420
|
-
* @example
|
|
421
|
-
* ```ts
|
|
422
|
-
* const [todos, setTodos] = createOptimistic(initialTodos);
|
|
423
|
-
*
|
|
424
|
-
* const addTodo = action(function* (text: string) {
|
|
425
|
-
* const tempId = crypto.randomUUID();
|
|
426
|
-
* setTodos(t => [...t, { id: tempId, text, pending: true }]); // optimistic
|
|
427
|
-
* const saved = yield api.createTodo(text);
|
|
428
|
-
* setTodos(t => t.map(x => (x.id === tempId ? saved : x))); // reconcile
|
|
429
|
-
* });
|
|
430
|
-
* ```
|
|
431
|
-
*
|
|
432
|
-
* @description https://docs.solidjs.com/reference/basic-reactivity/create-optimistic-signal
|
|
433
|
-
*/
|
|
434
|
-
export declare function createOptimistic<T>(): Signal<T | undefined>;
|
|
435
|
-
export declare function createOptimistic<T>(value: Exclude<T, Function>, options?: SignalOptions<T>): Signal<T>;
|
|
436
|
-
export declare function createOptimistic<T>(fn: ComputeFunction<T>, options?: SignalOptions<T> & MemoOptions<T>): Signal<T>;
|
|
437
|
-
/**
|
|
438
|
-
* Schedules `callback` to run **once** after the reactive graph has fully
|
|
439
|
-
* settled — i.e. once every pending async read inside the current owner has
|
|
440
|
-
* resolved and the queue has flushed. Each call registers a single fire; it
|
|
441
|
-
* does not create an ongoing subscription.
|
|
442
|
-
*
|
|
443
|
-
* The canonical lifecycle primitive in 2.0. Three main usages:
|
|
444
|
-
*
|
|
445
|
-
* - **Component-level setup-and-teardown** *(the most common shape)*: run
|
|
446
|
-
* setup after the component's first stable render and **return a cleanup
|
|
447
|
-
* function** to dispose it on owner disposal. This is the replacement for
|
|
448
|
-
* the 1.x `onMount` + `onCleanup` pairing — setup and teardown live in one
|
|
449
|
-
* block, and `onCleanup` is no longer the right tool for component
|
|
450
|
-
* bodies. (`onMount` no longer exists in 2.0.)
|
|
451
|
-
* - **Post-settle "ready" hook:** run once after a component's first stable
|
|
452
|
-
* render — analytics ping, focus, scroll-into-view, etc. No cleanup needed.
|
|
453
|
-
* - **Inside an event handler:** schedule work to run after the action /
|
|
454
|
-
* transition triggered by the event has completed.
|
|
455
|
-
*
|
|
456
|
-
* Reactive reads inside the callback are *not* tracked — to react to
|
|
457
|
-
* subsequent settles, register a new `onSettled` each time.
|
|
458
|
-
*
|
|
459
|
-
* `onCleanup` is **not** allowed inside the callback — return a cleanup
|
|
460
|
-
* function instead. The returned cleanup runs on owner disposal.
|
|
461
|
-
*
|
|
462
|
-
* @example
|
|
463
|
-
* ```tsx
|
|
464
|
-
* // Component-level setup + teardown — replaces onMount + onCleanup.
|
|
465
|
-
* // Subscribe to an external source on mount, unsubscribe on dispose.
|
|
466
|
-
* function useViewportWidth() {
|
|
467
|
-
* const [width, setWidth] = createSignal(window.innerWidth);
|
|
468
|
-
* onSettled(() => {
|
|
469
|
-
* const onResize = () => setWidth(window.innerWidth);
|
|
470
|
-
* window.addEventListener("resize", onResize);
|
|
471
|
-
* return () => window.removeEventListener("resize", onResize);
|
|
472
|
-
* });
|
|
473
|
-
* return width;
|
|
474
|
-
* }
|
|
475
|
-
* ```
|
|
476
|
-
*
|
|
477
|
-
* @example
|
|
478
|
-
* ```tsx
|
|
479
|
-
* // Post-settle "ready" hook — no cleanup needed.
|
|
480
|
-
* function Dashboard() {
|
|
481
|
-
* const data = createMemo(async () => fetchData());
|
|
482
|
-
*
|
|
483
|
-
* onSettled(() => {
|
|
484
|
-
* analytics.track("dashboard.ready");
|
|
485
|
-
* });
|
|
486
|
-
*
|
|
487
|
-
* return <Loading fallback={<Spinner />}><pre>{data()}</pre></Loading>;
|
|
488
|
-
* }
|
|
489
|
-
* ```
|
|
490
|
-
*
|
|
491
|
-
* @example
|
|
492
|
-
* ```tsx
|
|
493
|
-
* // Event-handler — runs after the action settles.
|
|
494
|
-
* function SaveButton() {
|
|
495
|
-
* const save = action(function* () {
|
|
496
|
-
* yield api.save();
|
|
497
|
-
* });
|
|
498
|
-
*
|
|
499
|
-
* const handleClick = () => {
|
|
500
|
-
* save();
|
|
501
|
-
* onSettled(() => toast("Saved!"));
|
|
502
|
-
* };
|
|
503
|
-
*
|
|
504
|
-
* return <button onClick={handleClick}>Save</button>;
|
|
505
|
-
* }
|
|
506
|
-
* ```
|
|
507
|
-
*
|
|
508
|
-
* @param callback Function to run; may return a cleanup function that fires
|
|
509
|
-
* on owner disposal
|
|
510
|
-
*/
|
|
511
|
-
export declare function onSettled(callback: () => void | (() => void)): void;
|
|
512
|
-
export {};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export type { Store, StoreSetter, StoreNode, StoreOptions, ProjectionOptions, NotWrappable, SolidStore } from "./store.js";
|
|
2
|
-
export type { Merge, Omit } from "./utils.js";
|
|
3
|
-
export { isWrappable, createStore, $TRACK, $PROXY, $TARGET } from "./store.js";
|
|
4
|
-
export { createProjection } from "./projection.js";
|
|
5
|
-
export { createOptimisticStore } from "./optimistic.js";
|
|
6
|
-
export { reconcile } from "./reconcile.js";
|
|
7
|
-
export { storePath } from "./storePath.js";
|
|
8
|
-
export type { PathSetter, Part, StorePathRange, ArrayFilterFn, CustomPartial } from "./storePath.js";
|
|
9
|
-
export { snapshot, deep, merge, omit } from "./utils.js";
|