@solidjs/signals 2.0.0-rc.2 → 2.0.0-rc.20

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 (198) hide show
  1. package/dist/dev-shared.js +6505 -0
  2. package/dist/dev.attribution.js +3484 -0
  3. package/dist/dev.js +10227 -9508
  4. package/dist/observe/affects-marks.js +86 -0
  5. package/dist/observe/affects.js +112 -0
  6. package/dist/observe/attribution.js +7 -0
  7. package/dist/observe/boundaries.js +696 -0
  8. package/dist/observe/core/action.js +182 -0
  9. package/dist/observe/core/async.js +824 -0
  10. package/dist/observe/core/attribution-costs.js +66 -0
  11. package/dist/observe/core/attribution-feedback.js +280 -0
  12. package/dist/observe/core/attribution-hooks.js +83 -0
  13. package/dist/observe/core/attribution-queries.js +43 -0
  14. package/dist/observe/core/attribution.js +3079 -0
  15. package/dist/observe/core/constants.js +269 -0
  16. package/dist/observe/core/context.js +63 -0
  17. package/dist/observe/core/copies.js +10 -0
  18. package/dist/observe/core/core.js +1707 -0
  19. package/dist/observe/core/dev.js +394 -0
  20. package/dist/observe/core/effect.js +193 -0
  21. package/dist/observe/core/error-hooks.js +71 -0
  22. package/dist/observe/core/error.js +82 -0
  23. package/dist/observe/core/external.js +97 -0
  24. package/dist/observe/core/graph.js +162 -0
  25. package/dist/observe/core/heap.js +124 -0
  26. package/dist/observe/core/identities.js +62 -0
  27. package/dist/observe/core/invariants.js +12 -0
  28. package/dist/observe/core/lanes.js +972 -0
  29. package/dist/observe/core/owner.js +371 -0
  30. package/dist/observe/core/scheduler.js +1157 -0
  31. package/dist/observe/core/truth.js +47 -0
  32. package/dist/observe/core/verdict.js +470 -0
  33. package/dist/observe/deferred.js +186 -0
  34. package/dist/observe/flatten.js +79 -0
  35. package/dist/observe/from.js +248 -0
  36. package/dist/observe/index.js +71 -0
  37. package/dist/observe/map.js +593 -0
  38. package/dist/observe/reveal.js +212 -0
  39. package/dist/observe/signals.js +717 -0
  40. package/dist/observe/store/affects.js +142 -0
  41. package/dist/observe/store/edges.js +39 -0
  42. package/dist/observe/store/hooks.js +16 -0
  43. package/dist/observe/store/index.js +47 -0
  44. package/dist/observe/store/optimistic.js +713 -0
  45. package/dist/observe/store/projection.js +345 -0
  46. package/dist/observe/store/reconcile.js +281 -0
  47. package/dist/observe/store/store.js +2127 -0
  48. package/dist/observe/store/storePath.js +103 -0
  49. package/dist/observe/store/target.js +46 -0
  50. package/dist/observe/store/types.js +83 -0
  51. package/dist/observe/store/utils.js +1063 -0
  52. package/dist/prod/affects-marks.js +86 -0
  53. package/dist/prod/affects.js +98 -112
  54. package/dist/prod/attribution.js +45 -0
  55. package/dist/prod/boundaries.js +578 -468
  56. package/dist/prod/core/action.js +92 -59
  57. package/dist/prod/core/async.js +522 -336
  58. package/dist/prod/core/attribution-hooks.js +3 -0
  59. package/dist/prod/core/constants.js +168 -44
  60. package/dist/prod/core/context.js +12 -16
  61. package/dist/prod/core/copies.js +10 -0
  62. package/dist/prod/core/core.js +1345 -627
  63. package/dist/prod/core/dev.js +123 -1
  64. package/dist/prod/core/effect.js +113 -80
  65. package/dist/prod/core/error-hooks.js +71 -0
  66. package/dist/prod/core/error.js +18 -4
  67. package/dist/prod/core/external.js +6 -7
  68. package/dist/prod/core/graph.js +119 -72
  69. package/dist/prod/core/heap.js +85 -109
  70. package/dist/prod/core/identities.js +62 -0
  71. package/dist/prod/core/invariants.js +1 -32
  72. package/dist/prod/core/lanes.js +931 -132
  73. package/dist/prod/core/owner.js +192 -129
  74. package/dist/prod/core/scheduler.js +948 -642
  75. package/dist/prod/core/truth.js +47 -0
  76. package/dist/prod/core/verdict.js +409 -420
  77. package/dist/prod/deferred.js +184 -0
  78. package/dist/prod/flatten.js +77 -0
  79. package/dist/prod/from.js +248 -0
  80. package/dist/prod/index.js +40 -16
  81. package/dist/prod/map.js +481 -211
  82. package/dist/prod/reveal.js +212 -0
  83. package/dist/prod/signals.js +401 -84
  84. package/dist/prod/store/affects.js +142 -0
  85. package/dist/prod/store/edges.js +39 -0
  86. package/dist/prod/store/hooks.js +16 -0
  87. package/dist/prod/store/index.js +27 -18
  88. package/dist/prod/store/optimistic.js +707 -0
  89. package/dist/prod/store/projection.js +331 -0
  90. package/dist/prod/store/reconcile.js +281 -0
  91. package/dist/prod/store/store.js +1952 -267
  92. package/dist/prod/store/storePath.js +1 -1
  93. package/dist/prod/store/target.js +43 -0
  94. package/dist/prod/store/types.js +83 -0
  95. package/dist/prod/store/utils.js +997 -138
  96. package/dist/types/affects-marks.d.ts +14 -0
  97. package/dist/types/affects.d.ts +12 -30
  98. package/dist/types/attribution.d.ts +19 -0
  99. package/dist/types/attribution.prod.d.ts +22 -0
  100. package/dist/types/boundaries.d.ts +99 -124
  101. package/dist/types/carved.d.ts +1 -0
  102. package/dist/types/core/action.d.ts +23 -9
  103. package/dist/types/core/async.d.ts +34 -6
  104. package/dist/types/core/attribution-costs.d.ts +35 -0
  105. package/dist/types/core/attribution-feedback.d.ts +133 -0
  106. package/dist/types/core/attribution-hooks.d.ts +307 -8
  107. package/dist/types/core/attribution-queries.d.ts +24 -0
  108. package/dist/types/core/attribution.d.ts +802 -72
  109. package/dist/types/core/constants.d.ts +195 -38
  110. package/dist/types/core/copies.d.ts +54 -0
  111. package/dist/types/core/core.d.ts +295 -65
  112. package/dist/types/core/dev.d.ts +509 -22
  113. package/dist/types/core/effect.d.ts +1 -1
  114. package/dist/types/core/error-hooks.d.ts +71 -0
  115. package/dist/types/core/error.d.ts +18 -1
  116. package/dist/types/core/graph.d.ts +40 -1
  117. package/dist/types/core/heap.d.ts +5 -5
  118. package/dist/types/core/identities.d.ts +17 -0
  119. package/dist/types/core/index.d.ts +11 -7
  120. package/dist/types/core/invariants.d.ts +1 -26
  121. package/dist/types/core/lanes.d.ts +74 -43
  122. package/dist/types/core/owner.d.ts +27 -9
  123. package/dist/types/core/scheduler.d.ts +353 -102
  124. package/dist/types/core/truth.d.ts +18 -0
  125. package/dist/types/core/types.d.ts +97 -71
  126. package/dist/types/core/verdict.d.ts +35 -0
  127. package/dist/types/deferred.d.ts +28 -0
  128. package/dist/types/flatten.d.ts +8 -0
  129. package/dist/types/from.d.ts +47 -0
  130. package/dist/types/index.d.ts +33 -7
  131. package/dist/types/map.d.ts +4 -2
  132. package/dist/types/reveal.d.ts +19 -0
  133. package/dist/types/signals.d.ts +196 -45
  134. package/dist/types/store/affects.d.ts +12 -0
  135. package/dist/types/store/edges.d.ts +9 -0
  136. package/dist/types/store/hooks.d.ts +62 -0
  137. package/dist/types/store/index.d.ts +42 -15
  138. package/dist/types/store/optimistic.d.ts +24 -45
  139. package/dist/types/store/projection.d.ts +17 -68
  140. package/dist/types/store/reconcile.d.ts +3 -46
  141. package/dist/types/store/store.d.ts +133 -136
  142. package/dist/types/store/storePath.d.ts +1 -1
  143. package/dist/types/store/target.d.ts +166 -0
  144. package/dist/types/store/types.d.ts +105 -0
  145. package/dist/types/store/utils.d.ts +188 -0
  146. package/package.json +31 -26
  147. package/dist/node.cjs +0 -8745
  148. package/dist/prod/core/optimistic.js +0 -265
  149. package/dist/prod/store/next/optimistic.js +0 -385
  150. package/dist/prod/store/next/projection.js +0 -172
  151. package/dist/prod/store/next/reconcile.js +0 -331
  152. package/dist/prod/store/next/store.js +0 -1499
  153. package/dist/prod/store/next/target.js +0 -20
  154. package/dist/types/core/optimistic.d.ts +0 -6
  155. package/dist/types/store/next/optimistic.d.ts +0 -20
  156. package/dist/types/store/next/projection.d.ts +0 -8
  157. package/dist/types/store/next/reconcile.d.ts +0 -3
  158. package/dist/types/store/next/store.d.ts +0 -77
  159. package/dist/types/store/next/target.d.ts +0 -117
  160. package/dist/types-cjs/affects.d.cts +0 -47
  161. package/dist/types-cjs/boundaries.d.cts +0 -175
  162. package/dist/types-cjs/core/action.d.cts +0 -64
  163. package/dist/types-cjs/core/async.d.cts +0 -21
  164. package/dist/types-cjs/core/attribution-hooks.d.cts +0 -52
  165. package/dist/types-cjs/core/attribution.d.cts +0 -186
  166. package/dist/types-cjs/core/constants.d.cts +0 -97
  167. package/dist/types-cjs/core/context.d.cts +0 -36
  168. package/dist/types-cjs/core/core.d.cts +0 -163
  169. package/dist/types-cjs/core/dev.d.cts +0 -81
  170. package/dist/types-cjs/core/effect.d.cts +0 -30
  171. package/dist/types-cjs/core/error.d.cts +0 -47
  172. package/dist/types-cjs/core/external.d.cts +0 -15
  173. package/dist/types-cjs/core/graph.d.cts +0 -6
  174. package/dist/types-cjs/core/heap.d.cts +0 -22
  175. package/dist/types-cjs/core/index.d.cts +0 -13
  176. package/dist/types-cjs/core/invariants.d.cts +0 -59
  177. package/dist/types-cjs/core/lanes.d.cts +0 -44
  178. package/dist/types-cjs/core/optimistic.d.cts +0 -6
  179. package/dist/types-cjs/core/owner.d.cts +0 -124
  180. package/dist/types-cjs/core/scheduler.d.cts +0 -180
  181. package/dist/types-cjs/core/types.d.cts +0 -192
  182. package/dist/types-cjs/core/verdict.d.cts +0 -2
  183. package/dist/types-cjs/index.d.cts +0 -10
  184. package/dist/types-cjs/map.d.cts +0 -69
  185. package/dist/types-cjs/package.json +0 -3
  186. package/dist/types-cjs/signals.d.cts +0 -624
  187. package/dist/types-cjs/store/index.d.cts +0 -19
  188. package/dist/types-cjs/store/next/optimistic.d.cts +0 -20
  189. package/dist/types-cjs/store/next/projection.d.cts +0 -8
  190. package/dist/types-cjs/store/next/reconcile.d.cts +0 -3
  191. package/dist/types-cjs/store/next/store.d.cts +0 -77
  192. package/dist/types-cjs/store/next/target.d.cts +0 -117
  193. package/dist/types-cjs/store/optimistic.d.cts +0 -45
  194. package/dist/types-cjs/store/projection.d.cts +0 -70
  195. package/dist/types-cjs/store/reconcile.d.cts +0 -46
  196. package/dist/types-cjs/store/store.d.cts +0 -138
  197. package/dist/types-cjs/store/storePath.d.cts +0 -58
  198. package/dist/types-cjs/store/utils.d.cts +0 -74
