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

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 (90) hide show
  1. package/dist/dev-shared.js +2268 -1734
  2. package/dist/dev.attribution.js +75 -52
  3. package/dist/dev.js +1348 -658
  4. package/dist/observe/affects-marks.js +86 -0
  5. package/dist/observe/affects.js +22 -73
  6. package/dist/observe/boundaries.js +192 -190
  7. package/dist/observe/core/async.js +177 -131
  8. package/dist/observe/core/attribution-queries.js +1 -1
  9. package/dist/observe/core/attribution.js +176 -159
  10. package/dist/observe/core/constants.js +17 -3
  11. package/dist/observe/core/context.js +5 -3
  12. package/dist/observe/core/core.js +520 -364
  13. package/dist/observe/core/dev.js +66 -38
  14. package/dist/observe/core/effect.js +50 -48
  15. package/dist/observe/core/error.js +5 -3
  16. package/dist/observe/core/external.js +5 -6
  17. package/dist/observe/core/graph.js +60 -44
  18. package/dist/observe/core/heap.js +33 -33
  19. package/dist/observe/core/identities.js +62 -0
  20. package/dist/observe/core/lanes.js +238 -260
  21. package/dist/observe/core/owner.js +117 -79
  22. package/dist/observe/core/scheduler.js +381 -217
  23. package/dist/observe/core/truth.js +45 -0
  24. package/dist/observe/core/verdict.js +91 -50
  25. package/dist/observe/deferred.js +184 -0
  26. package/dist/observe/index.js +7 -1
  27. package/dist/observe/map.js +345 -260
  28. package/dist/observe/reveal.js +76 -76
  29. package/dist/observe/signals.js +47 -31
  30. package/dist/observe/store/affects.js +18 -18
  31. package/dist/observe/store/edges.js +39 -0
  32. package/dist/observe/store/optimistic.js +146 -100
  33. package/dist/observe/store/projection.js +68 -55
  34. package/dist/observe/store/store.js +180 -118
  35. package/dist/prod/affects-marks.js +86 -0
  36. package/dist/prod/affects.js +23 -72
  37. package/dist/prod/boundaries.js +156 -154
  38. package/dist/prod/core/async.js +173 -127
  39. package/dist/prod/core/constants.js +17 -3
  40. package/dist/prod/core/context.js +5 -3
  41. package/dist/prod/core/core.js +495 -343
  42. package/dist/prod/core/effect.js +70 -68
  43. package/dist/prod/core/error.js +5 -3
  44. package/dist/prod/core/external.js +5 -6
  45. package/dist/prod/core/graph.js +60 -44
  46. package/dist/prod/core/heap.js +38 -38
  47. package/dist/prod/core/identities.js +62 -0
  48. package/dist/prod/core/lanes.js +230 -252
  49. package/dist/prod/core/owner.js +114 -77
  50. package/dist/prod/core/scheduler.js +327 -163
  51. package/dist/prod/core/truth.js +45 -0
  52. package/dist/prod/core/verdict.js +90 -49
  53. package/dist/prod/deferred.js +182 -0
  54. package/dist/prod/index.js +7 -1
  55. package/dist/prod/map.js +360 -275
  56. package/dist/prod/reveal.js +76 -76
  57. package/dist/prod/signals.js +42 -26
  58. package/dist/prod/store/affects.js +6 -6
  59. package/dist/prod/store/edges.js +39 -0
  60. package/dist/prod/store/optimistic.js +143 -98
  61. package/dist/prod/store/projection.js +25 -19
  62. package/dist/prod/store/store.js +157 -100
  63. package/dist/types/affects-marks.d.ts +14 -0
  64. package/dist/types/boundaries.d.ts +1 -1
  65. package/dist/types/core/async.d.ts +10 -0
  66. package/dist/types/core/constants.d.ts +13 -1
  67. package/dist/types/core/core.d.ts +54 -5
  68. package/dist/types/core/dev.d.ts +51 -13
  69. package/dist/types/core/error.d.ts +9 -1
  70. package/dist/types/core/graph.d.ts +11 -0
  71. package/dist/types/core/identities.d.ts +17 -0
  72. package/dist/types/core/index.d.ts +2 -1
  73. package/dist/types/core/lanes.d.ts +2 -14
  74. package/dist/types/core/owner.d.ts +9 -3
  75. package/dist/types/core/scheduler.d.ts +70 -32
  76. package/dist/types/core/truth.d.ts +16 -0
  77. package/dist/types/core/types.d.ts +21 -0
  78. package/dist/types/core/verdict.d.ts +32 -0
  79. package/dist/types/deferred.d.ts +28 -0
  80. package/dist/types/index.d.ts +6 -0
  81. package/dist/types/map.d.ts +2 -2
  82. package/dist/types/signals.d.ts +28 -7
  83. package/dist/types/store/edges.d.ts +9 -0
  84. package/dist/types/store/index.d.ts +10 -3
  85. package/dist/types/store/optimistic.d.ts +3 -2
  86. package/dist/types/store/projection.d.ts +4 -3
  87. package/dist/types/store/store.d.ts +1 -1
  88. package/dist/types/store/target.d.ts +16 -8
  89. package/dist/types/store/types.d.ts +14 -0
  90. package/package.json +1 -1
