@solidjs/signals 2.0.0-rc.1 → 2.0.0-rc.10

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 (150) hide show
  1. package/dist/dev-shared.js +7138 -0
  2. package/dist/dev.attribution.js +3307 -0
  3. package/dist/dev.js +5691 -4491
  4. package/dist/observe/affects.js +129 -0
  5. package/dist/observe/attribution.js +7 -0
  6. package/dist/observe/boundaries.js +793 -0
  7. package/dist/observe/core/action.js +177 -0
  8. package/dist/observe/core/async.js +849 -0
  9. package/dist/observe/core/attribution-costs.js +66 -0
  10. package/dist/observe/core/attribution-feedback.js +280 -0
  11. package/dist/observe/core/attribution-hooks.js +83 -0
  12. package/dist/observe/core/attribution-queries.js +43 -0
  13. package/dist/observe/core/attribution.js +2904 -0
  14. package/dist/observe/core/constants.js +283 -0
  15. package/dist/{types-cjs/core/context.d.cts → observe/core/context.js} +37 -12
  16. package/dist/observe/core/core.js +1999 -0
  17. package/dist/observe/core/dev.js +343 -0
  18. package/dist/observe/core/effect.js +200 -0
  19. package/dist/observe/core/error-hooks.js +71 -0
  20. package/dist/observe/core/error.js +80 -0
  21. package/dist/observe/core/external.js +98 -0
  22. package/dist/observe/core/graph.js +155 -0
  23. package/dist/observe/core/heap.js +147 -0
  24. package/dist/observe/core/invariants.js +45 -0
  25. package/dist/observe/core/lanes.js +205 -0
  26. package/dist/observe/core/optimistic.js +627 -0
  27. package/dist/observe/core/owner.js +353 -0
  28. package/dist/observe/core/scheduler.js +1547 -0
  29. package/dist/observe/core/verdict.js +674 -0
  30. package/dist/observe/index.js +59 -0
  31. package/dist/observe/map.js +484 -0
  32. package/dist/observe/signals.js +731 -0
  33. package/dist/observe/store/index.js +44 -0
  34. package/dist/observe/store/next/optimistic.js +717 -0
  35. package/dist/observe/store/next/projection.js +266 -0
  36. package/dist/observe/store/next/reconcile.js +375 -0
  37. package/dist/observe/store/next/store.js +2480 -0
  38. package/dist/observe/store/next/target.js +51 -0
  39. package/dist/observe/store/store.js +331 -0
  40. package/dist/observe/store/storePath.js +103 -0
  41. package/dist/observe/store/utils.js +1070 -0
  42. package/dist/prod/affects.js +10 -9
  43. package/dist/prod/attribution.js +45 -0
  44. package/dist/prod/boundaries.js +388 -178
  45. package/dist/prod/core/action.js +65 -37
  46. package/dist/prod/core/async.js +378 -163
  47. package/dist/prod/core/attribution-hooks.js +3 -0
  48. package/dist/prod/core/constants.js +186 -1
  49. package/dist/prod/core/context.js +10 -16
  50. package/dist/prod/core/core.js +1546 -416
  51. package/dist/prod/core/dev.js +18 -1
  52. package/dist/prod/core/effect.js +119 -79
  53. package/dist/prod/core/error-hooks.js +71 -0
  54. package/dist/prod/core/error.js +13 -1
  55. package/dist/prod/core/external.js +4 -4
  56. package/dist/prod/core/graph.js +105 -54
  57. package/dist/prod/core/heap.js +72 -65
  58. package/dist/prod/core/invariants.js +3 -2
  59. package/dist/prod/core/lanes.js +117 -52
  60. package/dist/prod/core/optimistic.js +458 -104
  61. package/dist/prod/core/owner.js +131 -84
  62. package/dist/prod/core/scheduler.js +998 -241
  63. package/dist/prod/core/verdict.js +417 -112
  64. package/dist/prod/index.js +20 -8
  65. package/dist/prod/map.js +312 -151
  66. package/dist/prod/signals.js +363 -32
  67. package/dist/prod/store/index.js +2 -0
  68. package/dist/prod/store/next/optimistic.js +530 -197
  69. package/dist/prod/store/next/projection.js +142 -57
  70. package/dist/prod/store/next/reconcile.js +149 -103
  71. package/dist/prod/store/next/store.js +1470 -346
  72. package/dist/prod/store/next/target.js +40 -9
  73. package/dist/prod/store/store.js +23 -19
  74. package/dist/prod/store/utils.js +997 -130
  75. package/dist/types/attribution.d.ts +19 -0
  76. package/dist/types/attribution.prod.d.ts +22 -0
  77. package/dist/types/boundaries.d.ts +78 -5
  78. package/dist/types/core/action.d.ts +12 -5
  79. package/dist/types/core/async.d.ts +3 -1
  80. package/dist/types/core/attribution-costs.d.ts +35 -0
  81. package/dist/types/core/attribution-feedback.d.ts +133 -0
  82. package/dist/types/core/attribution-hooks.d.ts +304 -0
  83. package/dist/types/core/attribution-queries.d.ts +24 -0
  84. package/dist/types/core/attribution.d.ts +892 -0
  85. package/dist/types/core/constants.d.ts +179 -0
  86. package/dist/types/core/core.d.ts +299 -25
  87. package/dist/types/core/dev.d.ts +421 -8
  88. package/dist/types/core/effect.d.ts +8 -1
  89. package/dist/types/core/error-hooks.d.ts +71 -0
  90. package/dist/types/core/error.d.ts +9 -0
  91. package/dist/types/core/graph.d.ts +23 -0
  92. package/dist/types/core/heap.d.ts +5 -3
  93. package/dist/types/core/index.d.ts +6 -3
  94. package/dist/types/core/invariants.d.ts +5 -1
  95. package/dist/types/core/lanes.d.ts +51 -19
  96. package/dist/types/core/owner.d.ts +15 -3
  97. package/dist/types/core/scheduler.d.ts +248 -1
  98. package/dist/types/core/types.d.ts +124 -41
  99. package/dist/types/index.d.ts +18 -5
  100. package/dist/types/map.d.ts +2 -0
  101. package/dist/types/signals.d.ts +145 -13
  102. package/dist/types/store/index.d.ts +7 -6
  103. package/dist/types/store/next/optimistic.d.ts +18 -13
  104. package/dist/types/store/next/projection.d.ts +5 -2
  105. package/dist/types/store/next/reconcile.d.ts +7 -0
  106. package/dist/types/store/next/store.d.ts +83 -11
  107. package/dist/types/store/next/target.d.ts +108 -11
  108. package/dist/types/store/store.d.ts +20 -11
  109. package/dist/types/store/utils.d.ts +188 -0
  110. package/package.json +31 -26
  111. package/dist/node.cjs +0 -8137
  112. package/dist/types/store/optimistic.d.ts +0 -45
  113. package/dist/types/store/projection.d.ts +0 -70
  114. package/dist/types/store/reconcile.d.ts +0 -46
  115. package/dist/types-cjs/affects.d.cts +0 -47
  116. package/dist/types-cjs/boundaries.d.cts +0 -175
  117. package/dist/types-cjs/core/action.d.cts +0 -64
  118. package/dist/types-cjs/core/async.d.cts +0 -21
  119. package/dist/types-cjs/core/constants.d.cts +0 -71
  120. package/dist/types-cjs/core/core.d.cts +0 -156
  121. package/dist/types-cjs/core/dev.d.cts +0 -64
  122. package/dist/types-cjs/core/effect.d.cts +0 -30
  123. package/dist/types-cjs/core/error.d.cts +0 -47
  124. package/dist/types-cjs/core/external.d.cts +0 -15
  125. package/dist/types-cjs/core/graph.d.cts +0 -5
  126. package/dist/types-cjs/core/heap.d.cts +0 -22
  127. package/dist/types-cjs/core/index.d.cts +0 -13
  128. package/dist/types-cjs/core/invariants.d.cts +0 -59
  129. package/dist/types-cjs/core/lanes.d.cts +0 -56
  130. package/dist/types-cjs/core/optimistic.d.cts +0 -6
  131. package/dist/types-cjs/core/owner.d.cts +0 -124
  132. package/dist/types-cjs/core/scheduler.d.cts +0 -172
  133. package/dist/types-cjs/core/types.d.cts +0 -148
  134. package/dist/types-cjs/core/verdict.d.cts +0 -2
  135. package/dist/types-cjs/index.d.cts +0 -10
  136. package/dist/types-cjs/map.d.cts +0 -69
  137. package/dist/types-cjs/package.json +0 -3
  138. package/dist/types-cjs/signals.d.cts +0 -624
  139. package/dist/types-cjs/store/index.d.cts +0 -19
  140. package/dist/types-cjs/store/next/optimistic.d.cts +0 -20
  141. package/dist/types-cjs/store/next/projection.d.cts +0 -24
  142. package/dist/types-cjs/store/next/reconcile.d.cts +0 -3
  143. package/dist/types-cjs/store/next/store.d.cts +0 -71
  144. package/dist/types-cjs/store/next/target.d.cts +0 -99
  145. package/dist/types-cjs/store/optimistic.d.cts +0 -45
  146. package/dist/types-cjs/store/projection.d.cts +0 -70
  147. package/dist/types-cjs/store/reconcile.d.cts +0 -46
  148. package/dist/types-cjs/store/store.d.cts +0 -138
  149. package/dist/types-cjs/store/storePath.d.cts +0 -58
  150. package/dist/types-cjs/store/utils.d.cts +0 -74