@@ -1,14 +1,27 @@
1
- import { globalQueue, activeTransition, currentTransition, schedule, flush } from "./scheduler.js";
2
-
3
1
  import { isThenable } from "./async.js";
4
2
 
5
3
  import "./core.js";
6
4
 
7
- function restoreTransition(e, r) {
8
- globalQueue.initTransition(e);
9
- const t = r();
10
- flush();
11
- return t;
5
+ import { joinFuture, newTransaction, enterAction, exitAction, resolveTx, schedule, actionDepth, flush, nextQuestion, setQuestion, question } from "./scheduler.js";
6
+
7
+ /** A slice of the body runs in the action's transaction: the flush that
8
+ * carries its writes parks into it (`joinFuture` — merging whatever the tick
9
+ * already joined: O1, an action that opens in a tick owns it; a second
10
+ * action in the tick, or one called from the body, merges into the first).
11
+ * A resumed slice drains at once: the seam parks what it wrote (the action
12
+ * holds the transaction open) or, the body having returned, lands it. A
13
+ * nested action resuming synchronously inside the outer body does not drain
14
+ * — that would park the outer's remaining writes' frame mid-slice; the outer
15
+ * step's own return does. */ function inTransaction(t, n, e) {
16
+ // The slice and its flush ask this action's question (A18 provenance):
17
+ // the guesses it writes and the flights it starts are stamped with it.
18
+ const i = question;
19
+ setQuestion(n);
20
+ joinFuture(t);
21
+ const o = e();
22
+ if (actionDepth === 0) flush();
23
+ setQuestion(i);
24
+ return o;
12
25
  }
13
26
 
14
27
  /**
@@ -29,26 +42,40 @@ function restoreTransition(e, r) {
29
42
  * submission tracking layered on top. The shared name is deliberate.
30
43
  *
31
44
  * Wraps a generator function so each invocation runs as a single transaction
32
- * (a "transition") that batches every signal/store write between yields. The
33
- * surrounding UI sees one atomic update per yielded step; nothing is committed
34
- * until the action either completes or the next `yield` resolves.
45
+ * that holds every signal/store write between yields. The surrounding UI sees
46
+ * one atomic update when the action completes; nothing is committed until
47
+ * every action in the transaction has returned.
35
48
  *
36
49
  * `yield` is the transaction-safe suspension point: the action waits for a
37
50
  * yielded promise and re-enters the transaction before running the code after
38
51
  * it. A plain `await` does NOT — the runtime has no hook into an async
39
- * generator's internal await continuations, so writes to fresh signals
40
- * between an `await` and the next `yield` escape the transaction and commit
41
- * immediately. `await` is still the ergonomic choice for typed results; just
42
- * put a bare `yield` before any writes that follow it:
52
+ * generator's internal await continuations, so code between an `await` and
53
+ * the next `yield` runs OUTSIDE the transaction: writes to fresh signals
54
+ * commit immediately, and anything that creates a reader there — `until()`,
55
+ * `latest()`, a memo or effect, a mount — is created mainline, where a read of
56
+ * this action's held state makes it born held (A29): staged with the
57
+ * transaction and replayed at its commit. `await` is still the ergonomic
58
+ * choice for typed results; just put a bare `yield` before any write or
59
+ * reader creation that follows it — including the expression of the next
60
+ * `yield`, which is evaluated before the step re-enters:
43
61
  *
44
62
  * ```ts
45
63
  * const saved = await api.createTodo(text); // typed result
46
- * yield; // re-enter the transaction before writing
64
+ * yield; // re-enter the transaction before writing or reading
47
65
  * setTodos(t => { ... });
66
+ * yield until(() => todos.some(t => t.id === saved.id));
48
67
  * ```
49
68
  *
69
+ * The same holds inside an async helper the action yields
70
+ * (`yield (async () => { ... })()`): everything after its first `await` runs
71
+ * outside the transaction. An `await refresh(x)` or `await until(...)` there
72
+ * waits for this action's commit, which waits on the helper, so it hangs
73
+ * whenever `x` re-ran during the action (#4263) and works otherwise. Call
74
+ * `refresh(x)` in the generator once the helper returns; `yield` it only when
75
+ * the action needs the fresh value.
76
+ *
50
77
  * (For the same reason, don't call `flush()` inside an action body — it
51
- * drains the transaction mid-step.)
78
+ * cannot reveal the held writes and is refused.)
52
79
  *
53
80
  * Each call returns a `Promise` that resolves with the generator's return
54
81
  * value, or rejects if it throws. Pair with `createOptimistic` /
@@ -73,66 +100,72 @@ function restoreTransition(e, r) {
73
100
  *
74
101
  * await addTodo("buy milk");
75
102
  * ```
76
- */ function action(e) {
77
- return (...r) => new Promise((t, n) => {
78
- const i = e(...r);
79
- globalQueue.initTransition();
80
- let o = activeTransition;
81
- o.oe.push(i);
82
- const done = (e, r, u = false) => {
83
- o = currentTransition(o);
84
- const s = o.oe.indexOf(i);
85
- if (s >= 0) o.oe.splice(s, 1);
86
- // Re-adopt through initTransition like every other resumption site:
87
- // a bare setActiveTransition leaves globalQueue._batch as a detached
88
- // ambient batch, and anything registered before the scheduled flush
89
- // (held writes on a merging transition, optimistic overrides,
90
- // affects() marks) lands there with nothing to ever finalize it.
91
- globalQueue.initTransition(o);
103
+ */ function action(t) {
104
+ return (...n) => new Promise((e, i) => {
105
+ const o = t(...n);
106
+ // The action's transaction, held open until the body returns. The
107
+ // first slice's writes are carried by the tick's scheduled flush.
108
+ const r = newTransaction(false);
109
+ r.tt = 1;
110
+ r.nt = true;
111
+ const s = nextQuestion();
112
+ const done = (t, n, o = false) => {
113
+ resolveTx(r).tt--;
92
114
  schedule();
93
- u ? n(r) : t(e);
115
+ o ? i(n) : e(t);
94
116
  };
95
- const step = (e, r) => {
96
- let t;
117
+ const step = (t, n) => {
118
+ let e;
119
+ // The body is on the stack between these brackets: flush() is
120
+ // refused inside (FLUSH_IN_ACTION, scheduler.ts).
121
+ enterAction();
97
122
  try {
98
- t = r ? i.throw(e) : i.next(e);
99
- } catch (e) {
100
- return done(undefined, e, true);
123
+ e = n ? o.throw(t) : o.next(t);
124
+ } catch (t) {
125
+ exitAction();
126
+ return done(undefined, t, true);
101
127
  }
128
+ exitAction();
102
129
  // A rejected iterator result (async generators) means the error already
103
130
  // escaped the generator body — it is completed, and throwing back in
104
131
  // would just reject again forever. Settle instead.
105
- if (isThenable(t)) return void t.then(run, e => done(undefined, e, true));
106
- run(t);
132
+ if (isThenable(e)) return void e.then(run, t => done(undefined, t, true));
133
+ run(e);
107
134
  };
108
- const run = e => {
109
- if (e.done) return done(e.value);
135
+ const run = t => {
136
+ if (t.done) return done(t.value);
110
137
  // Thenable assimilation can itself throw synchronously (a `then`
111
138
  // getter, or a `then()` method that throws — #2918). Match `await`
112
139
  // semantics: the failure is thrown back into the generator at the
113
140
  // yield point (catchable there); if uncaught, step()'s guard settles
114
- // the action so its iterator never leaks in the transition. The
115
- // settled flag implements A+ 2.3.3.3.4.1: a throw after the thenable
116
- // already called a callback is ignored.
117
- let r = false;
141
+ // the action. The settled flag implements A+ 2.3.3.3.4.1: a throw
142
+ // after the thenable already called a callback is ignored.
143
+ let n = false;
118
144
  try {
119
- if (isThenable(e.value)) return void e.value.then(e => {
120
- if (r) return;
121
- r = true;
122
- restoreTransition(o, () => step(e));
123
- }, e => {
124
- if (r) return;
125
- r = true;
126
- restoreTransition(o, () => step(e, true));
145
+ if (isThenable(t.value)) return void t.value.then(t => {
146
+ if (n) return;
147
+ n = true;
148
+ inTransaction(r, s, () => step(t));
149
+ }, t => {
150
+ if (n) return;
151
+ n = true;
152
+ inTransaction(r, s, () => step(t, true));
127
153
  });
128
- } catch (e) {
129
- if (r) return;
130
- r = true;
131
- return void restoreTransition(o, () => step(e, true));
154
+ } catch (t) {
155
+ if (n) return;
156
+ n = true;
157
+ return void inTransaction(r, s, () => step(t, true));
132
158
  }
133
- restoreTransition(o, () => step(e.value));
159
+ inTransaction(r, s, () => step(t.value));
134
160
  };
161
+ // The first slice's writes are carried by the tick's scheduled flush;
162
+ // the slice itself asks the action's question (its guesses are stamped
163
+ // at the write).
164
+ joinFuture(r);
165
+ const u = question;
166
+ setQuestion(s);
135
167
  step();
168
+ setQuestion(u);
136
169
  });
137
170
  }
138
171