@@ -0,0 +1,86 @@
1
+ import { CONFIG_VERDICT, CONFIG_AUTHORITATIVE, STATUS_ERROR, CONFIG_SLOT_NODE, REACTIVE_RECOMPUTING_DEPS } from "./core/constants.js";
2
+
3
+ import { ext } from "./core/core.js";
4
+
5
+ import { enqueueSub } from "./core/heap.js";
6
+
7
+ import { GlobalQueue } from "./core/scheduler.js";
8
+
9
+ // The mark core: a declared not-final state on a node that reads pending
10
+ // (`isPending` → true) on the node and everything derived from it, without
11
+ // holding anything or entangling a reader. Two declarers share it:
12
+ // `affects()` (affects.ts — a mark scoped to a transaction, with a store
13
+ // half) and `createDeferred` (deferred.ts — a mark whose lifetime is the
14
+ // node's own flight). Split out so the second does not ship the first.
15
+ // Representation: a count on the marked node (`_x._marks`). Coverage of the
16
+ // derivations is pull-derived at probe time — `isPending`'s read walks the
17
+ // probed node's dependencies for a marked one (verdict.ts → `_marked`) — so
18
+ // nothing is stored downstream and a mid-window recompute strands nothing.
19
+ // The push half is the verdict readers' re-derivation when a node's marks
20
+ // start and end (`repoll`): the only notification a mark makes.
21
+ /** Live marks, every declarer — the gate on the probe's walk. */
22
+ let active = 0;
23
+
24
+ /** The verdict readers downstream of `node` — through derivations, stopping
25
+ * at effects — re-derive: the mark's one notification (a probe's answer
26
+ * changed with no value notifying anyone). Truth readers (`until`, the
27
+ * `refresh` waiter) too, which a lagging flight parked (deferred.ts) — but
28
+ * not through a derived store, whose leaves change only once its derive
29
+ * re-runs: they re-derive at that write. */ function repoll(e, r = new Set, o = CONFIG_VERDICT | CONFIG_AUTHORITATIVE) {
30
+ for (let t = e.o; t !== null; t = t.t) {
31
+ const e = t.u;
32
+ if (r.has(e)) continue;
33
+ r.add(e);
34
+ if (e.l & o) enqueueSub(e);
35
+ if (!e.i) repoll(e, r, o);
36
+ // A derived store's derive: its leaves' readers derive from it too
37
+ // (store/projection.ts; a live target's property, has and keys nodes).
38
+ const n = e.fam;
39
+ if (n) for (const e of n.live) for (const o of [ e.n, e.h, {
40
+ k: e.k,
41
+ d: e.dk
42
+ } ]) if (o) for (const e of Reflect.ownKeys(o)) o[e] && repoll(o[e], r, CONFIG_VERDICT);
43
+ }
44
+ }
45
+
46
+ /** A node is covered by a live mark iff it carries one, or derives — through
47
+ * its current dependencies — from one that does. A store slot derives from
48
+ * its family's derive (a derived store's leaves are not the derive's
49
+ * dependents, store/projection.ts), so coverage hops there. A real error
50
+ * outranks an inherited mark (A24 (c)): coverage does not flow through an
51
+ * errored node (a direct mark on one still reads pending). Mid-recompute,
52
+ * only the validated prefix of the dependency list is this pass's. */ function marked(e, r) {
53
+ if (e.T !== null && e.T.I !== 0) return true;
54
+ const o = e;
55
+ if (o.m & STATUS_ERROR || r.has(e)) return false;
56
+ r.add(e);
57
+ if (o.l & CONFIG_SLOT_NODE) {
58
+ const e = o.O?.fam?.node;
59
+ return e != null && marked(e, r);
60
+ }
61
+ const t = o.R & REACTIVE_RECOMPUTING_DEPS ? o._ : undefined;
62
+ if (t !== null) for (let e = o.C ?? null; e !== null; e = e.G) {
63
+ if (marked(e.S, r)) return true;
64
+ if (e === t) break;
65
+ }
66
+ return false;
67
+ }
68
+
69
+ /** One mark on `node`. The declarer repolls once its bookkeeping is done. */ function mark(e) {
70
+ ext(e).I++;
71
+ active++;
72
+ }
73
+
74
+ /** Drops one mark from `node`: true when it was the last — the node's
75
+ * verdict readers have re-derived. */ function unmark(e) {
76
+ active--;
77
+ if (--e.T.I !== 0) return false;
78
+ repoll(e);
79
+ return true;
80
+ }
81
+
82
+ GlobalQueue.p = e => active !== 0 && marked(e, new Set);
83
+
84
+ GlobalQueue.N = mark;
85
+
86
+ export { mark, repoll, unmark };
@@ -1,12 +1,10 @@
1
- import { $REFRESH, CONFIG_VERDICT, STATUS_PENDING, CONFIG_SLOT_NODE, STATUS_ERROR, REACTIVE_RECOMPUTING_DEPS } from "./core/constants.js";
2
-
3
- import { ext } from "./core/core.js";
1
+ import { $REFRESH, STATUS_PENDING, CONFIG_SLOT_NODE } from "./core/constants.js";
4
2
 
