@solidjs/signals 2.0.0-rc.13 → 2.0.0-rc.15

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