@solidjs/signals 2.0.0-rc.11 → 2.0.0-rc.14

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 (118) hide show
  1. package/dist/dev-shared.js +2056 -3773
  2. package/dist/dev.attribution.js +159 -91
  3. package/dist/dev.js +7263 -8384
  4. package/dist/observe/affects.js +125 -104
  5. package/dist/observe/boundaries.js +458 -665
  6. package/dist/observe/core/action.js +63 -66
  7. package/dist/observe/core/async.js +240 -383
  8. package/dist/observe/core/attribution-queries.js +1 -1
  9. package/dist/observe/core/attribution.js +271 -199
  10. package/dist/observe/core/constants.js +115 -178
  11. package/dist/observe/core/context.js +3 -3
  12. package/dist/observe/core/core.js +840 -1428
  13. package/dist/observe/core/dev.js +41 -18
  14. package/dist/observe/core/effect.js +75 -86
  15. package/dist/observe/core/external.js +5 -5
  16. package/dist/observe/core/graph.js +61 -70
  17. package/dist/observe/core/heap.js +75 -98
  18. package/dist/observe/core/invariants.js +1 -34
  19. package/dist/observe/core/lanes.js +704 -181
  20. package/dist/observe/core/owner.js +80 -101
  21. package/dist/observe/core/scheduler.js +708 -1351
  22. package/dist/observe/core/verdict.js +302 -621
  23. package/dist/observe/flatten.js +79 -0
  24. package/dist/observe/index.js +15 -13
  25. package/dist/observe/map.js +232 -235
  26. package/dist/observe/reveal.js +212 -0
  27. package/dist/observe/signals.js +133 -215
  28. package/dist/observe/store/affects.js +135 -0
  29. package/dist/observe/store/index.js +29 -24
  30. package/dist/observe/store/optimistic.js +538 -0
  31. package/dist/observe/store/projection.js +302 -0
  32. package/dist/observe/store/reconcile.js +257 -0
  33. package/dist/observe/store/store.js +1945 -277
  34. package/dist/observe/store/storePath.js +1 -1
  35. package/dist/{prod/store/next → observe/store}/target.js +17 -18
  36. package/dist/observe/store/types.js +73 -0
  37. package/dist/observe/store/utils.js +1 -13
  38. package/dist/prod/affects.js +127 -106
  39. package/dist/prod/boundaries.js +442 -654
  40. package/dist/prod/core/action.js +71 -74
  41. package/dist/prod/core/async.js +307 -442
  42. package/dist/prod/core/constants.js +112 -177
  43. package/dist/prod/core/context.js +3 -3
  44. package/dist/prod/core/core.js +852 -1448
  45. package/dist/prod/core/effect.js +88 -99
  46. package/dist/prod/core/external.js +5 -5
  47. package/dist/prod/core/graph.js +61 -70
  48. package/dist/prod/core/heap.js +75 -98
  49. package/dist/prod/core/invariants.js +1 -32
  50. package/dist/prod/core/lanes.js +666 -181
  51. package/dist/prod/core/owner.js +75 -96
  52. package/dist/prod/core/scheduler.js +677 -1332
  53. package/dist/prod/core/verdict.js +297 -621
  54. package/dist/prod/flatten.js +77 -0
  55. package/dist/prod/index.js +15 -13
  56. package/dist/prod/map.js +143 -146
  57. package/dist/prod/reveal.js +212 -0
  58. package/dist/prod/signals.js +144 -226
  59. package/dist/prod/store/affects.js +135 -0
  60. package/dist/prod/store/index.js +28 -19
  61. package/dist/prod/store/optimistic.js +533 -0
  62. package/dist/prod/store/projection.js +295 -0
  63. package/dist/prod/store/reconcile.js +257 -0
  64. package/dist/prod/store/store.js +1840 -272
  65. package/dist/prod/store/storePath.js +1 -1
  66. package/dist/{observe/store/next → prod/store}/target.js +13 -17
  67. package/dist/prod/store/types.js +73 -0
  68. package/dist/prod/store/utils.js +1 -11
  69. package/dist/types/affects.d.ts +11 -30
  70. package/dist/types/boundaries.d.ts +62 -176
  71. package/dist/types/carved.d.ts +1 -0
  72. package/dist/types/core/action.d.ts +5 -6
  73. package/dist/types/core/async.d.ts +10 -5
  74. package/dist/types/core/attribution-hooks.d.ts +48 -1
  75. package/dist/types/core/attribution.d.ts +29 -9
  76. package/dist/types/core/constants.d.ts +125 -171
  77. package/dist/types/core/core.d.ts +104 -264
  78. package/dist/types/core/dev.d.ts +60 -7
  79. package/dist/types/core/effect.d.ts +0 -7
  80. package/dist/types/core/graph.d.ts +7 -1
  81. package/dist/types/core/heap.d.ts +5 -7
  82. package/dist/types/core/index.d.ts +6 -6
  83. package/dist/types/core/invariants.d.ts +0 -29
  84. package/dist/types/core/lanes.d.ts +65 -87
  85. package/dist/types/core/owner.d.ts +3 -3
  86. package/dist/types/core/scheduler.d.ts +249 -331
  87. package/dist/types/core/types.d.ts +51 -85
  88. package/dist/types/core/verdict.d.ts +3 -0
  89. package/dist/types/flatten.d.ts +8 -0
  90. package/dist/types/index.d.ts +7 -5
  91. package/dist/types/reveal.d.ts +19 -0
  92. package/dist/types/signals.d.ts +53 -92
  93. package/dist/types/store/affects.d.ts +1 -0
  94. package/dist/types/store/index.d.ts +35 -15
  95. package/dist/types/store/optimistic.d.ts +23 -0
  96. package/dist/types/store/projection.d.ts +18 -0
  97. package/dist/types/store/reconcile.d.ts +3 -0
  98. package/dist/types/store/store.d.ts +165 -143
  99. package/dist/types/store/storePath.d.ts +1 -1
  100. package/dist/types/store/target.d.ts +151 -0
  101. package/dist/types/store/types.d.ts +84 -0
  102. package/package.json +1 -1
  103. package/dist/observe/core/optimistic.js +0 -669
  104. package/dist/observe/store/next/optimistic.js +0 -717
  105. package/dist/observe/store/next/projection.js +0 -266
  106. package/dist/observe/store/next/reconcile.js +0 -375
  107. package/dist/observe/store/next/store.js +0 -2480
  108. package/dist/prod/core/optimistic.js +0 -658
  109. package/dist/prod/store/next/optimistic.js +0 -710
  110. package/dist/prod/store/next/projection.js +0 -257
  111. package/dist/prod/store/next/reconcile.js +0 -373
  112. package/dist/prod/store/next/store.js +0 -2356
  113. package/dist/types/core/optimistic.d.ts +0 -6
  114. package/dist/types/store/next/optimistic.d.ts +0 -25
  115. package/dist/types/store/next/projection.d.ts +0 -27
  116. package/dist/types/store/next/reconcile.d.ts +0 -10
  117. package/dist/types/store/next/store.d.ts +0 -143
  118. package/dist/types/store/next/target.d.ts +0 -196