5
3
  import "./core/dev.js";
6
4
 
7
- import { enqueueSub } from "./core/heap.js";
5
+ import { schedule, resolveTx, flushTransaction, installMarkHooks, GlobalQueue } from "./core/scheduler.js";
8
6
 
9
- import { schedule, resolveTx, flushTransaction, GlobalQueue } from "./core/scheduler.js";
7
+ import { mark, repoll, unmark } from "./affects-marks.js";
10
8
 
11
9
  import { storeMarks, installStoreAffects, releaseMarkScope } from "./store/affects.js";
12
10
 
@@ -23,60 +21,22 @@ import { $TARGET } from "./store/types.js";
23
21
  // a node of its transaction (`blocked` never sees it), and a reader of marked
24
22
  // data joins nothing through it. A mark is never a re-ask, so a declared
25
23
  // reload's own `refresh()` cannot silence it; a real error outranks it.
26
- // Representation: a count on the marked node (`_x._marks`), listed with its
27
- // scope (the transaction's `_marks`, or the ambient list). Coverage of the
28
- // derivations is pull-derived at probe time — `isPending`'s read walks the
29
- // probed node's dependencies for a marked one (verdict.ts → `_marked`) — so
30
- // nothing is stored downstream and a mid-window recompute strands nothing.
31
- // The push half is the verdict readers' re-derivation at registration and at
32
- // release (`repoll`): the only notification a mark makes.
24
+ // Representation: the mark core (affects-marks.ts) — a count on the marked
25
+ // node, coverage pull-derived at probe time, readers repolled at registration
26
+ // and release. Here: each mark's scope (the transaction's `_marks`, or the
27
+ // ambient list) and the store half.
33
28
  // Installed on `GlobalQueue` when imported: a program that never declares a
34
29
  // mark carries none of this.
35
- /** Live marks, every scope — the gate on the probe's walk. */
36
- let active = 0;
37
-
38
- /** Marks declared outside a transaction: released at the next seam. */ const ambient = [];
39
-
40
- /** The verdict readers downstream of `node` — through derivations, stopping
41
- * at effects — re-derive: the mark's one notification (a probe's answer
42
- * changed with no value notifying anyone). */ function repoll(e, t = new Set) {
43
- for (let r = e.t; r !== null; r = r.o) {
44
- const e = r.l;
45
- if (t.has(e)) continue;
46
- t.add(e);
47
- if (e.i & CONFIG_VERDICT) enqueueSub(e);
48
- if (!e.u) repoll(e, t);
49
- }
50
- }
51
-
52
- /** A node is covered by a live mark iff it carries one, or derives — through
53
- * its current dependencies — from one that does. A real error outranks an
54
- * inherited mark (A24 (c)): coverage does not flow through an errored node
55
- * (a direct mark on one still reads pending). Mid-recompute, only the
56
- * validated prefix of the dependency list is this pass's. */ function marked(e, t) {
57
- if (e.m !== null && e.m.T !== 0) return true;
58
- const r = e;
59
- if (r.S & STATUS_ERROR || t.has(e)) return false;
60
- t.add(e);
61
- const n = r.R & REACTIVE_RECOMPUTING_DEPS ? r.p : undefined;
62
- if (n !== null) for (let e = r.G ?? null; e !== null; e = e._) {
63
- if (marked(e.I, t)) return true;
64
- if (e === n) break;
65
- }
66
- return false;
67
- }
30
+ /** Marks declared outside a transaction: released at the next seam. */
31
+ const ambient = [];
68
32
 
