@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.
Files changed (91) hide show
  1. package/README.md +13 -9
  2. package/dist/dev.js +5971 -1426
  3. package/dist/node.cjs +7681 -3293
  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 +60 -13
  34. package/dist/types/core/action.d.ts +35 -6
  35. package/dist/types/core/async.d.ts +16 -1
  36. package/dist/types/core/constants.d.ts +35 -6
  37. package/dist/types/core/context.d.ts +10 -2
  38. package/dist/types/core/core.d.ts +58 -63
  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 +50 -3
  50. package/dist/types/core/scheduler.d.ts +82 -10
  51. package/dist/types/core/types.d.ts +66 -1
  52. package/dist/types/core/verdict.d.ts +2 -0
  53. package/dist/types/index.d.ts +3 -2
  54. package/dist/types/map.d.ts +21 -5
  55. package/dist/types/signals.d.ts +164 -12
  56. package/dist/types/store/index.d.ts +1 -1
  57. package/dist/types/store/optimistic.d.ts +3 -3
  58. package/dist/types/store/projection.d.ts +10 -6
  59. package/dist/types/store/reconcile.d.ts +31 -8
  60. package/dist/types/store/store.d.ts +101 -6
  61. package/dist/types-cjs/affects.d.cts +47 -0
  62. package/dist/types-cjs/boundaries.d.cts +60 -13
  63. package/dist/types-cjs/core/action.d.cts +35 -6
  64. package/dist/types-cjs/core/async.d.cts +16 -1
  65. package/dist/types-cjs/core/constants.d.cts +35 -6
  66. package/dist/types-cjs/core/context.d.cts +10 -2
  67. package/dist/types-cjs/core/core.d.cts +58 -63
  68. package/dist/types-cjs/core/dev.d.cts +17 -2
  69. package/dist/types-cjs/core/effect.d.cts +1 -2
  70. package/dist/types-cjs/core/error.d.cts +33 -0
  71. package/dist/types-cjs/core/external.d.cts +0 -11
  72. package/dist/types-cjs/core/graph.d.cts +2 -1
  73. package/dist/types-cjs/core/heap.d.cts +8 -0
  74. package/dist/types-cjs/core/index.d.cts +3 -2
  75. package/dist/types-cjs/core/invariants.d.cts +59 -0
  76. package/dist/types-cjs/core/lanes.d.cts +2 -0
  77. package/dist/types-cjs/core/optimistic.d.cts +6 -0
  78. package/dist/types-cjs/core/owner.d.cts +50 -3
  79. package/dist/types-cjs/core/scheduler.d.cts +82 -10
  80. package/dist/types-cjs/core/types.d.cts +66 -1
  81. package/dist/types-cjs/core/verdict.d.cts +2 -0
  82. package/dist/types-cjs/index.d.cts +3 -2
  83. package/dist/types-cjs/map.d.cts +21 -5
  84. package/dist/types-cjs/signals.d.cts +164 -12
  85. package/dist/types-cjs/store/index.d.cts +1 -1
  86. package/dist/types-cjs/store/optimistic.d.cts +3 -3
  87. package/dist/types-cjs/store/projection.d.cts +10 -6
  88. package/dist/types-cjs/store/reconcile.d.cts +31 -8
  89. package/dist/types-cjs/store/store.d.cts +101 -6
  90. package/package.json +11 -9
  91. package/dist/prod.js +0 -3627
