@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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Computed, type Refreshable } from "../core/index.js";
|
|
2
|
-
import { type ProjectionOptions, type Store } from "./store.js";
|
|
2
|
+
import { type NoFn, type ProjectionOptions, type Store } from "./store.js";
|
|
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;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { STORE_SNAPSHOT_PROPS, type Computed, type Refreshable, type Signal } from "../core/index.js";
|
|
2
|
+
import { type Transition } from "../core/scheduler.js";
|
|
2
3
|
/** A read-only view of a store's value as seen by consumers. Mutate it via the paired `StoreSetter`. */
|
|
3
4
|
export type Store<T> = Readonly<T>;
|
|
4
5
|
/**
|
|
@@ -17,6 +18,10 @@ export type Store<T> = Readonly<T>;
|
|
|
17
18
|
* whose derive function reconciles its return by `options.key`.
|
|
18
19
|
*/
|
|
19
20
|
export type StoreSetter<T> = (fn: (state: T) => T | void) => void;
|
|
21
|
+
/** Tuple returned by the plain `createStore(initialValue)` form. */
|
|
22
|
+
export type StoreReturn<T> = [get: Store<T>, set: StoreSetter<T>];
|
|
23
|
+
/** Tuple returned by the derived `createStore(fn, seed, options?)` form. */
|
|
24
|
+
export type ProjectionStoreReturn<T> = [get: Refreshable<Store<T>>, set: StoreSetter<T>];
|
|
20
25
|
/** Base options for store primitives. */
|
|
21
26
|
export interface StoreOptions {
|
|
22
27
|
/** Debug name (dev mode only) */
|
|
@@ -24,26 +29,53 @@ export interface StoreOptions {
|
|
|
24
29
|
}
|
|
25
30
|
/** Options for derived/projected stores created with `createStore(fn)`, `createProjection`, or `createOptimisticStore(fn)`. */
|
|
26
31
|
export interface ProjectionOptions extends StoreOptions {
|
|
27
|
-
/** Key property name or function for reconciliation identity */
|
|
28
|
-
key?: string | ((item: NonNullable<any>) => any);
|
|
32
|
+
/** Key property name or function for reconciliation identity; `null` merges positionally */
|
|
33
|
+
key?: string | ((item: NonNullable<any>) => any) | null;
|
|
34
|
+
/** Single-layer store: root keys reactive, values raw records replaced by reference */
|
|
35
|
+
shallow?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Treat the seed as commit #0: the store is born committed with the seed's
|
|
38
|
+
* contents, shown until the derive's first real answer lands. While that
|
|
39
|
+
* first answer is in flight, reads serve the seed everywhere — nothing
|
|
40
|
+
* suspends to a `<Loading>` boundary, no transition is held, and
|
|
41
|
+
* `isPending` stays false (the seed answers by declaration; first-load
|
|
42
|
+
* affordances belong to the data, e.g. a `skeleton: true` field in the
|
|
43
|
+
* seed). Once the first answer lands (reconciled into the seed), refetches
|
|
44
|
+
* use normal pending semantics with `isPending` true.
|
|
45
|
+
*
|
|
46
|
+
* The store equivalent of `MemoOptions.loadingValue`; the seed already
|
|
47
|
+
* carries the placeholder shape, so this is just the opt-in.
|
|
48
|
+
*/
|
|
49
|
+
seedLoadingValue?: boolean;
|
|
29
50
|
}
|
|
30
51
|
export type NoFn<T> = T extends Function ? never : T;
|
|
31
52
|
type DataNode = Signal<any>;
|
|
32
53
|
type DataNodes = Record<PropertyKey, DataNode>;
|
|
33
|
-
|
|
34
|
-
|
|
54
|
+
/**
|
|
55
|
+
* Brand symbols used internally by the store proxy / projection plumbing.
|
|
56
|
+
* Cross-package wiring; not part of the user-facing API.
|
|
57
|
+
*
|
|
58
|
+
* @internal
|
|
59
|
+
*/
|
|
60
|
+
export declare const $TRACK: unique symbol, $TARGET: unique symbol, $PROXY: unique symbol, $DELETED: unique symbol, $AFFECTS: unique symbol;
|
|
61
|
+
export declare const STORE_VALUE = "v", STORE_OVERRIDE = "o", STORE_OPTIMISTIC_OVERRIDE = "x", STORE_NODE = "n", STORE_HAS = "h", STORE_CUSTOM_PROTO = "c", STORE_WRAP = "w", STORE_LOOKUP = "l", STORE_FIREWALL = "f", STORE_OPTIMISTIC = "p", STORE_OPTIMISTIC_OWNERS = "t", STORE_PARENT = "u", STORE_DESC = "d", STORE_SHALLOW = "s";
|
|
35
62
|
export type StoreNode = {
|
|
36
63
|
[$PROXY]: any;
|
|
37
64
|
[STORE_VALUE]: Record<PropertyKey, any>;
|
|
38
65
|
[STORE_OVERRIDE]?: Record<PropertyKey, any>;
|
|
39
66
|
[STORE_OPTIMISTIC_OVERRIDE]?: Record<PropertyKey, any>;
|
|
67
|
+
[STORE_OPTIMISTIC_OWNERS]?: Record<PropertyKey, Transition | null>;
|
|
40
68
|
[STORE_NODE]?: DataNodes;
|
|
41
69
|
[STORE_HAS]?: DataNodes;
|
|
70
|
+
[STORE_CUSTOM_PROTO]?: boolean;
|
|
42
71
|
[STORE_WRAP]?: (value: any, target?: StoreNode) => any;
|
|
43
72
|
[STORE_LOOKUP]?: WeakMap<any, any>;
|
|
44
73
|
[STORE_FIREWALL]?: Computed<any>;
|
|
45
74
|
[STORE_OPTIMISTIC]?: boolean;
|
|
46
75
|
[STORE_SNAPSHOT_PROPS]?: Record<PropertyKey, any>;
|
|
76
|
+
[STORE_PARENT]?: StoreNode;
|
|
77
|
+
[STORE_SHALLOW]?: boolean;
|
|
78
|
+
[STORE_DESC]?: boolean;
|
|
47
79
|
};
|
|
48
80
|
export declare namespace SolidStore {
|
|
49
81
|
interface Unwrappable {
|
|
@@ -52,11 +84,72 @@ export declare namespace SolidStore {
|
|
|
52
84
|
export type NotWrappable = string | number | bigint | symbol | boolean | Function | null | undefined | SolidStore.Unwrappable[keyof SolidStore.Unwrappable];
|
|
53
85
|
export declare function createStoreProxy<T extends object>(value: T, traps?: ProxyHandler<StoreNode>, extend?: (target: StoreNode) => void): any;
|
|
54
86
|
export declare const storeLookup: WeakMap<WeakKey, any>;
|
|
87
|
+
export declare const symbolKeyedRecords: WeakSet<object>;
|
|
88
|
+
export declare function lookupTarget(value: any, lookup?: WeakMap<any, any>): StoreNode | undefined;
|
|
89
|
+
/**
|
|
90
|
+
* Marks a value as raw: no store will ever wrap it — every store presents it
|
|
91
|
+
* as-is, tracked by reference at whatever slot holds it and updated by
|
|
92
|
+
* replacement. Useful for class instances and external objects (editors,
|
|
93
|
+
* scene graphs, Maps) and for record-shaped data updated wholesale. Sticky
|
|
94
|
+
* for the value's lifetime.
|
|
95
|
+
*/
|
|
96
|
+
export declare let rawValuesUsed: boolean;
|
|
97
|
+
export declare function isRawValue(value: any): boolean;
|
|
98
|
+
export declare function markRaw<T>(value: T): T;
|
|
99
|
+
export declare function markRawIngest(container: any): void;
|
|
55
100
|
export declare function wrap<T extends Record<PropertyKey, any>>(value: T, target?: StoreNode): T;
|
|
101
|
+
export declare function wrapShallow<T extends Record<PropertyKey, any>>(value: T): T;
|
|
56
102
|
export declare function isWrappable<T>(obj: T | NotWrappable): obj is T;
|
|
57
103
|
export declare function setWriteOverride(value: boolean): void;
|
|
104
|
+
export declare function ownEnumerableKeys(o: object): (string | symbol)[];
|
|
105
|
+
/**
|
|
106
|
+
* Single chokepoint for the store's layered value resolution: returns the
|
|
107
|
+
* override layer (optimistic first, then regular) that shadows `property`, or
|
|
108
|
+
* `undefined` when the base `STORE_VALUE` is authoritative. Every trap must
|
|
109
|
+
* resolve through this — hand-inlining the layer order is how the optimistic
|
|
110
|
+
* layer gets missed (#2850).
|
|
111
|
+
*/
|
|
112
|
+
export declare function getOverlayLayer(target: StoreNode, property: PropertyKey): Record<PropertyKey, any> | undefined;
|
|
113
|
+
/**
|
|
114
|
+
* The value a store leaf's backing signal currently shows to readers: active
|
|
115
|
+
* override, else held pending value, else committed value.
|
|
116
|
+
*/
|
|
117
|
+
export declare function visibleNodeValue(node: DataNode): any;
|
|
118
|
+
/**
|
|
119
|
+
* Witness live mark coverage of a record into the active isPending() probe.
|
|
120
|
+
* Tracked reads don't need this — they go through real signal nodes, which
|
|
121
|
+
* carry marks directly (declaration walk or birth inheritance). This covers
|
|
122
|
+
* UNTRACKED probes reading through records whose nodes never materialized
|
|
123
|
+
* (no observer ever subscribed, so no node exists to carry the mark).
|
|
124
|
+
* Callers guard on `pendingCheckActive`, so plain reads never pay for this.
|
|
125
|
+
*
|
|
126
|
+
* @internal
|
|
127
|
+
*/
|
|
128
|
+
export declare function witnessAffectsMark(target: StoreNode, property?: PropertyKey): void;
|
|
129
|
+
/**
|
|
130
|
+
* Resolves the store nodes an `affects()` declaration marks: with a `key`,
|
|
131
|
+
* the named slot's leaf node (upserted so the mark has an addressable
|
|
132
|
+
* carrier); without, the record's $AFFECTS carrier plus every LIVE node in
|
|
133
|
+
* its subtree (the edges existing readers subscribed through), with the
|
|
134
|
+
* subtree's identities snapshotted into the mark's scope so nodes created
|
|
135
|
+
* during the window — and untracked probes over captured proxies — resolve
|
|
136
|
+
* against it (#2882).
|
|
137
|
+
*
|
|
138
|
+
* @internal
|
|
139
|
+
*/
|
|
140
|
+
export declare function getStoreAffectsNodes(target: StoreNode, key?: PropertyKey): DataNode[];
|
|
58
141
|
export declare function trackSelf(target: StoreNode, symbol?: symbol): void;
|
|
142
|
+
export declare function notifySelf(target: StoreNode): void;
|
|
143
|
+
/**
|
|
144
|
+
* The write overlay a walk must read through: optimistic writes shadow
|
|
145
|
+
* regular pending writes, the same resolution order as every proxy trap and
|
|
146
|
+
* `reconcile` (#2850). Merging allocates only in the rare both-present case
|
|
147
|
+
* (a derived optimistic store with an in-flight projection commit).
|
|
148
|
+
*/
|
|
149
|
+
export declare function mergedOverlay(target: StoreNode): Record<PropertyKey, any> | undefined;
|
|
59
150
|
export declare function getKeys(source: Record<PropertyKey, any>, override: Record<PropertyKey, any> | undefined, enumerable?: boolean): PropertyKey[];
|
|
151
|
+
export declare function getStoreKeys(source: Record<PropertyKey, any>, override: Record<PropertyKey, any> | undefined): PropertyKey[];
|
|
152
|
+
export declare function getStoreSymbols(source: Record<PropertyKey, any>, override: Record<PropertyKey, any> | undefined): symbol[];
|
|
60
153
|
export declare function getPropertyDescriptor(source: Record<PropertyKey, any>, override: Record<PropertyKey, any> | undefined, property: PropertyKey): PropertyDescriptor | undefined;
|
|
61
154
|
export declare const storeTraps: ProxyHandler<StoreNode>;
|
|
62
155
|
export declare function storeSetter<T extends object>(store: Store<T>, fn: (draft: T) => T | void): void;
|
|
@@ -113,6 +206,8 @@ export declare function storeSetter<T extends object>(store: Store<T>, fn: (draf
|
|
|
113
206
|
*
|
|
114
207
|
* @returns `[store: Store<T>, setStore: StoreSetter<T>]`
|
|
115
208
|
*/
|
|
116
|
-
export declare function createStore<T extends object = {}>(store: NoFn<T> | Store<NoFn<T
|
|
117
|
-
|
|
209
|
+
export declare function createStore<T extends object = {}>(store: NoFn<T> | Store<NoFn<T>>, options?: StoreOptions & {
|
|
210
|
+
shallow?: boolean;
|
|
211
|
+
}): StoreReturn<T>;
|
|
212
|
+
export declare function createStore<T extends object = {}>(fn: (store: T) => void | T | Promise<void | T> | AsyncIterable<void | T>, store: Partial<T> | Store<NoFn<T>>, options?: ProjectionOptions): ProjectionStoreReturn<T>;
|
|
118
213
|
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Accessor } from "./signals.cjs";
|
|
2
|
+
import { type Store } from "./store/store.cjs";
|
|
3
|
+
/**
|
|
4
|
+
* Declares that in-flight work will change the targeted data: the named
|
|
5
|
+
* slot(s) — and everything DERIVED from them — read as pending
|
|
6
|
+
* (`isPending` → `true`) from the declaration until the surrounding
|
|
7
|
+
* transaction settles or reverts. A mark lives on its own channel — a
|
|
8
|
+
* refcount on the marked node plus dep-graph reachability in the verdict
|
|
9
|
+
* layer — so the marked values themselves stay readable (a mark is a promise
|
|
10
|
+
* of change, not an absence of value), no reader ever suspends on one, and
|
|
11
|
+
* completion/settlement accounting never sees one. This is the declaration
|
|
12
|
+
* verb of the pending model — additive only. A mark can turn pending ON for
|
|
13
|
+
* data the graph can't see changing yet; nothing can turn pending OFF while
|
|
14
|
+
* a real change is in flight — a quiet `refresh()` re-ask under a mark still
|
|
15
|
+
* reads pending (declaring the reload is what makes it a real question).
|
|
16
|
+
*
|
|
17
|
+
* Targets:
|
|
18
|
+
* - `affects(store)` — a store proxy (any record, root or nested): every
|
|
19
|
+
* record reachable from it at declaration time reads pending, including
|
|
20
|
+
* through captured child proxies (e.g. `<For>` rows). Siblings are
|
|
21
|
+
* untouched; records added after the declaration are not covered.
|
|
22
|
+
* - `affects(record, key)` — exactly the named slot of the record. One key
|
|
23
|
+
* per call (keys do NOT form a path — target the owning record directly).
|
|
24
|
+
* - `affects(accessor)` — a source accessor (signal or memo): the source
|
|
25
|
+
* reads pending.
|
|
26
|
+
*
|
|
27
|
+
* Typically called at the top of an `action` alongside optimistic writes —
|
|
28
|
+
* both are up-front declarations about the same mutation. Outside any
|
|
29
|
+
* transaction the mark is released at the end of the current flush.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* const send = action(function* (text: string) {
|
|
34
|
+
* setState(s => { s.messages.push({ text, status: "sending" }); });
|
|
35
|
+
* affects(state.messages.at(-1)!, "status"); // this slot pends until settle
|
|
36
|
+
* yield api.send(text);
|
|
37
|
+
* });
|
|
38
|
+
*
|
|
39
|
+
* const reload = action(function* () {
|
|
40
|
+
* affects(thing); // the whole store pends…
|
|
41
|
+
* refresh(thing); // …over this otherwise-quiet re-ask
|
|
42
|
+
* yield api.done();
|
|
43
|
+
* });
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function affects(target: Accessor<unknown> | Store<object>): void;
|
|
47
|
+
export declare function affects<T extends object>(target: Store<T>, key: keyof T): void;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Queue, type Computed, type Effect } from "./core/index.cjs";
|
|
2
2
|
import type { Signal } from "./core/index.cjs";
|
|
3
|
+
import { type Accessor } from "./signals.cjs";
|
|
3
4
|
export interface BoundaryComputed<T> extends Computed<T> {
|
|
4
5
|
_propagationMask: number;
|
|
5
6
|
}
|
|
@@ -19,18 +20,18 @@ export declare class RevealController {
|
|
|
19
20
|
_evaluating: boolean;
|
|
20
21
|
constructor(order: OrderAccessor, collapsed: BoolAccessor);
|
|
21
22
|
_forEachOwnedSlot(fn: (slot: RevealSlot) => boolean | void): boolean;
|
|
22
|
-
|
|
23
|
+
_isReady(): boolean;
|
|
23
24
|
/**
|
|
24
25
|
* "Minimally ready" = this group has something visible to show under its own policy.
|
|
25
26
|
* Used by an enclosing `together` group to decide when it can release.
|
|
26
|
-
* - `together`:
|
|
27
|
+
* - `together`: every direct slot is minimally ready.
|
|
27
28
|
* - `sequential`: the first owned slot is minimally ready (frontier can advance).
|
|
28
29
|
* - `natural`: any owned slot is minimally ready.
|
|
29
30
|
*/
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
_isMinimallyReady(): boolean;
|
|
32
|
+
_register(slot: RevealSlot): void;
|
|
33
|
+
_unregister(slot: RevealSlot): void;
|
|
34
|
+
_evaluate(disabledOverride?: boolean, collapsedOverride?: boolean): void;
|
|
34
35
|
}
|
|
35
36
|
export declare class CollectionQueue extends Queue {
|
|
36
37
|
_collectionType: number;
|
|
@@ -38,6 +39,7 @@ export declare class CollectionQueue extends Queue {
|
|
|
38
39
|
_tree?: BoundaryComputed<any>;
|
|
39
40
|
_pending: boolean;
|
|
40
41
|
_disabled: Signal<boolean>;
|
|
42
|
+
_error?: Signal<unknown>;
|
|
41
43
|
_collapsed: Signal<boolean>;
|
|
42
44
|
_revealController?: RevealController;
|
|
43
45
|
_initialized: boolean;
|
|
@@ -46,7 +48,7 @@ export declare class CollectionQueue extends Queue {
|
|
|
46
48
|
constructor(type: number);
|
|
47
49
|
run(type: number): void;
|
|
48
50
|
notify(node: Effect<any>, type: number, flags: number, error?: any): boolean;
|
|
49
|
-
|
|
51
|
+
_checkSources(): void;
|
|
50
52
|
}
|
|
51
53
|
/**
|
|
52
54
|
* Lower-level primitive that backs the `<Loading>` flow control. Catches
|
|
@@ -59,20 +61,45 @@ export declare class CollectionQueue extends Queue {
|
|
|
59
61
|
* @param fallback the fallback shown while async reads in `fn` are unresolved
|
|
60
62
|
* @param options `on` — accessor whose value scopes the boundary; when set,
|
|
61
63
|
* transitions caused by writes to other reactive sources are *not* caught
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```tsx
|
|
67
|
+
* // Custom boundary component built on top of the primitive.
|
|
68
|
+
* function MyLoading(props: { fallback: JSX.Element; children: JSX.Element }) {
|
|
69
|
+
* return createLoadingBoundary(
|
|
70
|
+
* () => props.children,
|
|
71
|
+
* () => props.fallback
|
|
72
|
+
* ) as unknown as JSX.Element;
|
|
73
|
+
* }
|
|
74
|
+
* ```
|
|
62
75
|
*/
|
|
63
|
-
export declare function createLoadingBoundary(fn: () =>
|
|
76
|
+
export declare function createLoadingBoundary<T, U>(fn: () => T, fallback: () => U, options?: {
|
|
64
77
|
on?: () => any;
|
|
65
|
-
}):
|
|
78
|
+
}): Accessor<T | U>;
|
|
66
79
|
/**
|
|
67
80
|
* Lower-level primitive that backs the `<Errored>` flow control. Catches
|
|
68
81
|
* thrown errors inside `fn` and invokes `fallback(error, reset)` instead.
|
|
69
|
-
* `
|
|
70
|
-
* recover.
|
|
82
|
+
* `error` is an accessor for the latest captured error; `reset()` recomputes
|
|
83
|
+
* the failing sources so the boundary can attempt to recover.
|
|
71
84
|
*
|
|
72
85
|
* App code should use `<Errored fallback={...}>` instead — reach for this only
|
|
73
86
|
* when authoring custom boundary components.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```tsx
|
|
90
|
+
* // Custom boundary that wraps the primitive and adds telemetry.
|
|
91
|
+
* function TracedErrored(props: { fallback: (e: () => unknown) => JSX.Element; children: JSX.Element }) {
|
|
92
|
+
* return createErrorBoundary(
|
|
93
|
+
* () => props.children,
|
|
94
|
+
* (err, reset) => {
|
|
95
|
+
* reportError(err());
|
|
96
|
+
* return props.fallback(err);
|
|
97
|
+
* }
|
|
98
|
+
* ) as unknown as JSX.Element;
|
|
99
|
+
* }
|
|
100
|
+
* ```
|
|
74
101
|
*/
|
|
75
|
-
export declare function createErrorBoundary<U>(fn: () =>
|
|
102
|
+
export declare function createErrorBoundary<T, U>(fn: () => T, fallback: (error: Accessor<unknown>, reset: () => void) => U): Accessor<T | U>;
|
|
76
103
|
/**
|
|
77
104
|
* Coordinate the reveal timing of sibling loading boundaries.
|
|
78
105
|
*
|
|
@@ -101,7 +128,18 @@ export declare function createErrorBoundary<U>(fn: () => any, fallback: (error:
|
|
|
101
128
|
* own minimal signal).
|
|
102
129
|
* - `together` — every direct slot is minimally ready.
|
|
103
130
|
* - `natural` — any direct slot has visible content (leaves on resolve; nested
|
|
104
|
-
* composites
|
|
131
|
+
* composites via their own minimal signal).
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```ts
|
|
135
|
+
* // Primitive form of `<Reveal>` — coordinate sibling loading boundaries
|
|
136
|
+
* // programmatically. App code uses the JSX `<Reveal>` component instead.
|
|
137
|
+
* // Both options are accessors so they can react to state changes.
|
|
138
|
+
* createRevealOrder(
|
|
139
|
+
* () => renderSiblings(),
|
|
140
|
+
* { order: () => mode(), collapsed: () => true }
|
|
141
|
+
* );
|
|
142
|
+
* ```
|
|
105
143
|
*/
|
|
106
144
|
export declare function createRevealOrder<T>(fn: () => T, options?: {
|
|
107
145
|
order?: OrderAccessor;
|
|
@@ -120,6 +158,15 @@ export declare function createRevealOrder<T>(fn: () => T, options?: {
|
|
|
120
158
|
* @param options
|
|
121
159
|
* - `skipNonRendered` — drop values that won't render
|
|
122
160
|
* - `doNotUnwrap` — leave function children as-is (caller will resolve)
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```ts
|
|
164
|
+
* // Custom renderer walking a children tree manually. Most authors should
|
|
165
|
+
* // use `children()` from solid-js, which memoizes the resolved value.
|
|
166
|
+
* function renderChildren(value: unknown): unknown {
|
|
167
|
+
* return flatten(value, { skipNonRendered: true });
|
|
168
|
+
* }
|
|
169
|
+
* ```
|
|
123
170
|
*/
|
|
124
171
|
export declare function flatten(children: any, options?: {
|
|
125
172
|
skipNonRendered?: boolean;
|
|
@@ -1,13 +1,41 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* The primitive for mutations: imperative async workflows whose *writes span
|
|
3
|
+
* an async gap* — optimistic write, server round-trip, reconciling write —
|
|
4
|
+
* where intermediate state must not leak and failure must revert cleanly
|
|
5
|
+
* (pair with `createOptimistic` / `createOptimisticStore`).
|
|
6
|
+
*
|
|
7
|
+
* Navigation-shaped updates do not need an action. A plain setter call is
|
|
8
|
+
* enough: reads pull the async, and downstream async computeds hold their
|
|
9
|
+
* previous values per-node until the new ones are ready (`isPending` /
|
|
10
|
+
* `latest` expose the in-flight state). Reach for `action` only when writes
|
|
11
|
+
* happen *after* async work, not merely upstream of it.
|
|
12
|
+
*
|
|
13
|
+
* Framework-level actions (router form actions, server actions) are
|
|
14
|
+
* specializations of this primitive: they are actions in exactly this sense —
|
|
15
|
+
* the same transactional semantics — with form binding, serialization, and
|
|
16
|
+
* submission tracking layered on top. The shared name is deliberate.
|
|
17
|
+
*
|
|
2
18
|
* Wraps a generator function so each invocation runs as a single transaction
|
|
3
19
|
* (a "transition") that batches every signal/store write between yields. The
|
|
4
20
|
* surrounding UI sees one atomic update per yielded step; nothing is committed
|
|
5
21
|
* until the action either completes or the next `yield` resolves.
|
|
6
22
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
23
|
+
* `yield` is the transaction-safe suspension point: the action waits for a
|
|
24
|
+
* yielded promise and re-enters the transaction before running the code after
|
|
25
|
+
* it. A plain `await` does NOT — the runtime has no hook into an async
|
|
26
|
+
* generator's internal await continuations, so writes to fresh signals
|
|
27
|
+
* between an `await` and the next `yield` escape the transaction and commit
|
|
28
|
+
* immediately. `await` is still the ergonomic choice for typed results; just
|
|
29
|
+
* put a bare `yield` before any writes that follow it:
|
|
30
|
+
*
|
|
31
|
+
* ```ts
|
|
32
|
+
* const saved = await api.createTodo(text); // typed result
|
|
33
|
+
* yield; // re-enter the transaction before writing
|
|
34
|
+
* setTodos(t => { ... });
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* (For the same reason, don't call `flush()` inside an action body — it
|
|
38
|
+
* drains the transaction mid-step.)
|
|
11
39
|
*
|
|
12
40
|
* Each call returns a `Promise` that resolves with the generator's return
|
|
13
41
|
* value, or rejects if it throws. Pair with `createOptimistic` /
|
|
@@ -18,10 +46,11 @@
|
|
|
18
46
|
* ```ts
|
|
19
47
|
* const [todos, setTodos] = createOptimisticStore<Todo[]>([]);
|
|
20
48
|
*
|
|
21
|
-
* const addTodo = action(function* (text: string) {
|
|
49
|
+
* const addTodo = action(async function* (text: string) {
|
|
22
50
|
* const tempId = crypto.randomUUID();
|
|
23
51
|
* setTodos(t => { t.push({ id: tempId, text, pending: true }); }); // optimistic
|
|
24
|
-
* const saved =
|
|
52
|
+
* const saved = await api.createTodo(text); // network round-trip, typed
|
|
53
|
+
* yield; // re-enter the transaction
|
|
25
54
|
* setTodos(t => {
|
|
26
55
|
* const i = t.findIndex(x => x.id === tempId);
|
|
27
56
|
* if (i >= 0) t[i] = saved;
|
|
@@ -1,6 +1,21 @@
|
|
|
1
|
+
import { NotReadyError } from "./error.cjs";
|
|
1
2
|
import { type OptimisticLane } from "./lanes.cjs";
|
|
2
|
-
import type { Computed } from "./types.cjs";
|
|
3
|
+
import type { Computed, Link } from "./types.cjs";
|
|
4
|
+
export declare function addPendingSource(el: Computed<any>, source: Computed<any>): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* A loading-window node hit an unready source (sync throw in recompute, or a
|
|
7
|
+
* NotReadyError-rejected flight): register for the source's settle — the
|
|
8
|
+
* settlePendingSource walk runs off `_pendingSources` + `_blocked` alone —
|
|
9
|
+
* with NO read-visible pending status, no downstream propagation, no
|
|
10
|
+
* transition, no lane registration. Commit #0 keeps serving.
|
|
11
|
+
*/
|
|
12
|
+
export declare function parkLoadingWindow(el: Computed<any>, e: NotReadyError): void;
|
|
13
|
+
export declare function setPendingError(el: Computed<any>, source?: Computed<any>, error?: any): void;
|
|
14
|
+
export declare function forEachDependent(el: Computed<any>, fn: (node: Computed<any>, link: Link) => void): void;
|
|
15
|
+
export declare function releaseSettledDependents(el: Computed<any>): void;
|
|
16
|
+
export declare function settleErroredDependents(el: Computed<any>, error: any): void;
|
|
3
17
|
export declare function settlePendingSource(el: Computed<any>): void;
|
|
18
|
+
export declare function isThenable<T>(value: T | PromiseLike<T>): value is PromiseLike<T>;
|
|
4
19
|
export declare function handleAsync<T>(el: Computed<T>, result: T | PromiseLike<T> | AsyncIterable<T>, setter?: (value: T) => void): T;
|
|
5
20
|
export declare function clearStatus(el: Computed<any>, clearUninitialized?: boolean): void;
|
|
6
21
|
export declare function notifyStatus(el: Computed<any>, status: number, error: any, blockStatus?: boolean, lane?: OptimisticLane): void;
|
|
@@ -9,12 +9,22 @@ export declare const REACTIVE_DISPOSED: number;
|
|
|
9
9
|
export declare const REACTIVE_OPTIMISTIC_DIRTY: number;
|
|
10
10
|
export declare const REACTIVE_SNAPSHOT_STALE: number;
|
|
11
11
|
export declare const REACTIVE_LAZY: number;
|
|
12
|
+
export declare const REACTIVE_MANUAL_WRITE: number;
|
|
13
|
+
/**
|
|
14
|
+
* The pending recompute is a re-ask of the same question: `refresh()` dirtied
|
|
15
|
+
* the node while no tracked input changed value. Cleared whenever a real
|
|
16
|
+
* value-change notification arrives (`insertSubs`), and consumed by
|
|
17
|
+
* `recompute` into the node's `_reask` classification — a quiet (re-ask)
|
|
18
|
+
* pending window does not read as pending (question-scoped pending model).
|
|
19
|
+
*/
|
|
20
|
+
export declare const REACTIVE_REASK: number;
|
|
12
21
|
export declare const CONFIG_OWNED_WRITE: number;
|
|
13
22
|
export declare const CONFIG_NO_SNAPSHOT: number;
|
|
14
23
|
export declare const CONFIG_TRANSPARENT: number;
|
|
15
24
|
export declare const CONFIG_IN_SNAPSHOT_SCOPE: number;
|
|
16
25
|
export declare const CONFIG_CHILDREN_FORBIDDEN: number;
|
|
17
26
|
export declare const CONFIG_AUTO_DISPOSE: number;
|
|
27
|
+
export declare const CONFIG_SYNC: number;
|
|
18
28
|
export declare const STATUS_NONE = 0;
|
|
19
29
|
export declare const STATUS_PENDING: number;
|
|
20
30
|
export declare const STATUS_ERROR: number;
|
|
@@ -25,17 +35,36 @@ export declare const EFFECT_USER = 2;
|
|
|
25
35
|
export declare const EFFECT_TRACKED = 3;
|
|
26
36
|
export declare const NOT_PENDING: {};
|
|
27
37
|
export declare const NO_SNAPSHOT: {};
|
|
38
|
+
/**
|
|
39
|
+
* Stand-in stored in `_overrideValue` for an optimistic write of literal
|
|
40
|
+
* `undefined` (#2898). The slot doubles as the optimistic-node brand
|
|
41
|
+
* (`undefined` = not optimistic, `NOT_PENDING` = at rest), so the raw value
|
|
42
|
+
* would erase the node's optimistic identity: the write turns invisible and
|
|
43
|
+
* follow-up writes route off the optimistic path and commit permanently.
|
|
44
|
+
* Same shape as NO_SNAPSHOT. Sites that surface the override VALUE unwrap
|
|
45
|
+
* via `visibleOverrideValue`; slot identity tests stay raw.
|
|
46
|
+
*/
|
|
47
|
+
export declare const OVERRIDE_UNDEFINED: {};
|
|
48
|
+
/** Unwrap an active override's stored value for surfacing to readers (#2898). */
|
|
49
|
+
export declare function unwrapOverride<T = any>(v: unknown): T;
|
|
28
50
|
export declare const STORE_SNAPSHOT_PROPS = "sp";
|
|
29
51
|
export declare const SUPPORTS_PROXY: boolean;
|
|
30
52
|
export declare const defaultContext: {};
|
|
53
|
+
/**
|
|
54
|
+
* Brand symbol used by `Refreshable<T>` values (projection stores, async
|
|
55
|
+
* memos) to expose their underlying computation to `refresh()`. Not part of
|
|
56
|
+
* the user-facing API.
|
|
57
|
+
*
|
|
58
|
+
* @internal
|
|
59
|
+
*/
|
|
31
60
|
export declare const $REFRESH: unique symbol;
|
|
32
61
|
/**
|
|
33
|
-
* Brand applied to
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
62
|
+
* Brand applied to values that participate in the `refresh()` re-run protocol.
|
|
63
|
+
* Accessors receive this handle internally; projected stores expose it through
|
|
64
|
+
* their public return type so user-defined hooks that wrap `createOptimisticStore`
|
|
65
|
+
* / `createProjection` / projection-form `createStore` can have their return
|
|
66
|
+
* types inferred without leaking the internal `$REFRESH` symbol into public type
|
|
67
|
+
* signatures (TS4058).
|
|
39
68
|
*/
|
|
40
69
|
export type Refreshable<T> = T & {
|
|
41
70
|
readonly [$REFRESH]: any;
|
|
@@ -14,15 +14,23 @@ export type ContextRecord = Record<string | symbol, unknown>;
|
|
|
14
14
|
*/
|
|
15
15
|
export declare function createContext<T>(defaultValue?: T, description?: string): Context<T>;
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
17
|
+
* Low-level owner-targeted context read. The user-facing read API is
|
|
18
|
+
* `useContext` (in `solid-js`), which wraps this primitive. Exposed here for
|
|
19
|
+
* cross-package wiring (e.g. hydration-aware context plumbing).
|
|
18
20
|
*
|
|
19
21
|
* @throws `NoOwnerError` if there's no owner at the time of call.
|
|
20
22
|
* @throws `ContextNotFoundError` if a context value has not been set yet.
|
|
23
|
+
*
|
|
24
|
+
* @internal
|
|
21
25
|
*/
|
|
22
26
|
export declare function getContext<T>(context: Context<T>, owner?: Owner | null): T;
|
|
23
27
|
/**
|
|
24
|
-
*
|
|
28
|
+
* Low-level owner-targeted context write. The user-facing API is
|
|
29
|
+
* `createContext` (in `solid-js`); its provider component wraps this
|
|
30
|
+
* primitive. Exposed here for cross-package wiring.
|
|
25
31
|
*
|
|
26
32
|
* @throws `NoOwnerError` if there's no owner at the time of call.
|
|
33
|
+
*
|
|
34
|
+
* @internal
|
|
27
35
|
*/
|
|
28
36
|
export declare function setContext<T>(context: Context<T>, value?: T, owner?: Owner | null): void;
|