@@ -1,34 +1,28 @@
1
- import { REACTIVE_DISPOSED, CONFIG_CHILD_COMPANIONS, STATUS_PENDING, CONFIG_AUTO_DISPOSE, REACTIVE_ZOMBIE, REACTIVE_IN_HEAP, REACTIVE_IN_HEAP_HEIGHT, CONFIG_TRANSPARENT, defaultContext } from "./constants.js";
1
+ import { defaultContext, CONFIG_TRANSPARENT, REACTIVE_DISPOSED, STATUS_PENDING, REACTIVE_FRAME_READ, CONFIG_AUTO_DISPOSE, REACTIVE_ZOMBIE } from "./constants.js";
2
2
 
3
- import { context, runWithOwner, pendingCheckActive, latestReadActive, tracking } from "./core.js";
3
+ import { context, runWithOwner, tracking } from "./core.js";
4
4
 
5
- import { unregisterRoot, registerRoot } from "./dev.js";
5
+ import { registerRoot, unregisterRoot } from "./dev.js";
6
6
 
7
7
  import { clearDeps, unobserved } from "./graph.js";
8
8
 
9
- import { deleteFromHeap, queueFor, insertIntoHeap, insertIntoHeapHeight } from "./heap.js";
9
+ import { deleteFromHeap } from "./heap.js";
10
10
 