@@ -0,0 +1,103 @@
1
+ import { isWrappable, ownEnumerableKeys } from "./store.js";
2
+
3
+ const DELETE = Symbol(0);
4
+
5
+ function isPrototypePollutionKey(t) {
6
+ return t === "__proto__" || t === "constructor" || t === "prototype";
7
+ }
8
+
9
+ function updatePath(t, e, o = 0) {
10
+ let r, n = t;
11
+ if (o < e.length - 1) {
12
+ r = e[o];
13
+ const i = typeof r;
14
+ const f = Array.isArray(t);
15
+ if (i === "string" && isPrototypePollutionKey(r)) return;
16
+ if (Array.isArray(r)) {
17
+ for (let n = 0; n < r.length; n++) {
18
+ e[o] = r[n];
19
+ updatePath(t, e, o);
20
+ }
21
+ e[o] = r;
22
+ return;
23
+ } else if (f && i === "function") {
24
+ for (let n = 0; n < t.length; n++) {
25
+ if (r(t[n], n)) {
26
+ e[o] = n;
27
+ updatePath(t, e, o);
28
+ }
29
+ }
30
+ e[o] = r;
31
+ return;
32
+ } else if (f && i === "object") {
33
+ const {from: n = 0, to: i = t.length - 1, by: f = 1} = r;
34
+ for (let r = n; r <= i; r += f) {
35
+ e[o] = r;
36
+ updatePath(t, e, o);
37
+ }
38
+ e[o] = r;
39
+ return;
40
+ } else if (o < e.length - 2) {
41
+ updatePath(t[r], e, o + 1);
42
+ return;
43
+ }
44
+ n = t[r];
45
+ }
46
+ let i = e[e.length - 1];
47
+ if (typeof i === "function") {
48
+ i = i(n);
49
+ if (i === n) return;
50
+ }
51
+ if (r === undefined && i == undefined) return;
52
+ if (i === DELETE) {
53
+ delete t[r];
54
+ } else if (r === undefined || isWrappable(n) && isWrappable(i) && !Array.isArray(i)) {
55
+ const e = r !== undefined ? t[r] : t;
56
+ const o = ownEnumerableKeys(i);
57
+ for (let t = 0; t < o.length; t++) {
58
+ const r = o[t];
59
+ if (typeof r === "string" && isPrototypePollutionKey(r)) continue;
60
+ const n = Object.getOwnPropertyDescriptor(i, r);
61
+ if (n.get || n.set) Object.defineProperty(e, r, n); else e[r] = n.value;
62
+ }
63
+ } else {
64
+ t[r] = i;
65
+ }
66
+ }
67
+
68
+ /**
69
+ * Path-based setter helper for `createStore`. Call `storePath(...path, value)`
70
+ * to produce a draft-mutating function suitable for passing to `setStore`.
71
+ *
72
+ * The canonical setter form in Solid 2.0 is the draft-mutating callback
73
+ * (`setStore(s => { s.user.name = "Ada"; })`). `storePath` is a backwards-
74
+ * compatibility helper for users porting from Solid 1.x's
75
+ * `setStore("user", "name", "Ada")` style — it's optional and you can mix the
76
+ * two styles freely.
77
+ *
78
+ * Path parts can be:
79
+ * - a single key — `"user"`, `0`
80
+ * - an array of keys — `[0, 1, 2]`
81
+ * - a range over an array — `{ from?, to?, by? }`
82
+ * - a filter `(item, index) => boolean` for arrays
83
+ *
84
+ * The final argument is the new value or an updater `(prev) => next`. Use
85
+ * `storePath.DELETE` to remove a property.
86
+ *
87
+ * @example
88
+ * ```ts
89
+ * const [state, setState] = createStore({ user: { name: "Ada" }, todos: [] });
90
+ *
91
+ * setState(storePath("user", "name", "Grace"));
92
+ * setState(storePath("todos", t => !t.done, "done", true)); // mark all undone as done
93
+ * setState(storePath("user", "nickname", storePath.DELETE));
94
+ * ```
95
+ */ const storePath = /* @__PURE__ */ Object.assign(function storePath(...t) {
96
+ return e => {
97
+ updatePath(e, t);
98
+ };
99
+ }, {
100
+ DELETE: DELETE
101
+ });
102
+
103
+ export { storePath };
@@ -0,0 +1,328 @@
1
+ import { pendingCheckActive } from "../core/core.js";
2
+
3
+ import { SUPPORTS_PROXY } from "../core/constants.js";
4
+
5
+ import "../core/scheduler.js";
6
+
7
+ import "../core/invariants.js";
8
+
9
+ import "../core/verdict.js";
10
+
11
+ import "../core/effect.js";
12
+
13
+ import { createMemo } from "../signals.js";
14
+
15
+ import { ownEnumerableKeys, $PROXY, isWrappable, $TARGET, lookupTarget, trackSelf, witnessAffectsMark, mergedOverlay, STORE_VALUE, storeLookup, STORE_LOOKUP, $DELETED, wrap, getStoreSymbols, getPropertyDescriptor, getStoreKeys, getKeys, $TRACK, rawValuesUsed, isRawValue } from "./store.js";
16
+
17
+ function snapshotImpl(e, t, r, n) {
18
+ let o, s, i, c, f, u;
19
+ if (!isWrappable(e)) return e;
20
+ if (r && r.has(e)) return r.get(e);
21
+ if (!r) r = new Map;
22
+ if (o = e[$TARGET] || lookupTarget(e, n)) {
23
+ if (t) {
24
+ trackSelf(o, $TRACK);
25
+ // A tracked walk reads THROUGH the record without touching the proxy
26
+ // traps — witness the record's affects() channel like a trap read would.
27
+ if (pendingCheckActive) witnessAffectsMark(o);
28
+ }
29
+ i = mergedOverlay(o);
30
+ // A derived store's STORE_VALUE is the inner store's live proxy
31
+ // (store-in-store: createOptimisticStore/createProjection over a store).
32
+ // Without an overlay of its own, the fast path below would map to — and
33
+ // could return — that proxy verbatim. Recurse instead so the
34
+ // inner store's own target branch unwraps it (chains of any depth).
35
+ // With an overlay, a fresh `result` is always built, so the walk over the
36
+ // inner proxy already copies plain values.
37
+ if (!i && o[STORE_VALUE][$TARGET]) {
38
+ f = snapshotImpl(o[STORE_VALUE], t, r, n);
39
+ r.set(e, f);
40
+ return f;
41
+ }
42
+ s = Array.isArray(o[STORE_VALUE]);
43
+ r.set(e, i ? c = s ? [] : Object.create(Object.getPrototypeOf(o[STORE_VALUE])) : o[STORE_VALUE]);
44
+ e = o[STORE_VALUE];
45
+ n = o[STORE_LOOKUP] ?? storeLookup;
46
+ } else {
47
+ s = Array.isArray(e);
48
+ r.set(e, e);
49
+ }
50
+ if (s) {
51
+ const s = i?.length ?? e.length;
52
+ for (let a = 0; a < s; a++) {
53
+ u = i && a in i ? i[a] : e[a];
54
+ if (u === $DELETED) continue;
55
+ if (t && isWrappable(u) && !(rawValuesUsed && isRawValue(u))) wrap(u, o);
56
+ if ((f = snapshotImpl(u, t, r, n)) !== u || c) {
57
+ if (!c) r.set(e, c = [ ...e ]);
58
+ c[a] = f;
59
+ }
60
+ }
61
+ // Enumerate array symbols separately to avoid scanning indices twice.
62
+ // Spread copies omit symbols, so assign them after the numeric walk.
63
+ const a = n ? getStoreSymbols(e, i) : [];
64
+ for (let s = 0, l = a.length; s < l; s++) {
65
+ const l = a[s];
66
+ const p = getPropertyDescriptor(e, i, l);
67
+ if (!p || p.get) continue;
68
+ u = i && l in i ? i[l] : e[l];
69
+ if (t && isWrappable(u) && !(rawValuesUsed && isRawValue(u))) wrap(u, o);
70
+ f = snapshotImpl(u, t, r, n);
71
+ if (f !== u || c) {
72
+ if (!c) r.set(e, c = Object.assign([ ...e ], e));
73
+ c[l] = f;
74
+ }
75
+ }
76
+ // Deleted trailing slots are skipped above, so restore length to preserve
77
+ // holes instead of truncating the copy (#2846) — mirrors unwrapStoreValue.
78
+ if (c) c.length = s;
79
+ } else if (!i) {
80
+ // Specialized walk for the common no-overlay case (from #2756): the own
81
+ // descriptor gives the value directly, so each property is read once with
82
+ // no overlay membership checks.
83
+ // A lookup means this object belongs to an immutable store backing tree,
84
+ // even if that nested value has not needed its own proxy yet.
85
+ const s = n ? getStoreKeys(e, undefined) : getKeys(e, undefined);
86
+ for (let i = 0, a = s.length; i < a; i++) {
87
+ const a = s[i];
88
+ const l = Object.getOwnPropertyDescriptor(e, a);
89
+ if (l.get) continue;
90
+ u = l.value;
91
+ if (t && isWrappable(u) && !(rawValuesUsed && isRawValue(u))) wrap(u, o);
92
+ if ((f = snapshotImpl(u, t, r, n)) !== u || c) {
93
+ if (!c) {
94
+ c = Object.create(Object.getPrototypeOf(e));
95
+ Object.assign(c, e);
96
+ }
97
+ c[a] = f;
98
+ }
99
+ }
100
+ } else {
101
+ // An override only exists on a store record, and the target branch above
102
+ // always set `lookup` alongside it — so this branch is always store-keyed.
103
+ const s = getStoreKeys(e, i);
104
+ for (let a = 0, l = s.length; a < l; a++) {
105
+ let l = s[a];
106
+ const p = getPropertyDescriptor(e, i, l);
107
+ if (p.get) continue;
108
+ u = l in i ? i[l] : e[l];
109
+ if (t && isWrappable(u) && !(rawValuesUsed && isRawValue(u))) wrap(u, o);
110
+ if ((f = snapshotImpl(u, t, r, n)) !== e[l] || c) {
111
+ if (!c) {
112
+ c = Object.create(Object.getPrototypeOf(e));
113
+ Object.assign(c, e);
114
+ }
115
+ c[l] = f;
116
+ }
117
+ }
118
+ }
119
+ return c || e;
120
+ }
121
+
122
+ function snapshot(e, t, r) {
123
+ return snapshotImpl(e, false, t, r);
124
+ }
125
+
126
+ /**
127
+ * Returns a plain (non-proxy) deep copy **and** subscribes the current
128
+ * tracking scope to every nested change in the source store. Any write
129
+ * anywhere in the subtree invalidates the consumer.
130
+ *
131
+ * Use this when you need plain data inside a reactive scope and want to
132
+ * react to deep mutations (e.g. passing a snapshot to `reconcile()` or to a
133
+ * memo that should rerun on any nested change). For most read paths, prefer
134
+ * direct property access — Solid stores already track per-property reads
135
+ * with no `deep()` wrapper needed.
136
+ *
137
+ * @example
138
+ * ```ts
139
+ * const [state] = createStore({ a: { b: { c: 1 } } });
140
+ *
141
+ * createEffect(
142
+ * () => deep(state), // reruns on any nested change
143
+ * plain => sendToWorker(plain) // worker gets a non-proxy copy
144
+ * );
145
+ * ```
146
+ */ function deep(e) {
147
+ return snapshotImpl(e, true);
148
+ }
149
+
150
+ function trueFn() {
151
+ return true;
152
+ }
153
+
154
+ const propTraps = {
155
+ get(e, t, r) {
156
+ if (t === $PROXY) return r;
157
+ return e.get(t);
158
+ },
159
+ has(e, t) {
160
+ if (t === $PROXY) return true;
161
+ return e.has(t);
162
+ },
163
+ set: trueFn,
164
+ deleteProperty: trueFn,
165
+ getOwnPropertyDescriptor(e, t) {
166
+ return {
167
+ configurable: true,
168
+ enumerable: true,
169
+ get() {
170
+ return e.get(t);
171
+ },
172
+ set: trueFn,
173
+ deleteProperty: trueFn
174
+ };
175
+ },
176
+ ownKeys(e) {
177
+ return e.keys();
178
+ }
179
+ };
180
+
181
+ function resolveSource(e) {
182
+ return !(e = typeof e === "function" ? e() : e) ? {} : e;
183
+ }
184
+
185
+ const $SOURCES = Symbol(0);
186
+
187
+ /**
188
+ * Merges multiple props-like objects into a single proxy that *preserves
189
+ * reactivity*. Reads are forwarded to the right-most source that defines the
190
+ * property, so later sources override earlier ones (like `Object.assign`).
191
+ *
192
+ * Function arguments are treated as memo-backed sources — useful for passing
193
+ * derived defaults whose computation should track reactively.
194
+ *
195
+ * Use this in component bodies to merge defaults / overrides without losing
196
+ * Solid's per-property tracking.
197
+ *
198
+ * @example
199
+ * ```tsx
200
+ * function Button(_props: { label: string; type?: string; disabled?: boolean }) {
201
+ * const props = merge({ type: "button", disabled: false }, _props);
202
+ *
203
+ * return <button type={props.type} disabled={props.disabled}>{props.label}</button>;
204
+ * }
205
+ * ```
206
+ */ function merge(...e) {
207
+ if (e.length === 1 && typeof e[0] !== "function") return e[0];
208
+ let t = false;
209
+ const r = [];
210
+ for (let n = 0; n < e.length; n++) {
211
+ const o = e[n];
212
+ t = t || !!o && $PROXY in o;
213
+ const s = !!o && o[$SOURCES];
214
+ if (s) {
215
+ for (let e = 0; e < s.length; e++) r.push(s[e]);
216
+ } else r.push(typeof o === "function" ? (t = true, createMemo(o)) : o);
217
+ }
218
+ if (SUPPORTS_PROXY && t) {
219
+ return new Proxy({
220
+ get(e) {
221
+ if (e === $SOURCES) return r;
222
+ for (let t = r.length - 1; t >= 0; t--) {
223
+ const n = resolveSource(r[t]);
224
+ if (e in n) return n[e];
225
+ }
226
+ },
227
+ has(e) {
228
+ for (let t = r.length - 1; t >= 0; t--) {
229
+ if (e in resolveSource(r[t])) return true;
230
+ }
231
+ return false;
232
+ },
233
+ keys() {
234
+ const e = new Set;
235
+ for (let t = 0; t < r.length; t++) {
236
+ const n = ownEnumerableKeys(resolveSource(r[t]));
237
+ for (let t = 0; t < n.length; t++) e.add(n[t]);
238
+ }
239
+ return [ ...e ];
240
+ }
241
+ }, propTraps);
242
+ }
243
+ const n = Object.create(null);
244
+ let o = false;
245
+ let s = r.length - 1;
246
+ for (let e = s; e >= 0; e--) {
247
+ const t = r[e];
248
+ if (!t) {
249
+ e === s && s--;
250
+ continue;
251
+ }
252
+ const i = Object.getOwnPropertyNames(t);
253
+ for (let r = i.length - 1; r >= 0; r--) {
254
+ const c = i[r];
255
+ if (c === "__proto__" || c === "constructor") continue;
256
+ if (!n[c]) {
257
+ o = o || e !== s;
258
+ const r = Object.getOwnPropertyDescriptor(t, c);
259
+ n[c] = r.get ? {
260
+ enumerable: true,
261
+ configurable: true,
262
+ get: r.get.bind(t)
263
+ } : r;
264
+ }
265
+ }
266
+ }
267
+ if (!o) return r[s];
268
+ const i = {};
269
+ const c = Object.keys(n);
270
+ for (let e = c.length - 1; e >= 0; e--) {
271
+ const t = c[e], r = n[t];
272
+ if (r.get) Object.defineProperty(i, t, r); else i[t] = r.value;
273
+ }
274
+ i[$SOURCES] = r;
275
+ return i;
276
+ }
277
+
278
+ /**
279
+ * Returns a reactive proxy of `props` with the listed keys hidden. Tracking
280
+ * on the remaining keys is preserved.
281
+ *
282
+ * Use it to forward "rest" props to a child element while pulling out the
283
+ * keys your component handles itself — the equivalent of `splitProps(p, ["a","b"])[1]`.
284
+ *
285
+ * @example
286
+ * ```tsx
287
+ * function Input(props: { label: string; value: string; onInput: (v: string) => void } & JSX.HTMLAttributes<HTMLInputElement>) {
288
+ * const rest = omit(props, "label", "value", "onInput");
289
+ *
290
+ * return (
291
+ * <label>
292
+ * {props.label}
293
+ * <input
294
+ * {...rest}
295
+ * value={props.value}
296
+ * onInput={e => props.onInput(e.currentTarget.value)}
297
+ * />
298
+ * </label>
299
+ * );
300
+ * }
301
+ * ```
302
+ */ function omit(e, ...t) {
303
+ if (SUPPORTS_PROXY && $PROXY in e) {
304
+ return new Proxy({
305
+ get(r) {
306
+ return t.includes(r) ? undefined : e[r];
307
+ },
308
+ has(r) {
309
+ return !t.includes(r) && r in e;
310
+ },
311
+ keys() {
312
+ return ownEnumerableKeys(e).filter(e => !t.includes(e));
313
+ }
314
+ }, propTraps);
315
+ }
316
+ const r = {};
317
+ const n = Object.getOwnPropertyNames(e);
318
+ const o = t.length > 4 && n.length > t.length ? new Set(t) : undefined;
319
+ for (const s of n) {
320
+ if (o ? !o.has(s) : !t.includes(s)) {
321
+ const t = Object.getOwnPropertyDescriptor(e, s);
322
+ !t.get && !t.set && t.enumerable && t.writable && t.configurable ? r[s] = t.value : Object.defineProperty(r, s, t);
323
+ }
324
+ }
325
+ return r;
326
+ }
327
+
328
+ export { deep, merge, omit, snapshot };
@@ -0,0 +1,47 @@
1
+ import type { Accessor } from "./signals.js";
2
+ import { type Store } from "./store/store.js";
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.js";
2
2
  import type { Signal } from "./core/index.js";
3
+ import { type Accessor } from "./signals.js";
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
- isReady(): boolean;
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`: fully ready (atomic).
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
- isMinimallyReady(): boolean;
31
- register(slot: RevealSlot): void;
32
- unregister(slot: RevealSlot): void;
33
- evaluate(disabledOverride?: boolean, collapsedOverride?: boolean): void;
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
- checkSources(): void;
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: () => any, fallback: () => any, options?: {
76
+ export declare function createLoadingBoundary<T, U>(fn: () => T, fallback: () => U, options?: {
64
77
  on?: () => any;
65
- }): import("./signals.js").Accessor<unknown>;
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
- * `reset()` recomputes the failing sources so the boundary can attempt to
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: () => any, fallback: (error: unknown, reset: () => void) => U): import("./signals.js").Accessor<unknown>;
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 when fully ready, since natural treats composites as atomic).
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
- * Yield promises (or any awaitable) inside the generator the action waits
8
- * for each before continuing, but the writes you made beforehand are already
9
- * visible (or held by `<Loading>` if optimistic). Yield bare values for
10
- * synchronous batched steps.
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 = yield api.createTodo(text); // network round-trip
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;