@solidjs/signals 2.0.0-beta.9 → 2.0.0-rc.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/README.md +13 -9
- package/dist/dev.js +5971 -1426
- package/dist/node.cjs +7681 -3293
- package/dist/prod/affects.js +126 -0
- package/dist/prod/boundaries.js +572 -0
- package/dist/prod/core/action.js +139 -0
- package/dist/prod/core/async.js +553 -0
- package/dist/prod/core/constants.js +92 -0
- package/dist/prod/core/context.js +67 -0
- package/dist/prod/core/core.js +817 -0
- package/dist/prod/core/dev.js +3 -0
- package/dist/prod/core/effect.js +145 -0
- package/dist/prod/core/error.js +68 -0
- package/dist/prod/core/external.js +98 -0
- package/dist/prod/core/graph.js +104 -0
- package/dist/prod/core/heap.js +140 -0
- package/dist/prod/core/invariants.js +42 -0
- package/dist/prod/core/lanes.js +140 -0
- package/dist/prod/core/optimistic.js +245 -0
- package/dist/prod/core/owner.js +302 -0
- package/dist/prod/core/scheduler.js +749 -0
- package/dist/prod/core/verdict.js +369 -0
- package/dist/prod/index.js +45 -0
- package/dist/prod/map.js +317 -0
- package/dist/prod/signals.js +375 -0
- package/dist/prod/store/optimistic.js +217 -0
- package/dist/prod/store/projection.js +231 -0
- package/dist/prod/store/reconcile.js +707 -0
- package/dist/prod/store/store.js +1081 -0
- package/dist/prod/store/storePath.js +103 -0
- package/dist/prod/store/utils.js +328 -0
- package/dist/types/affects.d.ts +47 -0
- package/dist/types/boundaries.d.ts +60 -13
- package/dist/types/core/action.d.ts +35 -6
- package/dist/types/core/async.d.ts +16 -1
- package/dist/types/core/constants.d.ts +35 -6
- package/dist/types/core/context.d.ts +10 -2
- package/dist/types/core/core.d.ts +58 -63
- package/dist/types/core/dev.d.ts +17 -2
- package/dist/types/core/effect.d.ts +1 -2
- package/dist/types/core/error.d.ts +33 -0
- package/dist/types/core/external.d.ts +0 -11
- package/dist/types/core/graph.d.ts +2 -1
- package/dist/types/core/heap.d.ts +8 -0
- package/dist/types/core/index.d.ts +3 -2
- package/dist/types/core/invariants.d.ts +59 -0
- package/dist/types/core/lanes.d.ts +2 -0
- package/dist/types/core/optimistic.d.ts +6 -0
- package/dist/types/core/owner.d.ts +50 -3
- package/dist/types/core/scheduler.d.ts +82 -10
- package/dist/types/core/types.d.ts +66 -1
- package/dist/types/core/verdict.d.ts +2 -0
- package/dist/types/index.d.ts +3 -2
- package/dist/types/map.d.ts +21 -5
- package/dist/types/signals.d.ts +164 -12
- package/dist/types/store/index.d.ts +1 -1
- package/dist/types/store/optimistic.d.ts +3 -3
- package/dist/types/store/projection.d.ts +10 -6
- package/dist/types/store/reconcile.d.ts +31 -8
- package/dist/types/store/store.d.ts +101 -6
- package/dist/types-cjs/affects.d.cts +47 -0
- package/dist/types-cjs/boundaries.d.cts +60 -13
- package/dist/types-cjs/core/action.d.cts +35 -6
- package/dist/types-cjs/core/async.d.cts +16 -1
- package/dist/types-cjs/core/constants.d.cts +35 -6
- package/dist/types-cjs/core/context.d.cts +10 -2
- package/dist/types-cjs/core/core.d.cts +58 -63
- package/dist/types-cjs/core/dev.d.cts +17 -2
- package/dist/types-cjs/core/effect.d.cts +1 -2
- package/dist/types-cjs/core/error.d.cts +33 -0
- package/dist/types-cjs/core/external.d.cts +0 -11
- package/dist/types-cjs/core/graph.d.cts +2 -1
- package/dist/types-cjs/core/heap.d.cts +8 -0
- package/dist/types-cjs/core/index.d.cts +3 -2
- package/dist/types-cjs/core/invariants.d.cts +59 -0
- package/dist/types-cjs/core/lanes.d.cts +2 -0
- package/dist/types-cjs/core/optimistic.d.cts +6 -0
- package/dist/types-cjs/core/owner.d.cts +50 -3
- package/dist/types-cjs/core/scheduler.d.cts +82 -10
- package/dist/types-cjs/core/types.d.cts +66 -1
- package/dist/types-cjs/core/verdict.d.cts +2 -0
- package/dist/types-cjs/index.d.cts +3 -2
- package/dist/types-cjs/map.d.cts +21 -5
- package/dist/types-cjs/signals.d.cts +164 -12
- package/dist/types-cjs/store/index.d.cts +1 -1
- package/dist/types-cjs/store/optimistic.d.cts +3 -3
- package/dist/types-cjs/store/projection.d.cts +10 -6
- package/dist/types-cjs/store/reconcile.d.cts +31 -8
- package/dist/types-cjs/store/store.d.cts +101 -6
- package/package.json +11 -9
- package/dist/prod.js +0 -3627
|
@@ -10,6 +10,14 @@ export interface Link {
|
|
|
10
10
|
_nextDep: Link | null;
|
|
11
11
|
_prevSub: Link | null;
|
|
12
12
|
_nextSub: Link | null;
|
|
13
|
+
/**
|
|
14
|
+
* `_sub._depGen` at the time this link was created or last revalidated
|
|
15
|
+
* in-order. A link stamped with the subscriber's current pass generation is
|
|
16
|
+
* inside the validated `[deps.._depsTail]` prefix — an O(1) replacement for
|
|
17
|
+
* scanning the dep list to answer membership (see `link()`).
|
|
18
|
+
*/
|
|
19
|
+
_gen: number;
|
|
20
|
+
_pendingObserver?: boolean;
|
|
13
21
|
}
|
|
14
22
|
export interface NodeOptions<T> {
|
|
15
23
|
id?: string;
|
|
@@ -21,6 +29,17 @@ export interface NodeOptions<T> {
|
|
|
21
29
|
_noSnapshot?: boolean;
|
|
22
30
|
unobserved?: () => void;
|
|
23
31
|
lazy?: boolean;
|
|
32
|
+
sync?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Commit #0. When present (checked with `in`, so an explicit `undefined`
|
|
35
|
+
* counts), the node is born committed with this value instead of
|
|
36
|
+
* STATUS_UNINITIALIZED: reads serve it everywhere, nothing suspends to
|
|
37
|
+
* Loading boundaries, transitions are never held, and the window is
|
|
38
|
+
* verdict-quiet (`isPending` stays false — commit #0 answers the question
|
|
39
|
+
* by declaration; first-load affordances live in the value itself). After
|
|
40
|
+
* the first real answer lands, normal refetch/pending semantics apply.
|
|
41
|
+
*/
|
|
42
|
+
loadingValue?: T;
|
|
24
43
|
}
|
|
25
44
|
export interface RawSignal<T> {
|
|
26
45
|
_subs: Link | null;
|
|
@@ -35,10 +54,29 @@ export interface RawSignal<T> {
|
|
|
35
54
|
_transition: Transition | null;
|
|
36
55
|
_pendingValue: T | typeof NOT_PENDING;
|
|
37
56
|
_overrideValue?: T | typeof NOT_PENDING;
|
|
57
|
+
/**
|
|
58
|
+
* The transaction that owns the active override (stamped at optimistic
|
|
59
|
+
* write, cleared at settle). Ownership must live on the node: a lane's
|
|
60
|
+
* _transition is a scheduling affinity that a shared subscriber can merge
|
|
61
|
+
* across transactions (#2912) — following it would let one action's settle
|
|
62
|
+
* revert another action's live override. Node-level sibling of the store
|
|
63
|
+
* layer's STORE_OPTIMISTIC_OWNERS stamps (#2899). `null` = ambient write.
|
|
64
|
+
*/
|
|
65
|
+
_overrideOwner?: Transition | null;
|
|
38
66
|
_optimisticLane?: OptimisticLane;
|
|
39
67
|
_pendingSignal?: Signal<boolean>;
|
|
40
68
|
_latestValueComputed?: Computed<T>;
|
|
41
69
|
_parentSource?: Signal<any> | Computed<any>;
|
|
70
|
+
/**
|
|
71
|
+
* Live `affects()` marks on this node (refcount). Non-zero is declared
|
|
72
|
+
* motion: the node — and, via the verdict layer's dep-graph coverage walk,
|
|
73
|
+
* everything derived from it — reads pending regardless of graph state,
|
|
74
|
+
* until every declaring transaction settles/reverts and releases its mark.
|
|
75
|
+
* This count is the mark's ONLY graph state: the dedicated channel stores
|
|
76
|
+
* nothing downstream and never touches status flags, errors, or pending
|
|
77
|
+
* sources.
|
|
78
|
+
*/
|
|
79
|
+
_affectsCount?: number;
|
|
42
80
|
}
|
|
43
81
|
export interface FirewallSignal<T> extends RawSignal<T> {
|
|
44
82
|
_firewall: Computed<any>;
|
|
@@ -49,6 +87,8 @@ export interface Owner {
|
|
|
49
87
|
id?: string;
|
|
50
88
|
_config: number;
|
|
51
89
|
_snapshotScope?: boolean;
|
|
90
|
+
/** Effect-returned cleanup; managed across reruns, invoked at true disposal */
|
|
91
|
+
_cleanup?: () => void;
|
|
52
92
|
_disposal: Disposable | Disposable[] | null;
|
|
53
93
|
_parent: Owner | null;
|
|
54
94
|
_context: Record<symbol | string, unknown>;
|
|
@@ -56,15 +96,17 @@ export interface Owner {
|
|
|
56
96
|
_queue: IQueue;
|
|
57
97
|
_firstChild: Owner | null;
|
|
58
98
|
_nextSibling: Owner | null;
|
|
99
|
+
_prevSibling: Owner | null;
|
|
59
100
|
_pendingDisposal: Disposable | Disposable[] | null;
|
|
60
101
|
_pendingFirstChild: Owner | null;
|
|
61
102
|
}
|
|
62
103
|
export interface Computed<T> extends RawSignal<T>, Owner {
|
|
63
104
|
_deps: Link | null;
|
|
64
105
|
_depsTail: Link | null;
|
|
106
|
+
/** Recompute-pass counter; bumped when dep revalidation starts. */
|
|
107
|
+
_depGen: number;
|
|
65
108
|
_flags: number;
|
|
66
109
|
_blocked?: boolean;
|
|
67
|
-
_pendingSource?: Computed<any>;
|
|
68
110
|
_pendingSources?: Set<Computed<any>>;
|
|
69
111
|
_error?: unknown;
|
|
70
112
|
_statusFlags: number;
|
|
@@ -75,6 +117,29 @@ export interface Computed<T> extends RawSignal<T>, Owner {
|
|
|
75
117
|
_inFlight: PromiseLike<T> | AsyncIterable<T> | null;
|
|
76
118
|
_child: FirewallSignal<any> | null;
|
|
77
119
|
_notifyStatus?: (status?: number, error?: any) => void;
|
|
120
|
+
/**
|
|
121
|
+
* Question-scoped pending classification of the node's CURRENT pending
|
|
122
|
+
* window: `true` means the in-flight recompute is a re-ask of the same
|
|
123
|
+
* question (refresh/poll/confirm — no tracked input changed value), so the
|
|
124
|
+
* shown answer still answers the question and the node reads NOT pending.
|
|
125
|
+
* Set by `recompute` from `REACTIVE_REASK`, cleared on landing
|
|
126
|
+
* (`clearStatus`). Meaningless while not STATUS_PENDING.
|
|
127
|
+
*/
|
|
128
|
+
_reask: boolean;
|
|
129
|
+
/**
|
|
130
|
+
* True while a `loadingValue` node's first real answer hasn't landed: the
|
|
131
|
+
* node was born committed (commit #0 = the loading value) and `handleAsync`
|
|
132
|
+
* serves that committed value instead of throwing NotReadyError, so first
|
|
133
|
+
* flights never suspend readers, trip boundaries, or hold transitions.
|
|
134
|
+
* The window is verdict-quiet: `isPending` stays false, because commit #0
|
|
135
|
+
* answers the question by declaration (first-load affordances belong to
|
|
136
|
+
* the value channel). Cleared by the first value landing on any path (sync
|
|
137
|
+
* return, sync-resolved promise, first iterator yield, async settle); a
|
|
138
|
+
* real error leaves it set — errors answer reads but don't enter the value
|
|
139
|
+
* lineage, so a retry serves the loading value again. Once cleared, normal
|
|
140
|
+
* pending/refetch semantics apply forever.
|
|
141
|
+
*/
|
|
142
|
+
_loading: boolean;
|
|
78
143
|
}
|
|
79
144
|
export interface Root extends Owner {
|
|
80
145
|
_root: true;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
export { $REFRESH, ContextNotFoundError, NoOwnerError, NotReadyError, action, createContext, createOwner, createRoot, runWithOwner, flush, getNextChildId, peekNextChildId, getContext, setContext, getOwner, isDisposed, getObserver, isEqual, untrack, isPending, latest,
|
|
1
|
+
export { $REFRESH, ContextNotFoundError, NoOwnerError, NotReadyError, action, createContext, createOwner, createRoot, runWithOwner, flush, getNextChildId, peekNextChildId, getContext, setContext, getOwner, isDisposed, getObserver, isEqual, untrack, isPending, latest, refresh, SUPPORTS_PROXY, setSnapshotCapture, markSnapshotScope, releaseSnapshotScope, clearSnapshots, enforceLoadingBoundary, enableExternalSource, resetErrorHalt } from "./core/index.cjs";
|
|
2
2
|
import { type Dev } from "./core/index.cjs";
|
|
3
3
|
export declare const DEV: Dev | undefined;
|
|
4
4
|
export type { Owner, Context, ContextRecord, IQueue, ExternalSourceFactory, ExternalSource, ExternalSourceConfig, Refreshable, Dev, DevHooks, DiagnosticCapture, DiagnosticCode, DiagnosticEvent, DiagnosticKind, Diagnostics, DiagnosticSeverity } from "./core/index.cjs";
|
|
5
5
|
export { createSignal, createMemo, createEffect, createRenderEffect, createTrackedEffect, createReaction, createOptimistic, resolve, onSettled, onCleanup } from "./signals.cjs";
|
|
6
|
-
export type { Accessor, Setter, Signal, ComputeFunction, EffectFunction, EffectBundle, EffectOptions, SignalOptions, MemoOptions, NoInfer } from "./signals.cjs";
|
|
6
|
+
export type { Accessor, SourceAccessor, Setter, Signal, ComputeFunction, EffectFunction, EffectBundle, EffectOptions, SignalOptions, MemoOptions, NoInfer } from "./signals.cjs";
|
|
7
|
+
export { affects } from "./affects.cjs";
|
|
7
8
|
export { mapArray, repeat, type Maybe } from "./map.cjs";
|
|
8
9
|
export * from "./store/index.cjs";
|
|
9
10
|
export { createLoadingBoundary, createErrorBoundary, createRevealOrder, flatten, type RevealOrder } from "./boundaries.cjs";
|
package/dist/types-cjs/map.d.cts
CHANGED
|
@@ -2,8 +2,14 @@ import { type Accessor } from "./signals.cjs";
|
|
|
2
2
|
export type Maybe<T> = T | void | null | undefined | false;
|
|
3
3
|
/**
|
|
4
4
|
* Reactively maps an array, reusing the previously-mapped value for unchanged
|
|
5
|
-
* items.
|
|
6
|
-
*
|
|
5
|
+
* items.
|
|
6
|
+
*
|
|
7
|
+
* The callback shape follows the keying mode:
|
|
8
|
+
* - default / `keyed: true` receives `(item, index)` where `item` is the raw
|
|
9
|
+
* row value and `index` is an accessor.
|
|
10
|
+
* - `keyed: false` receives `(item, index)` where `item` is an accessor and
|
|
11
|
+
* `index` is a stable number.
|
|
12
|
+
* - `keyed: item => key` receives accessors for both arguments.
|
|
7
13
|
*
|
|
8
14
|
* This is the underlying helper that powers `<For>`. App code should use
|
|
9
15
|
* `<For>` directly; reach for `mapArray` when implementing custom list
|
|
@@ -19,15 +25,25 @@ export type Maybe<T> = T | void | null | undefined | false;
|
|
|
19
25
|
* ```ts
|
|
20
26
|
* const view = mapArray(
|
|
21
27
|
* items,
|
|
22
|
-
* (item, index) => `${index()}: ${item
|
|
28
|
+
* (item, index) => `${index()}: ${item.label}`,
|
|
23
29
|
* { fallback: () => "no items" }
|
|
24
30
|
* );
|
|
25
31
|
* ```
|
|
26
32
|
*
|
|
27
33
|
* @description https://docs.solidjs.com/reference/reactive-utilities/map-array
|
|
28
34
|
*/
|
|
29
|
-
export declare function mapArray<Item, MappedItem>(list: Accessor<Maybe<readonly Item[]>>, map: (value:
|
|
30
|
-
keyed?:
|
|
35
|
+
export declare function mapArray<Item, MappedItem>(list: Accessor<Maybe<readonly Item[]>>, map: (value: Item, index: Accessor<number>) => MappedItem, options?: {
|
|
36
|
+
keyed?: true;
|
|
37
|
+
fallback?: Accessor<any>;
|
|
38
|
+
name?: string;
|
|
39
|
+
}): Accessor<MappedItem[]>;
|
|
40
|
+
export declare function mapArray<Item, MappedItem>(list: Accessor<Maybe<readonly Item[]>>, map: (value: Accessor<Item>, index: number) => MappedItem, options: {
|
|
41
|
+
keyed: false;
|
|
42
|
+
fallback?: Accessor<any>;
|
|
43
|
+
name?: string;
|
|
44
|
+
}): Accessor<MappedItem[]>;
|
|
45
|
+
export declare function mapArray<Item, MappedItem>(list: Accessor<Maybe<readonly Item[]>>, map: (value: Accessor<Item>, index: Accessor<number>) => MappedItem, options: {
|
|
46
|
+
keyed: (item: Item) => any;
|
|
31
47
|
fallback?: Accessor<any>;
|
|
32
48
|
name?: string;
|
|
33
49
|
}): Accessor<MappedItem[]>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Disposable } from "./core/index.cjs";
|
|
1
|
+
import type { Disposable, Refreshable } from "./core/index.cjs";
|
|
2
2
|
/**
|
|
3
3
|
* Low-level reactive-cleanup primitive. Registers a callback that runs when
|
|
4
4
|
* the surrounding owner is disposed.
|
|
@@ -25,6 +25,18 @@ import type { Disposable } from "./core/index.cjs";
|
|
|
25
25
|
*
|
|
26
26
|
* Cannot be used inside `createTrackedEffect` or `onSettled` — return a
|
|
27
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
|
+
* ```
|
|
28
40
|
*/
|
|
29
41
|
export declare function onCleanup(fn: Disposable): Disposable;
|
|
30
42
|
/**
|
|
@@ -35,7 +47,8 @@ export declare function onCleanup(fn: Disposable): Disposable;
|
|
|
35
47
|
* creating a subscription.
|
|
36
48
|
*/
|
|
37
49
|
export type Accessor<T> = () => T;
|
|
38
|
-
export
|
|
50
|
+
export type SourceAccessor<T> = Refreshable<Accessor<T>>;
|
|
51
|
+
export declare function accessor<T>(node: any): SourceAccessor<T>;
|
|
39
52
|
/**
|
|
40
53
|
* A signal setter. Accepts either a new value or an updater `(prev) => next`.
|
|
41
54
|
*
|
|
@@ -51,11 +64,22 @@ export type Setter<in out T> = {
|
|
|
51
64
|
<U extends T>(value: Exclude<U, Function> | ((prev: T) => U)): U;
|
|
52
65
|
};
|
|
53
66
|
/** A `[get, set]` pair returned from `createSignal` / `createOptimistic`. */
|
|
54
|
-
export type Signal<T> = [get:
|
|
67
|
+
export type Signal<T> = [get: SourceAccessor<T>, set: Setter<T>];
|
|
55
68
|
export type ComputeFunction<Prev, Next extends Prev = Prev> = (v: Prev) => PromiseLike<Next> | AsyncIterable<Next> | Next;
|
|
56
69
|
export type EffectFunction<Prev, Next extends Prev = Prev> = (v: Next, p?: Prev) => (() => void) | void;
|
|
57
70
|
export type EffectBundle<Prev, Next extends Prev = Prev> = {
|
|
58
71
|
effect: EffectFunction<Prev, Next>;
|
|
72
|
+
/**
|
|
73
|
+
* Intercepts compute-phase errors (thrown by the compute function or arriving
|
|
74
|
+
* from upstream sources). Effect-phase throws are NOT routed here — they are
|
|
75
|
+
* your own imperative code and escalate to the nearest error boundary.
|
|
76
|
+
*
|
|
77
|
+
* This is the error arm of the effect phase: it runs on the same queue and
|
|
78
|
+
* in the same imperative, writable scope as `effect` (signal writes are
|
|
79
|
+
* legal), receives the error the user code threw, and observes settled
|
|
80
|
+
* outcomes — an error that recovers before the effect phase runs the
|
|
81
|
+
* `effect` arm instead, and a held transition defers it like `effect`.
|
|
82
|
+
*/
|
|
59
83
|
error: (err: unknown, cleanup: () => void) => void;
|
|
60
84
|
};
|
|
61
85
|
/** Options shared by every effect primitive. */
|
|
@@ -77,12 +101,49 @@ export interface EffectOptions extends BaseEffectOptions {
|
|
|
77
101
|
* `insert()` in `render()`).
|
|
78
102
|
*/
|
|
79
103
|
schedule?: boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Advanced. When true, asserts the compute function returns synchronous
|
|
106
|
+
* values only (never `PromiseLike` / `AsyncIterable`). Skips the
|
|
107
|
+
* async-shape probe in `recompute` for a small fixed-cost win per run.
|
|
108
|
+
* Intended for compiler emissions (`_$effect`) and library code that
|
|
109
|
+
* provably returns sync values. Returning a Promise or async iterable
|
|
110
|
+
* from a `sync: true` effect is undefined behavior — the value will be
|
|
111
|
+
* stored as-is and never awaited.
|
|
112
|
+
*/
|
|
113
|
+
sync?: boolean;
|
|
114
|
+
/**
|
|
115
|
+
* Advanced (integration tier). When true, the effect is invisible to the
|
|
116
|
+
* hydration id scheme: it inherits its parent's id instead of consuming a
|
|
117
|
+
* child slot, and during hydration its compute runs live instead of
|
|
118
|
+
* adopting the serialized server value (its first run is not frozen to
|
|
119
|
+
* the server's decision).
|
|
120
|
+
*
|
|
121
|
+
* For **client-only effects created while hydrating** — effects with no
|
|
122
|
+
* server-rendered counterpart (a router wiring link state, scroll
|
|
123
|
+
* restoration, etc.). An id-consuming node the server never created would
|
|
124
|
+
* shift every later sibling's hydration id, making serialized lookups and
|
|
125
|
+
* template claims after it miss. `transparent` is also the supported
|
|
126
|
+
* alternative to branching on hydration state
|
|
127
|
+
* (`if (hydrating) createEffect(...)`), which freezes whatever the first
|
|
128
|
+
* run decided: create the effect unconditionally and let it observe live
|
|
129
|
+
* state instead.
|
|
130
|
+
*
|
|
131
|
+
* SSR ignores this option (a server-side effect always allocates its id
|
|
132
|
+
* slot), so only mark effects the server does not create. Outside
|
|
133
|
+
* hydration it is a no-op.
|
|
134
|
+
*/
|
|
135
|
+
transparent?: boolean;
|
|
80
136
|
}
|
|
81
137
|
/** Options for plain signals created with `createSignal(value)` or `createOptimistic(value)`. */
|
|
82
138
|
export interface SignalOptions<T> {
|
|
83
139
|
/** Debug name (dev mode only) */
|
|
84
140
|
name?: string;
|
|
85
|
-
/**
|
|
141
|
+
/**
|
|
142
|
+
* Custom equality function, or `false` to always notify subscribers.
|
|
143
|
+
* Defaults to reference equality (`isEqual`). Pass a comparator (e.g.
|
|
144
|
+
* `(a, b) => a.id === b.id`) for value-based equality, or `false` to
|
|
145
|
+
* notify on every write regardless of equality.
|
|
146
|
+
*/
|
|
86
147
|
equals?: false | ((prev: T, next: T) => boolean);
|
|
87
148
|
/** Suppress dev-mode warnings when writing inside an owned scope */
|
|
88
149
|
ownedWrite?: boolean;
|
|
@@ -99,9 +160,21 @@ export interface MemoOptions<T> {
|
|
|
99
160
|
id?: string;
|
|
100
161
|
/** Debug name (dev mode only) */
|
|
101
162
|
name?: string;
|
|
102
|
-
/**
|
|
163
|
+
/**
|
|
164
|
+
* Advanced (integration tier). When true, the memo is invisible to the
|
|
165
|
+
* hydration id scheme: it inherits its parent's id instead of consuming a
|
|
166
|
+
* child slot, and during hydration it computes live instead of adopting
|
|
167
|
+
* the serialized server value. For client-only memos with no
|
|
168
|
+
* server-rendered counterpart — see {@link EffectOptions.transparent} for
|
|
169
|
+
* the full semantics. No-op outside hydration.
|
|
170
|
+
*/
|
|
103
171
|
transparent?: boolean;
|
|
104
|
-
/**
|
|
172
|
+
/**
|
|
173
|
+
* Custom equality function, or `false` to always notify subscribers.
|
|
174
|
+
* Defaults to reference equality (`isEqual`). Pass a comparator (e.g.
|
|
175
|
+
* `(a, b) => a.id === b.id`) for value-based equality, or `false` to
|
|
176
|
+
* notify on every recompute regardless of equality.
|
|
177
|
+
*/
|
|
105
178
|
equals?: false | ((prev: T, next: T) => boolean);
|
|
106
179
|
/** Callback invoked when the computed loses all subscribers */
|
|
107
180
|
unobserved?: () => void;
|
|
@@ -114,6 +187,40 @@ export interface MemoOptions<T> {
|
|
|
114
187
|
* never autodispose.
|
|
115
188
|
*/
|
|
116
189
|
lazy?: boolean;
|
|
190
|
+
/**
|
|
191
|
+
* Advanced. When true, asserts the compute function returns synchronous
|
|
192
|
+
* values only (never `PromiseLike` / `AsyncIterable`). Skips the
|
|
193
|
+
* async-shape probe in `recompute` for a small fixed-cost win per run.
|
|
194
|
+
* Intended for compiler emissions (`_$memo`) and library code that
|
|
195
|
+
* provably returns sync values. Returning a Promise or async iterable
|
|
196
|
+
* from a `sync: true` memo is undefined behavior — the value will be
|
|
197
|
+
* stored as-is and never awaited.
|
|
198
|
+
*/
|
|
199
|
+
sync?: boolean;
|
|
200
|
+
/**
|
|
201
|
+
* Commit #0: a committed value the memo is born with, shown until the
|
|
202
|
+
* compute's first real answer lands. While that first answer is in flight
|
|
203
|
+
* the memo reads as a settled value everywhere — nothing suspends to a
|
|
204
|
+
* `<Loading>` boundary, no transition is held (first-flight work is
|
|
205
|
+
* loading-class, like a boundary fallback), and `isPending(memo)` stays
|
|
206
|
+
* **false**: commit #0 answers the question by declaration, so first-load
|
|
207
|
+
* affordances are driven from the value itself (a `null` placeholder, a
|
|
208
|
+
* `skeleton: true` field, etc.). Once the first answer lands, the loading
|
|
209
|
+
* value leaves the lineage forever: refetches use normal pending semantics
|
|
210
|
+
* (stale value shown, `isPending` true, boundaries/transitions coordinate)
|
|
211
|
+
* — the canonical guard is `data.skeleton || isPending(data)`, whose two
|
|
212
|
+
* terms cover the two disjoint states.
|
|
213
|
+
*
|
|
214
|
+
* Typed strictly as `T`: to use `null`/`undefined` as the placeholder,
|
|
215
|
+
* declare it in the memo's type (e.g. `createMemo<User | null>(...)`), so
|
|
216
|
+
* every consumer sees the nullable window honestly. If the placeholder is
|
|
217
|
+
* shaped data standing in for real data, encode its provenance in the data
|
|
218
|
+
* (e.g. a `skeleton: true` field) rather than letting it impersonate truth.
|
|
219
|
+
*
|
|
220
|
+
* The loading value is also the compute's first `prev`, so `prev`-based
|
|
221
|
+
* memos fold from it.
|
|
222
|
+
*/
|
|
223
|
+
loadingValue?: T;
|
|
117
224
|
}
|
|
118
225
|
export type NoInfer<T extends any> = [T][T extends any ? 0 : never];
|
|
119
226
|
/**
|
|
@@ -162,7 +269,7 @@ export declare function createSignal<T>(fn: ComputeFunction<T>, options?: Signal
|
|
|
162
269
|
* const value = createMemo<T>(compute, options?: MemoOptions<T>);
|
|
163
270
|
* ```
|
|
164
271
|
* @param compute a function that receives its previous value and returns a new value used to react on a computation
|
|
165
|
-
* @param options `MemoOptions` -- id, name, equals, unobserved, lazy
|
|
272
|
+
* @param options `MemoOptions` -- id, name, equals, unobserved, lazy, transparent
|
|
166
273
|
*
|
|
167
274
|
* @example
|
|
168
275
|
* ```ts
|
|
@@ -185,7 +292,10 @@ export declare function createSignal<T>(fn: ComputeFunction<T>, options?: Signal
|
|
|
185
292
|
*
|
|
186
293
|
* @description https://docs.solidjs.com/reference/basic-reactivity/create-memo
|
|
187
294
|
*/
|
|
188
|
-
export declare function createMemo<T>(compute: ComputeFunction<
|
|
295
|
+
export declare function createMemo<T>(compute: ComputeFunction<NoInfer<T>, T>, options: MemoOptions<T> & {
|
|
296
|
+
loadingValue: T;
|
|
297
|
+
}): SourceAccessor<T>;
|
|
298
|
+
export declare function createMemo<T>(compute: ComputeFunction<undefined | NoInfer<T>, T>, options?: MemoOptions<T>): SourceAccessor<T>;
|
|
189
299
|
/**
|
|
190
300
|
* Creates a reactive effect with **separate compute and effect phases**.
|
|
191
301
|
*
|
|
@@ -202,14 +312,31 @@ export declare function createMemo<T>(compute: ComputeFunction<undefined | NoInf
|
|
|
202
312
|
* `createTrackedEffect` (with the tradeoffs noted there).
|
|
203
313
|
*
|
|
204
314
|
* Pass an `EffectBundle` (`{ effect, error }`) instead of a plain function to
|
|
205
|
-
* intercept errors thrown
|
|
315
|
+
* intercept **compute-phase** errors — errors thrown by `compute` or arriving
|
|
316
|
+
* from upstream reactive sources (including async rejections), which your own
|
|
317
|
+
* code has no frame to `try/catch`. The `error` handler is the error arm of
|
|
318
|
+
* the effect phase: it runs on the same schedule and in the same imperative,
|
|
319
|
+
* writable scope as `effect` (setting error state via signals is fine), and
|
|
320
|
+
* only for *settled* errors — a transient error that recovers before the
|
|
321
|
+
* effect phase runs `effect` with the recovered value instead, and a held
|
|
322
|
+
* transition defers it exactly as it defers `effect`. Without an `error`
|
|
323
|
+
* handler a compute-phase error is logged and the effect simply skips that
|
|
324
|
+
* run — a non-render effect's reactivity failing does not crash the app.
|
|
325
|
+
* Rethrowing from `error` escalates it to the nearest error boundary
|
|
326
|
+
* (halting the system if none exists).
|
|
327
|
+
*
|
|
328
|
+
* The **effect phase is different**: it is your own imperative code, so handle
|
|
329
|
+
* failures with `try/catch` where they occur. An uncaught effect-phase throw
|
|
330
|
+
* is treated as an unhandled application error — caught by the nearest
|
|
331
|
+
* `createErrorBoundary`/`<Errored>`, and permanently halting the reactive
|
|
332
|
+
* system if there is none. It is *not* routed to the bundle's `error` handler.
|
|
206
333
|
*
|
|
207
334
|
* ```typescript
|
|
208
335
|
* createEffect<T>(compute, effectFn | { effect, error }, options?: EffectOptions);
|
|
209
336
|
* ```
|
|
210
337
|
* @param compute a function that receives its previous value and returns a new value used to react on a computation
|
|
211
338
|
* @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
|
|
212
|
-
* @param options `EffectOptions` -- name, defer, schedule
|
|
339
|
+
* @param options `EffectOptions` -- name, defer, schedule, transparent
|
|
213
340
|
*
|
|
214
341
|
* @example
|
|
215
342
|
* ```ts
|
|
@@ -253,12 +380,28 @@ export declare function createEffect<T>(compute: ComputeFunction<undefined | NoI
|
|
|
253
380
|
* Creates a reactive computation that runs during the render phase as DOM elements
|
|
254
381
|
* are created and updated but not necessarily connected.
|
|
255
382
|
*
|
|
383
|
+
* Same compute / effect split as `createEffect`, but scheduled inside the render
|
|
384
|
+
* queue rather than after it. Reach for this only when authoring renderer
|
|
385
|
+
* plumbing (custom DOM bindings, JSX-generated `insert()` / `spread()` calls).
|
|
386
|
+
* App code should use `createEffect`.
|
|
387
|
+
*
|
|
256
388
|
* ```typescript
|
|
257
389
|
* createRenderEffect<T>(compute, effectFn, options?: EffectOptions);
|
|
258
390
|
* ```
|
|
259
391
|
* @param compute a function that receives its previous value and returns a new value used to react on a computation
|
|
260
392
|
* @param effectFn a function that receives the new value and is used to perform side effects
|
|
261
|
-
* @param options `EffectOptions` -- name, defer, schedule
|
|
393
|
+
* @param options `EffectOptions` -- name, defer, schedule, transparent
|
|
394
|
+
*
|
|
395
|
+
* @example
|
|
396
|
+
* ```ts
|
|
397
|
+
* // Custom directive: bind an element's textContent to a reactive source.
|
|
398
|
+
* function bindText(el: HTMLElement, source: () => string) {
|
|
399
|
+
* createRenderEffect(
|
|
400
|
+
* () => source(),
|
|
401
|
+
* value => { el.textContent = value; }
|
|
402
|
+
* );
|
|
403
|
+
* }
|
|
404
|
+
* ```
|
|
262
405
|
*
|
|
263
406
|
* @description https://docs.solidjs.com/reference/secondary-primitives/create-render-effect
|
|
264
407
|
*/
|
|
@@ -324,7 +467,9 @@ export declare function createReaction(effectFn: EffectFunction<undefined> | Eff
|
|
|
324
467
|
* Awaits a reactive expression and returns its first fully-settled value as a
|
|
325
468
|
* `Promise`. Pending async reads (`createMemo` returning a promise, etc.) are
|
|
326
469
|
* waited on; once the expression returns synchronously without `NotReadyError`
|
|
327
|
-
* the promise resolves with that value.
|
|
470
|
+
* the promise resolves with that value. If the expression settles with an
|
|
471
|
+
* error instead — including an async source that rejects — the promise
|
|
472
|
+
* rejects with it.
|
|
328
473
|
*
|
|
329
474
|
* Must be called *outside* a tracking scope — it doesn't subscribe, it just
|
|
330
475
|
* resolves the current value once.
|
|
@@ -400,6 +545,13 @@ export declare function createOptimistic<T>(fn: ComputeFunction<T>, options?: Si
|
|
|
400
545
|
* `onCleanup` is **not** allowed inside the callback — return a cleanup
|
|
401
546
|
* function instead. The returned cleanup runs on owner disposal.
|
|
402
547
|
*
|
|
548
|
+
* A cleanup return is only honored when `onSettled` is called from an **owned**
|
|
549
|
+
* scope (e.g. a component body). When it fires out of band from an *unowned*
|
|
550
|
+
* scope — an event handler, a tracked effect, or another `onSettled` — there is
|
|
551
|
+
* no owner lifecycle to bind a cleanup to; returning one is a dev-mode error
|
|
552
|
+
* (and is dropped in production). Use the post-settle/event-handler forms below
|
|
553
|
+
* for one-shot work, and keep setup-with-teardown in an owned scope.
|
|
554
|
+
*
|
|
403
555
|
* @example
|
|
404
556
|
* ```tsx
|
|
405
557
|
* // Component-level setup + teardown — replaces onMount + onCleanup.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { Store, StoreSetter, StoreNode, StoreOptions, ProjectionOptions, NotWrappable, SolidStore } from "./store.cjs";
|
|
1
|
+
export type { Store, StoreReturn, ProjectionStoreReturn, StoreSetter, StoreNode, StoreOptions, ProjectionOptions, NotWrappable, SolidStore } from "./store.cjs";
|
|
2
2
|
export type { Merge, Omit } from "./utils.cjs";
|
|
3
3
|
export { isWrappable, createStore, $TRACK, $PROXY, $TARGET } from "./store.cjs";
|
|
4
4
|
export { createProjection } from "./projection.cjs";
|
|
@@ -14,8 +14,8 @@ import { type NoFn, type ProjectionOptions, type Store, type StoreSetter } from
|
|
|
14
14
|
* optimistic overlay reverts after each transition.
|
|
15
15
|
*
|
|
16
16
|
* `options.key` defaults to `"id"`; specify it only when your data uses a
|
|
17
|
-
* different identity field (e.g. `{ key: "uuid" }` or `{ key: t => t.slug }`)
|
|
18
|
-
* Restating the default just adds noise.
|
|
17
|
+
* different identity field (e.g. `{ key: "uuid" }` or `{ key: t => t.slug }`),
|
|
18
|
+
* or `null` to merge positionally. Restating the default just adds noise.
|
|
19
19
|
*
|
|
20
20
|
* @example
|
|
21
21
|
* ```ts
|
|
@@ -41,5 +41,5 @@ import { type NoFn, type ProjectionOptions, type Store, type StoreSetter } from
|
|
|
41
41
|
*
|
|
42
42
|
* @returns `[store: Store<T>, setStore: StoreSetter<T>]`
|
|
43
43
|
*/
|
|
44
|
-
export declare function createOptimisticStore<T extends object = {}>(store: NoFn<T> | Store<NoFn<T
|
|
44
|
+
export declare function createOptimisticStore<T extends object = {}>(store: NoFn<T> | Store<NoFn<T>>, options?: ProjectionOptions): [get: Store<T>, set: StoreSetter<T>];
|
|
45
45
|
export declare function createOptimisticStore<T extends object = {}>(fn: (store: T) => void | T | Promise<void | T> | AsyncIterable<void | T>, store: Partial<T> | Store<NoFn<T>>, options?: ProjectionOptions): [get: Refreshable<Store<T>>, set: StoreSetter<T>];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Computed, type Refreshable } from "../core/index.cjs";
|
|
2
|
-
import { type ProjectionOptions, type Store } from "./store.cjs";
|
|
2
|
+
import { type NoFn, type ProjectionOptions, type Store } from "./store.cjs";
|
|
3
3
|
export declare function createProjectionInternal<T extends object = {}>(fn: (draft: T) => void | T | Promise<void | T> | AsyncIterable<void | T>, seed: Partial<T>, options?: ProjectionOptions): {
|
|
4
4
|
store: Refreshable<Store<T>>;
|
|
5
5
|
node: Computed<void | T>;
|
|
@@ -12,6 +12,10 @@ export declare function createProjectionInternal<T extends object = {}>(fn: (dra
|
|
|
12
12
|
* items keep their proxy identity — only added/removed items are
|
|
13
13
|
* created/disposed.
|
|
14
14
|
*
|
|
15
|
+
* If the derive returns a different entity than the one currently held (the
|
|
16
|
+
* `/users/1` → `/users/2` shape), the store swaps to it rather than merging,
|
|
17
|
+
* and nothing below it is treated as surviving.
|
|
18
|
+
*
|
|
15
19
|
* Returns the projected store directly (no setter — reads only).
|
|
16
20
|
*
|
|
17
21
|
* Use this when you want the structural-sharing / per-property tracking
|
|
@@ -24,7 +28,8 @@ export declare function createProjectionInternal<T extends object = {}>(fn: (dra
|
|
|
24
28
|
* @param seed the backing store value to wrap and reconcile into
|
|
25
29
|
* @param options `ProjectionOptions` — `name`, `key`. `key` defaults to
|
|
26
30
|
* `"id"`; specify it only when your data uses a different identity field
|
|
27
|
-
* (e.g. `{ key: "uuid" }` or `{ key: u => u.slug }`)
|
|
31
|
+
* (e.g. `{ key: "uuid" }` or `{ key: u => u.slug }`), or `null` to merge
|
|
32
|
+
* positionally with no keyed pass.
|
|
28
33
|
*
|
|
29
34
|
* @example
|
|
30
35
|
* ```ts
|
|
@@ -47,7 +52,7 @@ export declare function createProjectionInternal<T extends object = {}>(fn: (dra
|
|
|
47
52
|
*
|
|
48
53
|
* @see {@link https://github.com/solidjs/x-reactivity#createprojection}
|
|
49
54
|
*/
|
|
50
|
-
export declare function createProjection<T extends object = {}>(fn: (draft: T) => void | T | Promise<void | T> | AsyncIterable<void | T>, seed: Partial<T
|
|
55
|
+
export declare function createProjection<T extends object = {}>(fn: (draft: T) => void | T | Promise<void | T> | AsyncIterable<void | T>, seed: Partial<T> | Store<NoFn<T>>, options?: ProjectionOptions): Refreshable<Store<T>>;
|
|
51
56
|
/**
|
|
52
57
|
* Shared projection computed body used by both `createProjection` and the derived
|
|
53
58
|
* form of `createOptimisticStore`. Encapsulates the write-trap draft, `storeSetter`
|
|
@@ -61,6 +66,5 @@ export declare function createProjection<T extends object = {}>(fn: (draft: T) =
|
|
|
61
66
|
* instead of `STORE_OPTIMISTIC_OVERRIDE` even when an async yield fires outside
|
|
62
67
|
* the outer `setProjectionWriteActive` scope.
|
|
63
68
|
*/
|
|
64
|
-
export declare function runProjectionComputed<T extends object>(wrappedStore: Store<T>, fn: (draft: T) => void | T | Promise<void | T> | AsyncIterable<void | T>, key: string | ((item: NonNullable<any>) => any), wrapCommit?: (write: () => void) => void): Computed<void | T>;
|
|
65
|
-
export declare function createWriteTraps(isActive?: () => boolean): ProxyHandler<any>;
|
|
66
|
-
export declare const writeTraps: ProxyHandler<any>;
|
|
69
|
+
export declare function runProjectionComputed<T extends object>(wrappedStore: Store<T>, fn: (draft: T) => void | T | Promise<void | T> | AsyncIterable<void | T>, key: string | ((item: NonNullable<any>) => any) | null, wrapCommit?: (write: () => void) => void, onDraftWrite?: () => void): Computed<void | T>;
|
|
70
|
+
export declare function createWriteTraps(isActive?: () => boolean, onDraftWrite?: () => void): ProxyHandler<any>;
|
|
@@ -1,14 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared body of `reconcile()` and the projection commit. `replace` is the
|
|
3
|
+
* only difference: a projection commit is a value swap, not a merge — its root
|
|
4
|
+
* proxy is a cell handed out by `createProjection` that can never change
|
|
5
|
+
* reference, so a derive returning a different entity is not the slot mistake
|
|
6
|
+
* `reconcile()` throws on. Nothing below the root survives that swap, which is
|
|
7
|
+
* the rule the keyed diff already applies at a nested slot on a key mismatch.
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export declare function reconcileState(value: any, state: any, key: any, replace: boolean): void;
|
|
1
12
|
/**
|
|
2
13
|
* Returns a draft-mutating function that smart-merges `value` into a store,
|
|
3
|
-
* preserving
|
|
4
|
-
* new states. Useful when applying server payloads or full-replacement data
|
|
5
|
-
* onto an existing store without losing fine-grained reactivity.
|
|
14
|
+
* preserving fine-grained reactivity: only changed leaves trigger updates.
|
|
6
15
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
16
|
+
* With a `key` (default `"id"`), array items whose key matches between old
|
|
17
|
+
* and new states keep their identity (updated in place, moves and removals
|
|
18
|
+
* update the corresponding signals) — the shape for keyed server payloads.
|
|
19
|
+
* Items without the key field fall back to positional matching.
|
|
20
|
+
*
|
|
21
|
+
* With `key: null`, matching is purely positional: index N of the new array
|
|
22
|
+
* merges into index N of the old, and object properties merge recursively —
|
|
23
|
+
* the classic pattern for fixed-shape data that churns in place (dashboards,
|
|
24
|
+
* monitors), where no keyed diff pass is needed or wanted.
|
|
25
|
+
*
|
|
26
|
+
* Merging into a slot that holds a *different* entity throws — the caller
|
|
27
|
+
* picked the slot, so a key mismatch there is a bug.
|
|
9
28
|
*
|
|
10
29
|
* @param value the next state to merge in
|
|
11
|
-
* @param key property name (string) or extractor function for stable
|
|
30
|
+
* @param key property name (string) or extractor function for stable
|
|
31
|
+
* identity (default `"id"`); pass `null` for positional merging
|
|
12
32
|
*
|
|
13
33
|
* @example
|
|
14
34
|
* ```ts
|
|
@@ -16,8 +36,11 @@
|
|
|
16
36
|
*
|
|
17
37
|
* async function refresh() {
|
|
18
38
|
* const fresh = await api.getTodos();
|
|
19
|
-
* setTodos(reconcile(fresh
|
|
39
|
+
* setTodos(reconcile(fresh)); // diff-merge by `id`
|
|
20
40
|
* }
|
|
41
|
+
*
|
|
42
|
+
* // fixed-shape polling data — positional merge
|
|
43
|
+
* setStats(reconcile(nextStats, null));
|
|
21
44
|
* ```
|
|
22
45
|
*/
|
|
23
|
-
export declare function reconcile<T extends U, U>(value: T, key
|
|
46
|
+
export declare function reconcile<T extends U, U>(value: T, key?: string | ((item: NonNullable<any>) => any) | null): (state: U) => void;
|