11
- import { GlobalQueue, wokenTransitions, schedule, zombieQueue, dirtyQueue, globalQueue } from "./scheduler.js";
11
+ import { schedule, dirtyQueue } from "./scheduler.js";
12
12
 
13
- const PENDING_OWNER = {};
14
-
15
- // Dummy owner to trigger store's read() path
13
+ // L2 (step 2): the parked frame. A pass parks the previous frame's children
14
+ // and `_disposal` list on `_x._pendingFirstChild` / `_x._pendingDisposal`
15
+ // (`parkChildren`, core.ts); they keep reacting until the node's commit
16
+ // disposes them (`zombie` walk below) or the owner dies. `markDisposal` flags
17
+ // the parked subtree REACTIVE_ZOMBIE: the splice guard and the reawaken path
18
+ // key off it, and the heap defers a zombie's recompute past the seam (no
19
+ // second heap — the deferral list in scheduler.ts).
16
20
  function markDisposal(e) {
17
- let n = e._n;
21
+ let n = e.sn;
18
22
  while (n) {
19
- const e = n.oe;
20
- n.oe = e | REACTIVE_ZOMBIE;
21
- // migrate height-adjust entries too, not just recompute entries: every
22
- // `deleteFromHeap` call site picks the queue from the zombie flag, so a
23
- // node left physically linked in `dirtyQueue` after being zombified gets
24
- // unlinked from the wrong queue on dispose, corrupting the bucket and
25
- // livelocking the next `runHeap` that reaches it (#2759)
26
- if (e & (REACTIVE_IN_HEAP | REACTIVE_IN_HEAP_HEIGHT)) {
27
- deleteFromHeap(n, e & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue);
28
- if (e & REACTIVE_IN_HEAP) insertIntoHeap(n, zombieQueue); else insertIntoHeapHeight(n, zombieQueue);
29
- }
23
+ n.R |= REACTIVE_ZOMBIE;
30
24
  markDisposal(n);
31
- n = n.Fn;
25
+ n = n.rn;
32
26
  }
33
27
  }
34
28
 
@@ -39,47 +33,35 @@ function dispose(e) {
39
33
  // left queued would be recomputed and resurrected by the next flush (#2983)
40
34
  // — dep unlinking, child disposal) is exactly unobserved()'s body; only
41
35
  // this flag distinguishes death from dormancy.
42
- e.C &= ~CONFIG_AUTO_DISPOSE;
36
+ e.u &= ~CONFIG_AUTO_DISPOSE;
43
37
  unobserved(e);
44
38
  }
45
39
 
