@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
@@ -0,0 +1,369 @@
1
+ import { NOT_PENDING, REACTIVE_DISPOSED, REACTIVE_DIRTY, REACTIVE_CHECK, unwrapOverride, REACTIVE_ZOMBIE, STATUS_UNINITIALIZED, STATUS_PENDING, REACTIVE_MANUAL_WRITE, STATUS_ERROR, REACTIVE_RECOMPUTING_DEPS } from "./constants.js";
2
+
3
+ import { setSignal, prepareComputed, read, context, stale, currentOptimisticLane, tracking, setLatestReadActive, setContextInternal, optimisticComputed, setPendingCheckActive, latestReadActive, optimisticSignal, pendingCheckActive } from "./core.js";
4
+
5
+ import { NotReadyError } from "./error.js";
6
+
7
+ import { link } from "./graph.js";
8
+
9
+ import { insertIntoHeap, queueFor, markHeap } from "./heap.js";
10
+
11
+ import "./invariants.js";
12
+
13
+ import { findLane, hasActiveOverride } from "./lanes.js";
14
+
15
+ import { installOptimisticEngine } from "./optimistic.js";
16
+
17
+ import { GlobalQueue, clock, insertSubs, schedule, activeTransition, activeAffectsMarks } from "./scheduler.js";
18
+
19
+ /**
20
+ * The isPending()/latest() verdict layer, moved out of core.ts. Importing this
21
+ * module installs the companion-maintenance hooks on GlobalQueue; apps that
22
+ * never import isPending/latest never pay for any of it.
23
+ */
24
+ // Companions (pending signals / latest shadows) are optimistic nodes: their
25
+ // writes go through the optimistic write path and their reversion rides the
26
+ // same lanes, so the verdict layer brings the engine with it.
27
+ installOptimisticEngine();
28
+
29
+ let pendingProbe = null;
30
+
31
+ /**
32
+ * Get or create the pending signal for a node (lazy).
33
+ * Used by isPending() to track pending state reactively.
34
+ */ function getPendingSignal(e) {
35
+ if (!e.ge) {
36
+ // Start false, write true if pending - ensures reversion returns to false
37
+ e.ge = optimisticSignal(false, {
38
+ ownedWrite: true
39
+ });
40
+ e.ge.nn = e;
41
+ if (computePendingState(e)) setSignal(e.ge, true);
42
+ }
43
+ return e.ge;
44
+ }
45
+
46
+ function collectPendingSources(e) {
47
+ if (!pendingProbe) return;
48
+ pendingProbe.sources.add(e);
49
+ const t = e.lt || e;
50
+ if (t !== e) pendingProbe.sources.add(t);
51
+ }
52
+
53
+ /**
54
+ * Adds a node to the active isPending() probe without reading it. The store's
55
+ * untracked-probe fallback (`witnessAffectsMark`) reaches this through
56
+ * `GlobalQueue._witnessAffects` — its callers guard on `pendingCheckActive`,
57
+ * which only flips inside `isPending()`, so the hook is always installed by
58
+ * the time it can fire.
59
+ */ function witnessAffects(e) {
60
+ pendingProbe?.sources.add(e);
61
+ }
62
+
63
+ /**
64
+ * The affects() coverage walk — the read half of the dedicated mark channel.
65
+ * A node is covered by a live mark iff it carries one (`_affectsCount`) or
66
+ * derives, through its CURRENT deps (hopping store firewalls), from a node
67
+ * that does. Pull-based coverage means graph rewires, mid-window recomputes,
68
+ * and probe-triggered recomputes can never strand or strip a mark — there is
69
+ * nothing stored downstream to corrupt. Probe-created links
70
+ * (`_pendingObserver`) are skipped so an `isPending` wrapper memo never
71
+ * inherits the coverage it reports on.
72
+ */ function markWalk(e, t) {
73
+ if (e.t) return true;
74
+ // A real error outranks an inherited mark (A16/A24c): an errored node
75
+ // answers probes with its error, not a coverage verdict, and coverage does
76
+ // not flow through it — matching the rails' behavior, where propagation
77
+ // stopped at errored nodes. A DIRECT mark on an errored node still reads
78
+ // pending (the count check above), also matching.
79
+ if (e.S & STATUS_ERROR) return false;
80
+ if (t.has(e)) return false;
81
+ t.add(e);
82
+ const n = e.lt;
83
+ if (n && markWalk(n, t)) return true;
84
+ // Mid-recompute (the clearStatus companion poke runs before
85
+ // trimStaleDeps), only the validated prefix [_deps.._depsTail] is this
86
+ // pass's dependency set — walking past it would read dropped deps and
87
+ // latch a stale verdict on the companion.
88
+ const i = e;
89
+ const r = i.se & REACTIVE_RECOMPUTING_DEPS ? i.Ye : undefined;
90
+ if (r !== null) {
91
+ for (let e = i.tt ?? null; e !== null; e = e.nt) {
92
+ if (!e.Ge && markWalk(e.it, t)) return true;
93
+ if (e === r) break;
94
+ }
95
+ }
96
+ return false;
97
+ }
98
+
99
+ /** Gated entry: apps with no live mark pay one integer compare. */ function markCovered(e) {
100
+ return activeAffectsMarks !== 0 && markWalk(e, new Set);
101
+ }
102
+
103
+ function quietPending(e) {
104
+ if (e.oe) {
105
+ for (const t of e.oe) if (!t.he) return false;
106
+ return true;
107
+ }
108
+ return e.he;
109
+ }
110
+
111
+ // NOTE: a loadingValue node's open loading window (_loading) is verdict-quiet
112
+ // on purpose: commit #0 answers the question by declaration, so the window
113
+ // reads NOT pending — first-load affordances live in the value channel
114
+ // (null / skeleton provenance the author encoded), and isPending stays what
115
+ // it always was: refetch truth for an answered question. This keeps the
116
+ // verdict fully correlated with transition-class machinery and keeps server
117
+ // (always false) and client hydration trivially consistent.
118
+ function newQuestionInFlight(e) {
119
+ return !!(e.S & STATUS_PENDING) && !(e.S & STATUS_UNINITIALIZED) && !quietPending(e);
120
+ }
121
+
122
+ function computePendingState(e) {
123
+ const t = e;
124
+ if (t.se & REACTIVE_DISPOSED) return false;
125
+ // Mark coverage is transitive by dep-graph reachability: a latest() shadow
126
+ // reaches its owner (and a store leaf its firewall) through its own deps,
127
+ // so the one walk covers direct marks, derivation, and companion chains.
128
+ if (markCovered(e)) return true;
129
+ const n = e.lt;
130
+ if (e.nn) {
131
+ const t = e.nn;
132
+ const n = t.lt || t;
133
+ return newQuestionInFlight(n);
134
+ }
135
+ if (n && e.De !== NOT_PENDING && !hasActiveOverride(e)) {
136
+ return !!(n.se & REACTIVE_MANUAL_WRITE) || !n.Te && !(n.S & STATUS_PENDING) || !!(n.S & STATUS_PENDING) && quietPending(n);
137
+ }
138
+ // `!comp._loading`: a hold created while the loading window is still open is
139
+ // the window's own landing in flight to its commit — verdict-quiet like the
140
+ // rest of the window (the UNINITIALIZED check suppresses exactly this frame
141
+ // for windowless first loads; born-committed nodes need their own gate, #2990).
142
+ if (e.De !== NOT_PENDING && !(t.S & STATUS_UNINITIALIZED) && !t.Ee) {
143
+ if (hasActiveOverride(e)) return !e.be || !e.be(e.De, unwrapOverride(e._e));
144
+ return true;
145
+ }
146
+ return newQuestionInFlight(t);
147
+ }
148
+
149
+ function syncCompanions(e, t) {
150
+ if (e.ge) updatePendingSignal(e);
151
+ if (e.pe) setSignal(e.pe, t);
152
+ }
153
+
154
+ function updatePendingSignal(e) {
155
+ if (e.ge) {
156
+ setSignal(e.ge, computePendingState(e));
157
+ }
158
+ if (e.pe) updatePendingSignal(e.pe);
159
+ }
160
+
161
+ function updateChildCompanions(e) {
162
+ for (let t = e.u; t !== null; t = t.ae) {
163
+ if (t.ge || t.pe) updatePendingSignal(t);
164
+ }
165
+ }
166
+
167
+ /**
168
+ * Re-derive every verdict companion downstream of `el` (subs + firewall
169
+ * children, dedup'd). The affects() channel's poke walk: registration and
170
+ * re-ask flips use the live write path (companion setSignal — its own lane
171
+ * lets the wake escape an incomplete transition's effect stash, #2887);
172
+ * mark release passes `snap` because it runs inside queue finalization,
173
+ * where companion writes must land committed (a setSignal there would open
174
+ * a fresh override window that nothing settles).
175
+ */ function repollDownstreamVerdicts(e, t = false) {
176
+ const n = t ? snapCompanionsToState : updatePendingSignal;
177
+ const i = new Set;
178
+ const visit = e => {
179
+ if (i.has(e)) return;
180
+ i.add(e);
181
+ if (e.ge || e.pe) n(e);
182
+ for (let t = e.o; t !== null; t = t.le) visit(t.fe);
183
+ for (let t = e.u ?? null; t !== null; t = t.ae) {
184
+ visit(t);
185
+ }
186
+ };
187
+ visit(e);
188
+ }
189
+
190
+ function snapCompanionsToState(e) {
191
+ const t = e.ge;
192
+ if (t && (t._e === undefined || t._e === NOT_PENDING)) {
193
+ const n = computePendingState(e);
194
+ if (t.Ue !== n || t.De !== NOT_PENDING) {
195
+ t.Ue = n;
196
+ t.De = NOT_PENDING;
197
+ t.de = clock;
198
+ insertSubs(t);
199
+ schedule();
200
+ }
201
+ }
202
+ const n = e.pe;
203
+ if (n && !(n.se & REACTIVE_DISPOSED)) {
204
+ if ((n._e === undefined || n._e === NOT_PENDING) && n.De === NOT_PENDING && !Object.is(n.Ue, e.Ue) && !(n.se & (REACTIVE_DIRTY | REACTIVE_CHECK))) {
205
+ n.se |= REACTIVE_DIRTY;
206
+ insertIntoHeap(n, queueFor(n));
207
+ insertSubs(n);
208
+ schedule();
209
+ }
210
+ snapCompanionsToState(n);
211
+ }
212
+ }
213
+
214
+ function getLatestValueComputed(e) {
215
+ if (!e.pe) {
216
+ const t = latestReadActive;
217
+ setLatestReadActive(false);
218
+ const n = pendingCheckActive;
219
+ setPendingCheckActive(false);
220
+ const i = context;
221
+ setContextInternal(null);
222
+ // Detach from owner so it isn't disposed with effects
223
+ e.pe = optimisticComputed(() => read(e));
224
+ e.pe.nn = e;
225
+ // Parent-child lane relationship
226
+ setContextInternal(i);
227
+ setPendingCheckActive(n);
228
+ setLatestReadActive(t);
229
+ }
230
+ return e.pe;
231
+ }
232
+
233
+ /** The latest()-mode read path, installed as GlobalQueue._latestRead. */ function latestRead(e) {
234
+ const t = getLatestValueComputed(e);
235
+ const n = latestReadActive;
236
+ setLatestReadActive(false);
237
+ const i = e._e !== undefined && e._e !== NOT_PENDING ? unwrapOverride(e._e) : e.Ue;
238
+ let r;
239
+ try {
240
+ // An untracked latest() read has no reading context, so read() never
241
+ // performs its mid-tick pull — a plain write queued between two latest()
242
+ // calls left a still-subscribed shadow at its previous speculative value
243
+ // until the flush (#2922). Mirror the tracked-read pull here: mark the
244
+ // queued staleness through the graph, then bring the shadow up to date.
245
+ const e = queueFor(t);
246
+ if (t.xe >= e.Ve && !(t.se & (REACTIVE_DISPOSED | REACTIVE_ZOMBIE))) {
247
+ markHeap(e);
248
+ prepareComputed(t, true);
249
+ }
250
+ r = read(t);
251
+ } catch (t) {
252
+ if (t instanceof NotReadyError && (!context || !(e.S & STATUS_UNINITIALIZED))) return i;
253
+ throw t;
254
+ } finally {
255
+ setLatestReadActive(n);
256
+ }
257
+ if (t.S & STATUS_PENDING) return i;
258
+ if (stale && currentOptimisticLane && t.Ke) {
259
+ const e = findLane(t.Ke);
260
+ const n = findLane(currentOptimisticLane);
261
+ if (e !== n && e.Ae.size > 0) {
262
+ return i;
263
+ }
264
+ }
265
+ // A shadow recomputed by the pull above (not at creation) holds its fresh
266
+ // speculative value in _pendingValue; a contextless read() only surfaces
267
+ // _value. Overrides stay authoritative (A17), and stale readers keep the
268
+ // other transition's committed view, matching read()'s own selection.
269
+ if (t.De !== NOT_PENDING && !hasActiveOverride(t) && !(stale && t.Ne && activeTransition !== t.Ne)) return t.De;
270
+ return r;
271
+ }
272
+
273
+ /** The isPending()-probe read path, installed as GlobalQueue._pendingCheck. */ function pendingCheckRead(e, t, n, i) {
274
+ setPendingCheckActive(false);
275
+ if (typeof e.ce === "function") prepareComputed(e, true);
276
+ const r = n.S;
277
+ if (t && r & STATUS_PENDING && r & STATUS_UNINITIALIZED) {
278
+ if (tracking && e !== t) link(e, t);
279
+ setPendingCheckActive(true);
280
+ throw n._;
281
+ }
282
+ collectPendingSources(e);
283
+ if (i) collectPendingSources(i);
284
+ setPendingCheckActive(true);
285
+ }
286
+
287
+ function recordFreshRead(e, t) {
288
+ if (pendingProbe !== null && e.De !== NOT_PENDING && t === e.De) pendingProbe.freshReads.add(e);
289
+ }
290
+
291
+ function applyReask(e, t) {
292
+ const n = !!(e.S & STATUS_PENDING);
293
+ const i = t && !(n && !e.he);
294
+ const r = n && e.he !== i;
295
+ e.he = i;
296
+ return r;
297
+ }
298
+
299
+ function latest(e) {
300
+ const t = latestReadActive;
301
+ setLatestReadActive(true);
302
+ try {
303
+ return e();
304
+ } finally {
305
+ setLatestReadActive(t);
306
+ }
307
+ }
308
+
309
+ function isPending(e) {
310
+ const t = pendingCheckActive;
311
+ const n = pendingProbe;
312
+ setPendingCheckActive(true);
313
+ const i = pendingProbe = {
314
+ found: false,
315
+ sources: new Set,
316
+ freshReads: new Set
317
+ };
318
+ const collectPending = () => {
319
+ setPendingCheckActive(false);
320
+ try {
321
+ i.sources.forEach(e => {
322
+ if (read(getPendingSignal(e)) && !i.freshReads.has(e)) i.found = true;
323
+ });
324
+ } finally {
325
+ setPendingCheckActive(true);
326
+ }
327
+ };
328
+ try {
329
+ e();
330
+ collectPending();
331
+ return i.found;
332
+ } catch (e) {
333
+ collectPending();
334
+ if (e instanceof NotReadyError) {
335
+ const t = !!(e.source?.S & STATUS_UNINITIALIZED);
336
+ if (i.found && !t) return true;
337
+ if (context && t) throw e;
338
+ }
339
+ return i.found;
340
+ } finally {
341
+ setPendingCheckActive(t);
342
+ pendingProbe = n;
343
+ }
344
+ }
345
+
346
+ // Hook installation (same late-binding pattern as GlobalQueue._update /
347
+ // _propagateAffects): core call sites fire these behind the same guards the
348
+ // direct calls used, so behavior is identical once this module loads.
349
+ GlobalQueue.Pe = syncCompanions;
350
+
351
+ GlobalQueue.Se = updatePendingSignal;
352
+
353
+ GlobalQueue.Oe = updateChildCompanions;
354
+
355
+ GlobalQueue.un = snapCompanionsToState;
356
+
357
+ GlobalQueue.At = latestRead;
358
+
359
+ GlobalQueue.Ct = pendingCheckRead;
360
+
361
+ GlobalQueue.ht = recordFreshRead;
362
+
363
+ GlobalQueue.Be = applyReask;
364
+
365
+ GlobalQueue.k = repollDownstreamVerdicts;
366
+
367
+ GlobalQueue.Lt = witnessAffects;
368
+
369
+ export { isPending, latest };
@@ -0,0 +1,45 @@
1
+ export { ContextNotFoundError, NoOwnerError, NotReadyError } from "./core/error.js";
2
+
3
+ export { clearSnapshots, isEqual, markSnapshotScope, refresh, releaseSnapshotScope, runWithOwner, setSnapshotCapture, untrack } from "./core/core.js";
4
+
5
+ export { enableExternalSource } from "./core/external.js";
6
+
7
+ export { createOwner, createRoot, getNextChildId, getObserver, getOwner, isDisposed, peekNextChildId } from "./core/owner.js";
8
+
9
+ export { createContext, getContext, setContext } from "./core/context.js";
10
+
11
+ export { $REFRESH, SUPPORTS_PROXY } from "./core/constants.js";
12
+
13
+ import "./core/invariants.js";
14
+
15
+ export { enforceLoadingBoundary, flush, resetErrorHalt } from "./core/scheduler.js";
16
+
17
+ export { isPending, latest } from "./core/verdict.js";
18
+
19
+ import "./core/effect.js";
20
+
21
+ export { action } from "./core/action.js";
22
+
23
+ export { createEffect, createMemo, createOptimistic, createReaction, createRenderEffect, createSignal, createTrackedEffect, onCleanup, onSettled, resolve } from "./signals.js";
24
+
25
+ export { affects } from "./affects.js";
26
+
27
+ export { mapArray, repeat } from "./map.js";
28
+
29
+ export { $PROXY, $TARGET, $TRACK, createStore, isWrappable } from "./store/store.js";
30
+
31
+ export { createProjection } from "./store/projection.js";
32
+
33
+ export { createOptimisticStore } from "./store/optimistic.js";
34
+
35
+ export { reconcile } from "./store/reconcile.js";
36
+
37
+ export { storePath } from "./store/storePath.js";
38
+
39
+ export { deep, merge, omit, snapshot } from "./store/utils.js";
40
+
41
+ export { createErrorBoundary, createLoadingBoundary, createRevealOrder, flatten } from "./boundaries.js";
42
+
43
+ const DEV = undefined;
44
+
45
+ export { DEV };