@solidjs/signals 2.0.0-beta.8 → 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.
Files changed (95) hide show
  1. package/README.md +13 -9
  2. package/dist/dev.js +6078 -1440
  3. package/dist/node.cjs +7684 -3248
  4. package/dist/prod/affects.js +126 -0
  5. package/dist/prod/boundaries.js +572 -0
  6. package/dist/prod/core/action.js +139 -0
  7. package/dist/prod/core/async.js +553 -0
  8. package/dist/prod/core/constants.js +92 -0
  9. package/dist/prod/core/context.js +67 -0
  10. package/dist/prod/core/core.js +817 -0
  11. package/dist/prod/core/dev.js +3 -0
  12. package/dist/prod/core/effect.js +145 -0
  13. package/dist/prod/core/error.js +68 -0
  14. package/dist/prod/core/external.js +98 -0
  15. package/dist/prod/core/graph.js +104 -0
  16. package/dist/prod/core/heap.js +140 -0
  17. package/dist/prod/core/invariants.js +42 -0
  18. package/dist/prod/core/lanes.js +140 -0
  19. package/dist/prod/core/optimistic.js +245 -0
  20. package/dist/prod/core/owner.js +302 -0
  21. package/dist/prod/core/scheduler.js +749 -0
  22. package/dist/prod/core/verdict.js +369 -0
  23. package/dist/prod/index.js +45 -0
  24. package/dist/prod/map.js +317 -0
  25. package/dist/prod/signals.js +375 -0
  26. package/dist/prod/store/optimistic.js +217 -0
  27. package/dist/prod/store/projection.js +231 -0
  28. package/dist/prod/store/reconcile.js +707 -0
  29. package/dist/prod/store/store.js +1081 -0
  30. package/dist/prod/store/storePath.js +103 -0
  31. package/dist/prod/store/utils.js +328 -0
  32. package/dist/types/affects.d.ts +47 -0
  33. package/dist/types/boundaries.d.ts +93 -11
  34. package/dist/types/core/action.d.ts +63 -0
  35. package/dist/types/core/async.d.ts +16 -1
  36. package/dist/types/core/constants.d.ts +46 -0
  37. package/dist/types/core/context.d.ts +10 -2
  38. package/dist/types/core/core.d.ts +111 -17
  39. package/dist/types/core/dev.d.ts +17 -2
  40. package/dist/types/core/effect.d.ts +1 -2
  41. package/dist/types/core/error.d.ts +33 -0
  42. package/dist/types/core/external.d.ts +0 -11
  43. package/dist/types/core/graph.d.ts +2 -1
  44. package/dist/types/core/heap.d.ts +8 -0
  45. package/dist/types/core/index.d.ts +3 -2
  46. package/dist/types/core/invariants.d.ts +59 -0
  47. package/dist/types/core/lanes.d.ts +2 -0
  48. package/dist/types/core/optimistic.d.ts +6 -0
  49. package/dist/types/core/owner.d.ts +101 -3
  50. package/dist/types/core/scheduler.d.ts +97 -9
  51. package/dist/types/core/types.d.ts +68 -6
  52. package/dist/types/core/verdict.d.ts +2 -0
  53. package/dist/types/index.d.ts +4 -3
  54. package/dist/types/map.d.ts +50 -5
  55. package/dist/types/signals.d.ts +424 -19
  56. package/dist/types/store/index.d.ts +1 -1
  57. package/dist/types/store/optimistic.d.ts +39 -13
  58. package/dist/types/store/projection.d.ts +48 -18
  59. package/dist/types/store/reconcile.d.ts +46 -1
  60. package/dist/types/store/store.d.ts +164 -19
  61. package/dist/types/store/storePath.d.ts +28 -0
  62. package/dist/types/store/utils.d.ts +78 -7
  63. package/dist/types-cjs/affects.d.cts +47 -0
  64. package/dist/types-cjs/boundaries.d.cts +93 -11
  65. package/dist/types-cjs/core/action.d.cts +63 -0
  66. package/dist/types-cjs/core/async.d.cts +16 -1
  67. package/dist/types-cjs/core/constants.d.cts +46 -0
  68. package/dist/types-cjs/core/context.d.cts +10 -2
  69. package/dist/types-cjs/core/core.d.cts +111 -17
  70. package/dist/types-cjs/core/dev.d.cts +17 -2
  71. package/dist/types-cjs/core/effect.d.cts +1 -2
  72. package/dist/types-cjs/core/error.d.cts +33 -0
  73. package/dist/types-cjs/core/external.d.cts +0 -11
  74. package/dist/types-cjs/core/graph.d.cts +2 -1
  75. package/dist/types-cjs/core/heap.d.cts +8 -0
  76. package/dist/types-cjs/core/index.d.cts +3 -2
  77. package/dist/types-cjs/core/invariants.d.cts +59 -0
  78. package/dist/types-cjs/core/lanes.d.cts +2 -0
  79. package/dist/types-cjs/core/optimistic.d.cts +6 -0
  80. package/dist/types-cjs/core/owner.d.cts +101 -3
  81. package/dist/types-cjs/core/scheduler.d.cts +97 -9
  82. package/dist/types-cjs/core/types.d.cts +68 -6
  83. package/dist/types-cjs/core/verdict.d.cts +2 -0
  84. package/dist/types-cjs/index.d.cts +4 -3
  85. package/dist/types-cjs/map.d.cts +50 -5
  86. package/dist/types-cjs/signals.d.cts +424 -19
  87. package/dist/types-cjs/store/index.d.cts +1 -1
  88. package/dist/types-cjs/store/optimistic.d.cts +39 -13
  89. package/dist/types-cjs/store/projection.d.cts +48 -18
  90. package/dist/types-cjs/store/reconcile.d.cts +46 -1
  91. package/dist/types-cjs/store/store.d.cts +164 -19
  92. package/dist/types-cjs/store/storePath.d.cts +28 -0
  93. package/dist/types-cjs/store/utils.d.cts +78 -7
  94. package/package.json +14 -11
  95. package/dist/prod.js +0 -3577