@@ -1,14 +1,25 @@
1
- import { globalQueue, activeTransition, currentTransition, schedule, flush } from "./scheduler.js";
1
+ import { setOrigin, globalQueue, activeTransition, currentTransition, schedule, actionStepDepth, flush, enterActionStep, exitActionStep } from "./scheduler.js";
2
2
 
3
3
  import { isThenable } from "./async.js";
4
4
 
5
5
  import "./core.js";
6
6
 
7
- function restoreTransition(e, r) {
8
- globalQueue.initTransition(e);
9
- const t = r();
10
- flush();
11
- return t;
7
+ /** Invocation order across all actions — the provenance every slice of an
8
+ * action runs under (scheduler `origin`): the flights and overrides its
9
+ * ambient windows issue are stamped with it, so a later action's override
10
+ * can tell this action's late answer from its own (#3331). */ let actionSeq = 0;
11
+
12
+ function restoreTransition(e, t, n) {
13
+ const r = setOrigin(e);
14
+ globalQueue.initTransition(t);
15
+ const i = n();
16
+ // A nested action resuming synchronously (its body yielded a non-thenable)
17
+ // runs this inside the OUTER action's slice: draining here would park the
18
+ // shared transaction and detach the outer body's remaining writes (the
19
+ // flush() rule, scheduler.ts). The outer step's own return drains.
20
+ if (actionStepDepth === 0) flush();
21
+ setOrigin(r);
22
+ return i;
12
23
  }
13
24
 
14
25
  /**
@@ -36,15 +47,22 @@ function restoreTransition(e, r) {
36
47
  * `yield` is the transaction-safe suspension point: the action waits for a
37
48
  * yielded promise and re-enters the transaction before running the code after
38
49
  * 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:
50
+ * generator's internal await continuations, so code between an `await` and
51
+ * the next `yield` runs OUTSIDE the transaction: writes to fresh signals
52
+ * commit immediately, and anything that creates a reader there — `until()`,
53
+ * `latest()`, a memo or effect, a mount — is created mainline, where a read of
54
+ * this action's held state makes it born held (A29): staged with the
55
+ * transaction and replayed at its commit. For `until()` that commit is the
56
+ * settle its own promise holds open (#3482). `await` is still the ergonomic
57
+ * choice for typed results; just put a bare `yield` before any write or
58
+ * reader creation that follows it — including the expression of the next
59
+ * `yield`, which is evaluated before the step re-enters:
43
60
  *
44
61
  * ```ts
45
62
  * const saved = await api.createTodo(text); // typed result
46
- * yield; // re-enter the transaction before writing
63
+ * yield; // re-enter the transaction before writing or reading
47
64
  * setTodos(t => { ... });
65
+ * yield until(() => todos.some(t => t.id === saved.id));
48
66
  * ```
49
67
  *
50
68
  * (For the same reason, don't call `flush()` inside an action body — it
@@ -74,36 +92,46 @@ function restoreTransition(e, r) {
74
92
  * await addTodo("buy milk");
75
93
  * ```
76
94
  */ function action(e) {
77
- return (...r) => new Promise((t, n) => {
78
- const i = e(...r);
95
+ return (...t) => new Promise((n, r) => {
96
+ const i = e(...t);
97
+ const o = ++actionSeq;
98
+ // The first slice's window runs to the scheduled flush, which clears
99
+ // the provenance with the window — no restore here.
100
+ setOrigin(o);
79
101
  globalQueue.initTransition();
80
- let o = activeTransition;
81
- o.ie.push(i);
82
- const done = (e, r, u = false) => {
83
- o = currentTransition(o);
84
- const s = o.ie.indexOf(i);
85
- if (s >= 0) o.ie.splice(s, 1);
102
+ let s = activeTransition;
103
+ s.pe.push(i);
104
+ s.Te = true;
105
+ const done = (e, t, o = false) => {
106
+ s = currentTransition(s);
107
+ const u = s.pe.indexOf(i);
108
+ if (u >= 0) s.pe.splice(u, 1);
86
109
  // Re-adopt through initTransition like every other resumption site:
87
110
  // a bare setActiveTransition leaves globalQueue._batch as a detached
88
111
  // ambient batch, and anything registered before the scheduled flush
89
112
  // (held writes on a merging transition, optimistic overrides,
90
113
  // affects() marks) lands there with nothing to ever finalize it.
91
- globalQueue.initTransition(o);
114
+ globalQueue.initTransition(s);
92
115
  schedule();
93
- u ? n(r) : t(e);
116
+ o ? r(t) : n(e);
94
117
  };
95
- const step = (e, r) => {
96
- let t;
118
+ const step = (e, t) => {
119
+ let n;
120
+ // The body is on the stack between these brackets: flush() is
121
+ // refused inside (FLUSH_IN_ACTION, scheduler.ts).
122
+ enterActionStep();
97
123
  try {
98
- t = r ? i.throw(e) : i.next(e);
124
+ n = t ? i.throw(e) : i.next(e);
99
125
  } catch (e) {
126
+ exitActionStep();
100
127
  return done(undefined, e, true);
101
128
  }
129
+ exitActionStep();
102
130
  // A rejected iterator result (async generators) means the error already
103
131
  // escaped the generator body — it is completed, and throwing back in
104
132
  // would just reject again forever. Settle instead.
105
- if (isThenable(t)) return void t.then(run, e => done(undefined, e, true));
106
- run(t);
133
+ if (isThenable(n)) return void n.then(run, e => done(undefined, e, true));
134
+ run(n);
107
135
  };
108
136
  const run = e => {
109
137
  if (e.done) return done(e.value);
@@ -114,23 +142,23 @@ function restoreTransition(e, r) {
114
142
  // the action so its iterator never leaks in the transition. The
115
143
  // settled flag implements A+ 2.3.3.3.4.1: a throw after the thenable
116
144
  // already called a callback is ignored.
117
- let r = false;
145
+ let t = false;
118
146
  try {
119
147
  if (isThenable(e.value)) return void e.value.then(e => {
120
- if (r) return;
121
- r = true;
122
- restoreTransition(o, () => step(e));
148
+ if (t) return;
149
+ t = true;
150
+ restoreTransition(o, s, () => step(e));
123
151
  }, e => {
124
- if (r) return;
125
- r = true;
126
- restoreTransition(o, () => step(e, true));
152
+ if (t) return;
153
+ t = true;
154
+ restoreTransition(o, s, () => step(e, true));
127
155
  });
128
156
  } catch (e) {
129
- if (r) return;
130
- r = true;
131
- return void restoreTransition(o, () => step(e, true));
157
+ if (t) return;
158
+ t = true;
159
+ return void restoreTransition(o, s, () => step(e, true));
132
160
  }
133
- restoreTransition(o, () => step(e.value));
161
+ restoreTransition(o, s, () => step(e.value));
134
162
  };
135
163
  step();
136
164
  });