46
40
  function disposeChildren(e, n = false, t) {
47
- const i = e.oe;
41
+ const i = e.R;
48
42
  if (i & REACTIVE_DISPOSED) return;
49
- // A previous frame parked as zombies (#3404) dies with its owner (#3024):
50
- // the commit that would retire it returns on the DISPOSED flag set below,
51
- // so it drains here or its cleanups never run and the zombies stay
52
- // subscribed, to rerun in a torn-down tree (#3561). Death only (`self`):
53
- // a rerun's `disposeChildren(el)` leaves the frame rendering until commit.
54
- if (n && !t && e.o !== null && (e.o.dt !== null || e.o.Et !== null)) disposeChildren(e, false, true);
43
+ // A parked frame dies with its owner (#3024): the commit that would retire
44
+ // it never comes once the node is DISPOSED, so it drains here or its
45
+ // cleanups never run and it stays subscribed, rerunning in a torn-down
46
+ // tree (#3561). Death only (`self`): a re-pass leaves the frame reacting
47
+ // until the commit.
48
+ if (n && !t && e.m !== null && (e.m.St !== null || e.m.ct !== null)) disposeChildren(e, false, true);
55
49
  if (n) {
56
- e.oe = i | REACTIVE_DISPOSED;
57
- if (e._parent === null && e.Zt) unregisterRoot(e);
58
- // Companions are created detached and outlive their owner, but a verdict
59
- // must not: a disposed source can never settle, so an isPending companion
60
- // latched `true` here would hold a spinner forever (INV-9, the PR #2845
61
- // edge). Snap runs after the DISPOSED flag is set so the oracle reads
62
- // false, and notifies subscribers still watching the companion.
63
- const n = e;
64
- if (n.o?.xe || n.o?.Me) GlobalQueue.Qn(n);
65
- // A firewall's leaves have no lifecycle of their own, so a companion on
66
- // one of them outlives its source the same way (INV-9's rationale). The
67
- // firewall knows which leaves carry companions (CONFIG_CHILD_COMPANIONS,
68
- // #3038): snap them with it — the snap retires a shadow whose firewall is
69
- // disposed (spec O5).
70
- if (n.C & CONFIG_CHILD_COMPANIONS) n.o.xt.forEach(GlobalQueue.Qn);
71
- // A pending reader parked in a transaction may be the only thing holding
72
- // it (#3372): its death is a completion event the transaction must be
73
- // re-judged for, and nothing else re-enters a parked transaction.
74
- const t = n.me;
75
- if (t && n.S & STATUS_PENDING && !wokenTransitions.includes(t)) wokenTransitions.push(t),
76
- schedule();
50
+ e.R = i | REACTIVE_DISPOSED;
51
+ if (e._parent === null && e.Ht) unregisterRoot(e);
52
+ }
53
+ if (n && e.re) {
54
+ if (e.m !== null) e.m.De = null;
55
+ // A death that can unblock the future (L2, `futureBlocked`): a held
56
+ // flight's — a transaction's or a lane's (its `_x._transaction`) — or a
57
+ // stale reader's (REACTIVE_FRAME_READ — a frame that derived from one).
58
+ // Nothing else re-examines a dead node, so make sure a seam comes.
59
+ if (e.G & STATUS_PENDING && e.m?._t != null || i & REACTIVE_FRAME_READ) schedule();
77
60
  }
78
- if (n && e.Se && e.o !== null) e.o.pe = null;
79
- let o = t ? e.o?.dt ?? null : e._n;
80
- if (!t) e._n = null;
81
- while (o) {
82
- const e = o;
61
+ let r = t ? e.m.St : e.sn;
62
+ if (t) e.m.St = null; else e.sn = null;
63
+ while (r) {
64
+ const e = r;
83
65
  // Owner teardown is death regardless of the child's own lifecycle
84
66
  // (#3024): strip AUTO_DISPOSE so a post-disposal read freezes at the
85
67
  // last committed value instead of reawakening in a torn-down tree.
@@ -87,7 +69,7 @@ function disposeChildren(e, n = false, t) {
87
69
  // disposeChildren call early-returns on REACTIVE_DISPOSED) die too.
88
70
  // Only unobserved()'s own node keeps its dormancy — it is never in
89
71
  // this loop; its children are rebuilt fresh on reawaken.
90
- e.C &= ~CONFIG_AUTO_DISPOSE;
72
+ e.u &= ~CONFIG_AUTO_DISPOSE;
91
73
  // Heap removal must not be gated on `_deps`: a dependency-free
92
74
  // computation queued by refresh() has a null dep list but still sits in
93
75
  // the dirty heap, and left there the post-disposal flush recomputes it —
@@ -95,50 +77,49 @@ function disposeChildren(e, n = false, t) {
95
77
  // comes back to life (post-unmount runs, leaked cleanups, #2983).
96
78
  // deleteFromHeap self-guards on the in-heap flags (and tolerates plain
97
79
  // Owners, whose _flags is undefined), so no gate here.
98
- deleteFromHeap(e, queueFor(e));
80
+ deleteFromHeap(e, dirtyQueue);
99
81
  clearDeps(e);
100
82
  // The chain is detached above so a node a cleanup links mid-drain lands
101
83
  // on the fresh head and survives. Pointing each drained child's prev at
102
84
  // itself routes its later splice onto the detached chain, never the head,
103
85
  // and keeps the dev owner-chain-head invariant honest for those children.
104
- o.kt = o;
105
- disposeChildren(o, true);
86
+ r.Gt = r;
87
+ disposeChildren(r, true);
106
88
  // Read after, not before: a sibling this disposal made dormant spliced
107
89
  // itself out of the detached chain, and a cleanup may then have linked
108
90
  // it at the fresh head, which rewrote the `_nextSibling` a pre-read
109
91
  // would still be holding.
110
- o = o.Fn;
92
+ r = r.rn;
111
93
  }
112
- if (t) {
113
- if (e.o !== null) e.o.dt = null;
114
- } else e.Nt = 0;
94
+ if (!t) e.Ct = 0;
115
95
  // O(1) splice out of parent's chain on individual dispose. Skipped during
116
- // batch dispose (parent already disposed) and zombie disposal (node sits on
117
- // parent's _pendingFirstChild). We leave node._nextSibling intact so outer
118
- // walks that already advanced past us still reach later siblings.
119
- if (n && !t && !(i & REACTIVE_ZOMBIE) && e._parent !== null && !(e._parent.oe & REACTIVE_DISPOSED)) {
120
- const n = e.kt;
121
- const t = e.Fn;
122
- if (n !== null) n.Fn = t; else e._parent._n = t;
123
- if (t !== null) t.kt = n;
124
- e.kt = null;
96
+ // batch dispose (parent already disposed) and for a zombie (it sits on the
97
+ // parent's parked frame, drained whole by the commit). We leave
98
+ // node._nextSibling intact so outer walks that already advanced past us
99
+ // still reach later siblings.
100
+ if (n && !t && !(i & REACTIVE_ZOMBIE) && e._parent !== null && !(e._parent.R & REACTIVE_DISPOSED)) {
101
+ const n = e.Gt;
102
+ const t = e.rn;
103
+ if (n !== null) n.rn = t; else e._parent.sn = t;
104
+ if (t !== null) t.Gt = n;
105
+ e.Gt = null;
125
106
  }
126
107
  runDisposal(e, t);
127
108
  // Final effect-returned cleanup fires at true disposal, after `_disposal`
128
109
  // to mirror rerun ordering (compute-phase teardown first, cleanup last).
129
- if (n && e.qt) {
130
- const n = e.qt;
131
- e.qt = undefined;
110
+ if (n && e.kt) {
111
+ const n = e.kt;
112
+ e.kt = undefined;
132
113
  n();
133
114
  }
134
115
  }
135
116
 
136
117
  function linkChild(e, n) {
137
- const t = e._n;
138
- n.kt = null;
139
- n.Fn = t;
140
- if (t !== null) t.kt = n;
141
- e._n = n;
118
+ const t = e.sn;
119
+ n.Gt = null;
120
+ n.rn = t;
121
+ if (t !== null) t.Gt = n;
122
+ e.sn = n;
142
123
  }
143
124
 
144
125
  function runDisposal(e, n) {
@@ -148,9 +129,9 @@ function runDisposal(e, n) {
148
129
  // walk ran every entry a second time. Detached, the re-entrant drain finds
149
130
  // nothing. The same shape latched a throwing cleanup: the list survived the
150
131
  // throw and every later drain re-ran and re-threw it.
151
- const t = n ? e.o?.Et : e.Ve;
132
+ const t = n ? e.m.ct : e.Pe;
152
133
  if (!t) return;
153
- if (n) e.o.Et = null; else e.Ve = null;
134
+ if (n) e.m.ct = null; else e.Pe = null;
154
135
  if (Array.isArray(t)) {
155
136
  // Unwind order (#3572, restores 1.x #1562): later registrations run
156
137
  // before earlier ones. Children have already been disposed by the caller,
@@ -167,8 +148,8 @@ function runDisposal(e, n) {
167
148
 
168
149
  function childId(e, n) {
169
150
  let t = e;
170
- while (t.C & CONFIG_TRANSPARENT && t._parent) t = t._parent;
171
- if (t.id != null) return formatId(t.id, n ? t.Nt++ : t.Nt);
151
+ while (t.u & CONFIG_TRANSPARENT && t._parent) t = t._parent;
152
+ if (t.id != null) return formatId(t.id, n ? t.Ct++ : t.Ct);
172
153
  throw new Error("");
173
154
  }
174
155
 
@@ -219,7 +200,6 @@ function formatId(e, n) {
219
200
  * }
220
201
  * ```
221
202
  */ function getObserver() {
222
- if (pendingCheckActive || latestReadActive) return PENDING_OWNER;
223
203
  return tracking ? context : null;
224
204
  }
225
205
 
@@ -249,14 +229,14 @@ function formatId(e, n) {
249
229
  * checks. `cleanup()` is the unchecked primitive used by internals.
250
230
  */ function cleanup(e) {
251
231
  if (!context) return e;
252
- if (!context.Ve) context.Ve = e; else if (Array.isArray(context.Ve)) context.Ve.push(e); else context.Ve = [ context.Ve, e ];
232
+ if (!context.Pe) context.Pe = e; else if (Array.isArray(context.Pe)) context.Pe.push(e); else context.Pe = [ context.Pe, e ];
253
233
  return e;
254
234
  }
255
235
 
256
236
  /**
257
- * Returns `true` if the owner has been disposed (or marked zombie pending
258
- * disposal). Pair with a captured owner to bail out of late callbacks whose
259
- * surrounding component already unmounted.
237
+ * Returns `true` if the owner has been disposed. Pair with a captured owner
238
+ * to bail out of late callbacks whose surrounding component already
239
+ * unmounted.
260
240
  *
261
241
  * @example
262
242
  * ```ts
@@ -269,7 +249,7 @@ function formatId(e, n) {
269
249
  * }
270
250
  * ```
271
251
  */ function isDisposed(e) {
272
- return !!(e.oe & (REACTIVE_DISPOSED | REACTIVE_ZOMBIE));
252
+ return !!(e.R & REACTIVE_DISPOSED);
273
253
  }
274
254
 
275
255
  function disposeRootSelf(e = true) {
@@ -292,17 +272,16 @@ function disposeRootSelf(e = true) {
292
272
  // is a plain store rather than a shape fork between labelled and plain roots.
293
273
  const i = {
294
274
  id: inheritId(e, t, n),
295
- C: t ? CONFIG_TRANSPARENT : 0,
296
- Zt: true,
297
- Yt: n?.Zt ? n.Yt : n,
298
- _n: null,
299
- Fn: null,
300
- kt: null,
301
- Ve: null,
302
- T: n?.T ?? globalQueue,
303
- rt: n?.rt || defaultContext,
304
- Nt: 0,
305
- o: null,
275
+ u: t ? CONFIG_TRANSPARENT : 0,
276
+ Ht: true,
277
+ gt: n?.Ht ? n.gt : n,
278
+ sn: null,
279
+ rn: null,
280
+ Gt: null,
281
+ Pe: null,
282
+ U: n?.U || defaultContext,
283
+ Ct: 0,
284
+ m: null,
306
285
  _parent: n,
307
286
  dispose: disposeRootSelf,
308
287
  _name: undefined