@@ -1,27 +1,58 @@
1
- import { $REFRESH, type Computed } from "../core/index.js";
2
- import { type ProjectionOptions, type Store } from "./store.js";
1
+ import { type Computed, type Refreshable } from "../core/index.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
- store: Store<T> & {
5
- [$REFRESH]: any;
6
- };
4
+ store: Refreshable<Store<T>>;
7
5
  node: Computed<void | T>;
8
6
  };
9
7
  /**
10
- * Creates a mutable derived store (projection). The derive function receives a mutable
11
- * draft and can mutate it directly or return a new value for reconciliation.
8
+ * Creates a derived (projected) store. Like `createMemo` but for stores: the
9
+ * derive function receives a mutable draft and either mutates it in place
10
+ * (canonical) or returns a new value. Either way the result is reconciled
11
+ * against the previous draft by `options.key` (default `"id"`), so surviving
12
+ * items keep their proxy identity — only added/removed items are
13
+ * created/disposed.
12
14
  *
13
- * ```typescript
14
- * const store = createProjection<T>(fn, seed, options?: ProjectionOptions);
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
+ *
19
+ * Returns the projected store directly (no setter — reads only).
20
+ *
21
+ * Use this when you want the structural-sharing / per-property tracking
22
+ * behaviour of a store on top of a derived computation. For simple read-only
23
+ * derivations, `createMemo` is lighter.
24
+ *
25
+ * @param fn receives the current draft; mutate it in place or return new
26
+ * data. Return is convenient for filter/derive shapes where mutation is
27
+ * awkward.
28
+ * @param seed the backing store value to wrap and reconcile into
29
+ * @param options `ProjectionOptions` — `name`, `key`. `key` defaults to
30
+ * `"id"`; specify it only when your data uses a different identity field
31
+ * (e.g. `{ key: "uuid" }` or `{ key: u => u.slug }`), or `null` to merge
32
+ * positionally with no keyed pass.
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * // Mutation form — update individual fields on the draft.
37
+ * const summary = createProjection<{ total: number; active: number }>(
38
+ * draft => {
39
+ * draft.total = users().length;
40
+ * draft.active = users().filter(u => u.active).length;
41
+ * },
42
+ * { total: 0, active: 0 }
43
+ * );
44
+ *
45
+ * // Return form — produce a derived collection. Reconciled by `id` so each
46
+ * // surviving user keeps the same store identity across recomputes.
47
+ * const activeUsers = createProjection<User[]>(
48
+ * () => allUsers().filter(u => u.active),
49
+ * []
50
+ * );
15
51
  * ```
16
- * @param fn a function that receives the current draft and mutates it or returns new data
17
- * @param seed the backing store host value to wrap and reconcile into
18
- * @param options `ProjectionOptions` -- name, key
19
52
  *
20
53
  * @see {@link https://github.com/solidjs/x-reactivity#createprojection}
21
54
  */