69
33
  /** Releases one scope's marks (a landed transaction's, the ambient list at
70
34
  * the seam): a node whose last mark drops re-derives its verdict readers. */ function release(e) {
71
35
  for (let t = 0; t < e.length; t++) {
72
36
  const r = e[t];
73
- active--;
74
- if (--r.m.T === 0) {
75
- repoll(r);
76
- // A store mark's carrier: its scope (and the marks the nodes born in
77
- // its window inherited) goes with it.
78
- releaseMarkScope(r);
79
- }
37
+ // A store mark's carrier: its scope (and the marks the nodes born in
38
+ // its window inherited) goes with the last mark.
39
+ if (unmark(r)) releaseMarkScope(r);
80
40
  }
81
41
  e.length = 0;
82
42
  }
@@ -87,16 +47,11 @@ let active = 0;
87
47
  const t = flushTransaction;
88
48
  if (t === null) ambient.push(e); else {
89
49
  const r = resolveTx(t);
90
- (r.T ??= []).push(e);
50
+ (r.I ??= []).push(e);
91
51
  }
92
52
  repoll(e);
93
53
  }
94
54
 
95
- function mark(e) {
96
- ext(e).T++;
97
- active++;
98
- }
99
-
100
55
  function affects(e, t) {
101
56
  // A store (the store half, store/affects.ts): the slot's leaf, or the
102
57
  // record's carrier and every live node under it.
@@ -108,26 +63,20 @@ function affects(e, t) {
108
63
  schedule();
109
64
  return;
110
65
  }
111
- const n = e?.[$REFRESH];
112
- if (!n) {
66
+ const s = e?.[$REFRESH];
67
+ if (!s) {
113
68
  return;
114
69
  }
115
- register(n);
70
+ register(s);
116
71
  schedule();
117
72
  }
118
73
 
119
- GlobalQueue.N = e => active !== 0 && marked(e, new Set);
120
-
121
- GlobalQueue.O = mark;
122
-
123
- GlobalQueue.k = release;
124
-
125
- GlobalQueue.A = e => {
74
+ installMarkHooks(release, e => {
126
75
  if (ambient.length === 0) return;
127
76
  // The flush parked: the declaration's window is the frame's — the marks
128
77
  // are its transaction's ("nothing async below ⇒ no window").
129
78
  if (e !== null) {
130
- const t = e.T ??= [];
79
+ const t = e.I ??= [];
131
80
  for (let e = 0; e < ambient.length; e++) t.push(ambient[e]);
132
81
  ambient.length = 0;
133
82
  return;
@@ -139,15 +88,15 @@ GlobalQueue.A = e => {
139
88
  let t = 0;
140
89
  const r = [];
141
90
  for (let e = 0; e < ambient.length; e++) {
142
- const n = ambient[e];
143
- if (inFlight(n)) ambient[t++] = n; else r.push(n);
91
+ const s = ambient[e];
92
+ if (inFlight(s)) ambient[t++] = s; else r.push(s);
144
93
  }
145
94
  ambient.length = t;
146
95
  if (r.length !== 0) release(r);
147
- };
96
+ });
148
97
 
149
98
  function inFlight(e) {
150
- return (e.S & STATUS_PENDING) !== 0 || (e.i & CONFIG_SLOT_NODE) !== 0 && GlobalQueue.C?.(e) === true;
99
+ return (e.m & STATUS_PENDING) !== 0 || (e.l & CONFIG_SLOT_NODE) !== 0 && GlobalQueue.k?.(e) === true;
151
100
  }
152
101
 
153
102
  export { affects };