22
- export declare function createProjection<T extends object = {}>(fn: (draft: T) => void | T | Promise<void | T> | AsyncIterable<void | T>, seed: Partial<T>, options?: ProjectionOptions): Store<T> & {
23
- [$REFRESH]: any;
24
- };
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>>;
25
56
  /**
26
57
  * Shared projection computed body used by both `createProjection` and the derived
27
58
  * form of `createOptimisticStore`. Encapsulates the write-trap draft, `storeSetter`
@@ -35,6 +66,5 @@ export declare function createProjection<T extends object = {}>(fn: (draft: T) =
35
66
  * instead of `STORE_OPTIMISTIC_OVERRIDE` even when an async yield fires outside
36
67
  * the outer `setProjectionWriteActive` scope.
37
68
  */
38
- 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>;
39
- export declare function createWriteTraps(isActive?: () => boolean): ProxyHandler<any>;
40
- 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 +1,46 @@
1
- export declare function reconcile<T extends U, U>(value: T, key: string | ((item: NonNullable<any>) => any)): (state: U) => void;
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;
12
+ /**
13
+ * Returns a draft-mutating function that smart-merges `value` into a store,
14
+ * preserving fine-grained reactivity: only changed leaves trigger updates.
15
+ *
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.
28
+ *
29
+ * @param value the next state to merge in
30
+ * @param key property name (string) or extractor function for stable
31
+ * identity (default `"id"`); pass `null` for positional merging
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * const [todos, setTodos] = createStore<Todo[]>([]);
36
+ *
37
+ * async function refresh() {
38
+ * const fresh = await api.getTodos();
39
+ * setTodos(reconcile(fresh)); // diff-merge by `id`
40
+ * }
41
+ *
42
+ * // fixed-shape polling data — positional merge
43
+ * setStats(reconcile(nextStats, null));
44
+ * ```
45
+ */
46
+ export declare function reconcile<T extends U, U>(value: T, key?: string | ((item: NonNullable<any>) => any) | null): (state: U) => void;
@@ -1,6 +1,27 @@
1
- import { $REFRESH, STORE_SNAPSHOT_PROPS, type Computed, type Signal } from "../core/index.js";
1
+ import { STORE_SNAPSHOT_PROPS, type Computed, type Refreshable, type Signal } from "../core/index.js";
2
+ import { type Transition } from "../core/scheduler.js";
3
+ /** A read-only view of a store's value as seen by consumers. Mutate it via the paired `StoreSetter`. */
2
4
  export type Store<T> = Readonly<T>;
5
+ /**
6
+ * A store setter. The callback receives a writable **draft** of the store.
7
+ *
8
+ * - **Mutate in place (canonical):** `s.foo = 1`, `s.list.push(x)`,
9
+ * `s.list.splice(i, 1)`. This is the default form for most updates.
10
+ * - **Return a new value:** for shapes where mutation is awkward, most
11
+ * commonly removing items (`s => s.list.filter(...)`). Arrays are replaced
12
+ * by index (length adjusted); objects are shallow-diffed at the top level
13
+ * (keys present in the returned value are written, missing keys deleted).
14
+ *
15
+ * The setter does **not** perform keyed reconciliation. If you need surviving
16
+ * items to keep their store identity across full-array replacement, use the
17
+ * projection form — `createStore(fn, seed, { key })` or `createProjection` —
18
+ * whose derive function reconciles its return by `options.key`.
19
+ */
3
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>];
4
25
  /** Base options for store primitives. */
5
26
  export interface StoreOptions {
6
27
  /** Debug name (dev mode only) */
@@ -8,26 +29,53 @@ export interface StoreOptions {
8
29
  }
9
30
  /** Options for derived/projected stores created with `createStore(fn)`, `createProjection`, or `createOptimisticStore(fn)`. */
10
31
  export interface ProjectionOptions extends StoreOptions {
11
- /** Key property name or function for reconciliation identity */
12
- 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;
13
50
  }
14
51
  export type NoFn<T> = T extends Function ? never : T;
15
52
  type DataNode = Signal<any>;
16
53
  type DataNodes = Record<PropertyKey, DataNode>;
17
- export declare const $TRACK: unique symbol, $TARGET: unique symbol, $PROXY: unique symbol, $DELETED: unique symbol;
18
- export declare const STORE_VALUE = "v", STORE_OVERRIDE = "o", STORE_OPTIMISTIC_OVERRIDE = "x", STORE_NODE = "n", STORE_HAS = "h", STORE_WRAP = "w", STORE_LOOKUP = "l", STORE_FIREWALL = "f", STORE_OPTIMISTIC = "p";
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";
19
62
  export type StoreNode = {
20
63
  [$PROXY]: any;
21
64
  [STORE_VALUE]: Record<PropertyKey, any>;
22
65
  [STORE_OVERRIDE]?: Record<PropertyKey, any>;
23
66
  [STORE_OPTIMISTIC_OVERRIDE]?: Record<PropertyKey, any>;
67
+ [STORE_OPTIMISTIC_OWNERS]?: Record<PropertyKey, Transition | null>;
24
68
  [STORE_NODE]?: DataNodes;
25
69
  [STORE_HAS]?: DataNodes;
70
+ [STORE_CUSTOM_PROTO]?: boolean;
26
71
  [STORE_WRAP]?: (value: any, target?: StoreNode) => any;
27
72
  [STORE_LOOKUP]?: WeakMap<any, any>;
28
73
  [STORE_FIREWALL]?: Computed<any>;
29
74
  [STORE_OPTIMISTIC]?: boolean;
30
75
  [STORE_SNAPSHOT_PROPS]?: Record<PropertyKey, any>;
76
+ [STORE_PARENT]?: StoreNode;
77
+ [STORE_SHALLOW]?: boolean;
78
+ [STORE_DESC]?: boolean;
31
79
  };
32
80
  export declare namespace SolidStore {
33
81
  interface Unwrappable {
@@ -36,33 +84,130 @@ export declare namespace SolidStore {
36
84
  export type NotWrappable = string | number | bigint | symbol | boolean | Function | null | undefined | SolidStore.Unwrappable[keyof SolidStore.Unwrappable];
37
85
  export declare function createStoreProxy<T extends object>(value: T, traps?: ProxyHandler<StoreNode>, extend?: (target: StoreNode) => void): any;
38
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;
39
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;
40
102
  export declare function isWrappable<T>(obj: T | NotWrappable): obj is T;
41
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[];
42
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;
43
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[];
44
153
  export declare function getPropertyDescriptor(source: Record<PropertyKey, any>, override: Record<PropertyKey, any> | undefined, property: PropertyKey): PropertyDescriptor | undefined;
45
154
  export declare const storeTraps: ProxyHandler<StoreNode>;
46
155
  export declare function storeSetter<T extends object>(store: Store<T>, fn: (draft: T) => T | void): void;
47
156
  /**
48
- * Creates a deeply reactive store with proxy-based tracking.
157
+ * Creates a deeply-reactive store backed by a Proxy. Reads track each property
158
+ * accessed; only the parts that change trigger updates.
49
159
  *
50
- * When called with a plain value, wraps it in a reactive proxy.
51
- * When called with a function, creates a derived projection store with `ProjectionOptions` (name, key).
160
+ * Store properties hold **plain values**, not accessors. The proxy already
161
+ * tracks reads per-property wrapping a value in `() => state.foo` produces
162
+ * a getter that *won't* track when called, which looks like a reactivity bug
163
+ * but is just a category error. If you have a signal-shaped piece of state,
164
+ * make it a property of the store (`{ foo: 1 }`) rather than nesting an
165
+ * accessor inside (`{ foo: () => signal() }`).
166
+ *
167
+ * The setter takes a **draft-mutating** function — mutate the draft in place
168
+ * (canonical). The callback may also return a new value: arrays are replaced
169
+ * by index (length adjusted), objects are shallow-diffed at the top level
170
+ * (keys present in the returned value are written, missing keys deleted). Use
171
+ * the return form for shapes where mutation is awkward — most commonly
172
+ * removing items via `filter`. The setter does **not** do keyed reconciliation;
173
+ * for that, use the derived/projection form (or `createProjection`).
174
+ *
175
+ * - Plain form: `createStore(initialValue)` — wraps a value in a reactive
176
+ * proxy.
177
+ * - Derived form: `createStore(fn, seed, options?)` — a *projection store*
178
+ * whose contents are computed by `fn(draft)`. `fn` may be sync, async, or
179
+ * an `AsyncIterable`; the projection's result reconciles against the
180
+ * existing store by `options.key` (default `"id"`) for stable identity.
181
+ *
182
+ * @example
183
+ * ```ts
184
+ * const [state, setState] = createStore({
185
+ * user: { name: "Ada", age: 36 },
186
+ * todos: [] as { id: string; text: string; done: boolean }[]
187
+ * });
188
+ *
189
+ * // Canonical: mutate the draft in place.
190
+ * setState(s => { s.user.age = 37; });
191
+ * setState(s => { s.todos.push({ id: "1", text: "x", done: false }); });
192
+ *
193
+ * // Return form: reach for it when mutation is awkward.
194
+ * setState(s => s.todos.filter(t => !t.done)); // remove items
195
+ * setState(s => ({ ...s, user: { name: "Grace", age: 85 } })); // shallow replace
196
+ * ```
52
197
  *
53
- * ```typescript
54
- * // Plain store
55
- * const [store, setStore] = createStore<T>(initialValue);
56
- * // Derived store (projection)
57
- * const [store, setStore] = createStore<T>(fn, seed, options?: ProjectionOptions);
198
+ * @example
199
+ * ```ts
200
+ * // Derived store auto-fetches & reconciles by `id`.
201
+ * const [users] = createStore(
202
+ * async () => fetch("/users").then(r => r.json()),
203
+ * [] as User[]
204
+ * );
58
205
  * ```
59
- * @param store initial value to wrap in a reactive proxy, or a derive function
60
- * @param options `ProjectionOptions` -- name, key (only for derived stores)
61
206
  *
62
207
  * @returns `[store: Store<T>, setStore: StoreSetter<T>]`
63
208
  */
64
- export declare function createStore<T extends object = {}>(store: NoFn<T> | Store<NoFn<T>>): [get: Store<T>, set: StoreSetter<T>];
65
- 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): [get: Store<T> & {
66
- [$REFRESH]: any;
67
- }, set: StoreSetter<T>];
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>;
68
213
  export {};
@@ -26,5 +26,33 @@ export interface storePath {
26
26
  <T, K1 extends KeyOf<W<T>>>(k1: Part<W<T>, K1>, setter: PathSetter<W<T>[K1]>): (state: T) => void;
27
27
  <T>(setter: PathSetter<T>): (state: T) => void;
28
28
  }
29
+ /**
30
+ * Path-based setter helper for `createStore`. Call `storePath(...path, value)`
31
+ * to produce a draft-mutating function suitable for passing to `setStore`.
32
+ *
33
+ * The canonical setter form in Solid 2.0 is the draft-mutating callback
34
+ * (`setStore(s => { s.user.name = "Ada"; })`). `storePath` is a backwards-
35
+ * compatibility helper for users porting from Solid 1.x's
36
+ * `setStore("user", "name", "Ada")` style — it's optional and you can mix the
37
+ * two styles freely.
38
+ *
39
+ * Path parts can be:
40
+ * - a single key — `"user"`, `0`
41
+ * - an array of keys — `[0, 1, 2]`
42
+ * - a range over an array — `{ from?, to?, by? }`
43
+ * - a filter `(item, index) => boolean` for arrays
44
+ *
45
+ * The final argument is the new value or an updater `(prev) => next`. Use
46
+ * `storePath.DELETE` to remove a property.
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * const [state, setState] = createStore({ user: { name: "Ada" }, todos: [] });
51
+ *
52
+ * setState(storePath("user", "name", "Grace"));
53
+ * setState(storePath("todos", t => !t.done, "done", true)); // mark all undone as done
54
+ * setState(storePath("user", "nickname", storePath.DELETE));
55
+ * ```
56
+ */
29
57
  export declare const storePath: storePath;
30
58
  export {};
@@ -1,15 +1,41 @@
1
1
  /**
2
- * Returns a non reactive copy of the store object.
3
- * It will attempt to preserver the original reference unless the value has been modified.
4
- * @param item store proxy object
2
+ * Returns a plain (non-proxy, non-reactive) deep copy of a store value.
3
+ * Reading via `snapshot` does **not** subscribe to changes use this when you
4
+ * need to hand a stable plain object to non-reactive code (logging,
5
+ * serialization, structured-clone, network payloads, etc.).
6
+ *
7
+ * Returns the original object identity for any sub-tree that wasn't modified
8
+ * relative to the proxy's underlying source.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * const [state] = createStore({ user: { name: "Ada" }, todos: [] });
13
+ *
14
+ * console.log(JSON.stringify(snapshot(state))); // safe, non-reactive copy
15
+ * ```
5
16
  */
6
17
  export declare function snapshot<T>(item: T): T;
7
18
  export declare function snapshot<T>(item: T, map?: Map<unknown, unknown>, lookup?: WeakMap<any, any>): T;
8
19
  /**
9
- * Returns a non-reactive snapshot of the store while subscribing to all nested changes.
10
- * Subscribes to `$TRACK` at every level so that any deep change triggers recomputation,
11
- * and returns plain (non-proxy) data. Works correctly with `reconcile()`.
12
- * @param store store proxy object
20
+ * Returns a plain (non-proxy) deep copy **and** subscribes the current
21
+ * tracking scope to every nested change in the source store. Any write
22
+ * anywhere in the subtree invalidates the consumer.
23
+ *
24
+ * Use this when you need plain data inside a reactive scope and want to
25
+ * react to deep mutations (e.g. passing a snapshot to `reconcile()` or to a
26
+ * memo that should rerun on any nested change). For most read paths, prefer
27
+ * direct property access — Solid stores already track per-property reads
28
+ * with no `deep()` wrapper needed.
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * const [state] = createStore({ a: { b: { c: 1 } } });
33
+ *
34
+ * createEffect(
35
+ * () => deep(state), // reruns on any nested change
36
+ * plain => sendToWorker(plain) // worker gets a non-proxy copy
37
+ * );
38
+ * ```
13
39
  */
14
40
  export declare function deep<T extends object>(store: T): T;
15
41
  type DistributeOverride<T, F> = T extends undefined ? F : T;
@@ -35,9 +61,54 @@ type _Merge<T extends unknown[], Curr = {}> = T extends [
35
61
  ...infer Rest
36
62
  ] ? _Merge<Rest, Override<Curr, Next>> : T extends [...infer Rest, infer Next | (() => infer Next)] ? Override<_Merge<Rest, Curr>, Next> : T extends [] ? Curr : T extends (infer I | (() => infer I))[] ? OverrideSpread<Curr, I> : Curr;
37
63
  export type Merge<T extends unknown[]> = Simplify<_Merge<T>>;
64
+ /**
65
+ * Merges multiple props-like objects into a single proxy that *preserves
66
+ * reactivity*. Reads are forwarded to the right-most source that defines the
67
+ * property, so later sources override earlier ones (like `Object.assign`).
68
+ *
69
+ * Function arguments are treated as memo-backed sources — useful for passing
70
+ * derived defaults whose computation should track reactively.
71
+ *
72
+ * Use this in component bodies to merge defaults / overrides without losing
73
+ * Solid's per-property tracking.
74
+ *
75
+ * @example
76
+ * ```tsx
77
+ * function Button(_props: { label: string; type?: string; disabled?: boolean }) {
78
+ * const props = merge({ type: "button", disabled: false }, _props);
79
+ *
80
+ * return <button type={props.type} disabled={props.disabled}>{props.label}</button>;
81
+ * }
82
+ * ```
83
+ */
38
84
  export declare function merge<T extends unknown[]>(...sources: T): Merge<T>;
39
85
  export type Omit<T, K extends readonly (keyof T)[]> = {
40
86
  [P in keyof T as Exclude<P, K[number]>]: T[P];
41
87
  };
88
+ /**
89
+ * Returns a reactive proxy of `props` with the listed keys hidden. Tracking
90
+ * on the remaining keys is preserved.
91
+ *
92
+ * Use it to forward "rest" props to a child element while pulling out the
93
+ * keys your component handles itself — the equivalent of `splitProps(p, ["a","b"])[1]`.
94
+ *
95
+ * @example
96
+ * ```tsx
97
+ * function Input(props: { label: string; value: string; onInput: (v: string) => void } & JSX.HTMLAttributes<HTMLInputElement>) {
98
+ * const rest = omit(props, "label", "value", "onInput");
99
+ *
100
+ * return (
101
+ * <label>
102
+ * {props.label}
103
+ * <input
104
+ * {...rest}
105
+ * value={props.value}
106
+ * onInput={e => props.onInput(e.currentTarget.value)}
107
+ * />
108
+ * </label>
109
+ * );
110
+ * }
111
+ * ```
112
+ */
42
113
  export declare function omit<T extends Record<any, any>, K extends readonly (keyof T)[]>(props: T, ...keys: K): Omit<T, K>;
43
114
  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;