@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,28 +1,30 @@
1
- import { setOrigin, globalQueue, activeTransition, currentTransition, schedule, actionStepDepth, flush, enterActionStep, exitActionStep } from "./scheduler.js";
2
-
3
1
  import { isThenable } from "./async.js";
4
2
 
5
3
  import "./core.js";
6
4
 
7
5
  import "./dev.js";
8
6
 
9
- import { attrHooks } from "./attribution-hooks.js";
7
+ import { joinFuture, newTransaction, enterAction, exitAction, resolveTx, schedule, actionDepth, flush, nextQuestion, setQuestion, question } from "./scheduler.js";
10
8
 
11
- /** Invocation order across all actions — the provenance every slice of an
12
- * action runs under (scheduler `origin`): the flights and overrides its
13
- * ambient windows issue are stamped with it, so a later action's override
14
- * can tell this action's late answer from its own (#3331). */ let actionSeq = 0;
9
+ import { attrHooks } from "./attribution-hooks.js";
15
10
 
16
- function restoreTransition(t, e, r) {
17
- const n = setOrigin(t);
18
- globalQueue.initTransition(e);
19
- const i = r();
20
- // A nested action resuming synchronously (its body yielded a non-thenable)
21
- // runs this inside the OUTER action's slice: draining here would park the
22
- // shared transaction and detach the outer body's remaining writes (the
23
- // flush() rule, scheduler.ts). The outer step's own return drains.
24
- if (actionStepDepth === 0) flush();
25
- setOrigin(n);
11
+ /** A slice of the body runs in the action's transaction: the flush that
12
+ * carries its writes parks into it (`joinFuture` — merging whatever the tick
13
+ * already joined: O1, an action that opens in a tick owns it; a second
14
+ * action in the tick, or one called from the body, merges into the first).
15
+ * A resumed slice drains at once: the seam parks what it wrote (the action
16
+ * holds the transaction open) or, the body having returned, lands it. A
17
+ * nested action resuming synchronously inside the outer body does not drain
18
+ * — that would park the outer's remaining writes' frame mid-slice; the outer
19
+ * step's own return does. */ function inTransaction(t, n, e) {
20
+ // The slice and its flush ask this action's question (A18 provenance):
21
+ // the guesses it writes and the flights it starts are stamped with it.
22
+ const o = question;
23
+ setQuestion(n);
24
+ joinFuture(t);
25
+ const i = e();
26
+ if (actionDepth === 0) flush();
27
+ setQuestion(o);
26
28
  return i;
27
29
  }
28
30
 
@@ -44,9 +46,9 @@ function restoreTransition(t, e, r) {
44
46
  * submission tracking layered on top. The shared name is deliberate.
45
47
  *
46
48
  * Wraps a generator function so each invocation runs as a single transaction
47
- * (a "transition") that batches every signal/store write between yields. The
48
- * surrounding UI sees one atomic update per yielded step; nothing is committed
49
- * until the action either completes or the next `yield` resolves.
49
+ * that holds every signal/store write between yields. The surrounding UI sees
50
+ * one atomic update when the action completes; nothing is committed until
51
+ * every action in the transaction has returned.
50
52
  *
51
53
  * `yield` is the transaction-safe suspension point: the action waits for a
52
54
  * yielded promise and re-enters the transaction before running the code after
@@ -56,8 +58,7 @@ function restoreTransition(t, e, r) {
56
58
  * commit immediately, and anything that creates a reader there — `until()`,
57
59
  * `latest()`, a memo or effect, a mount — is created mainline, where a read of
58
60
  * this action's held state makes it born held (A29): staged with the
59
- * transaction and replayed at its commit. For `until()` that commit is the
60
- * settle its own promise holds open (#3482). `await` is still the ergonomic
61
+ * transaction and replayed at its commit. `await` is still the ergonomic
61
62
  * choice for typed results; just put a bare `yield` before any write or
62
63
  * reader creation that follows it — including the expression of the next
63
64
  * `yield`, which is evaluated before the step re-enters:
@@ -70,7 +71,7 @@ function restoreTransition(t, e, r) {
70
71
  * ```
71
72
  *
72
73
  * (For the same reason, don't call `flush()` inside an action body — it
73
- * drains the transaction mid-step.)
74
+ * cannot reveal the held writes and is refused.)
74
75
  *
75
76
  * Each call returns a `Promise` that resolves with the generator's return
76
77
  * value, or rejects if it throws. Pair with `createOptimistic` /
@@ -96,52 +97,42 @@ function restoreTransition(t, e, r) {
96
97
  * await addTodo("buy milk");
97
98
  * ```
98
99
  */ function action(t) {
99
- return (...e) => new Promise((r, n) => {
100
- const i = t(...e);
101
- const o = ++actionSeq;
102
- // The first slice's window runs to the scheduled flush, which clears
103
- // the provenance with the window — no restore here.
104
- setOrigin(o);
105
- globalQueue.initTransition();
106
- let s = activeTransition;
107
- s.tt.push(i);
108
- s.et = true;
109
- const done = (t, e, o = false) => {
110
- s = currentTransition(s);
111
- const u = s.tt.indexOf(i);
112
- if (u >= 0) s.tt.splice(u, 1);
113
- // Re-adopt through initTransition like every other resumption site:
114
- // a bare setActiveTransition leaves globalQueue._batch as a detached
115
- // ambient batch, and anything registered before the scheduled flush
116
- // (held writes on a merging transition, optimistic overrides,
117
- // affects() marks) lands there with nothing to ever finalize it.
118
- globalQueue.initTransition(s);
100
+ return (...n) => new Promise((e, o) => {
101
+ const i = t(...n);
102
+ // The action's transaction, held open until the body returns. The
103
+ // first slice's writes are carried by the tick's scheduled flush.
104
+ const r = newTransaction(false);
105
+ r.tt = 1;
106
+ r.nt = true;
107
+ const s = nextQuestion();
108
+ const done = (t, n, i = false) => {
109
+ resolveTx(r).tt--;
119
110
  schedule();
120
- o ? n(e) : r(t);
111
+ i ? o(n) : e(t);
121
112
  };
122
- const step = (e, r) => {
123
- let n;
113
+ const step = (n, e) => {
114
+ let o;
124
115
  // Attribution hooks bracket the synchronous slice of generator body
125
116
  // this step runs (up to the next yield): writes inside are the
126
117
  // action's. Both sites sit outside the try (attribution-hooks.ts).
127
118
  if (attrHooks !== null) attrHooks.actionStepStart(i, t.name || undefined);
128
119
  // The body is on the stack between these brackets: flush() is
129
120
  // refused inside (FLUSH_IN_ACTION, scheduler.ts).
130
- enterActionStep();
121
+ enterAction();
131
122
  try {
132
- n = r ? i.throw(e) : i.next(e);
123
+ o = e ? i.throw(n) : i.next(n);
133
124
  } catch (t) {
134
- exitActionStep();
125
+ exitAction();
135
126
  if (attrHooks !== null) attrHooks.actionStepEnd(i);
136
127
  return done(undefined, t, true);
137
128
  }
138
- exitActionStep();
129
+ exitAction();
139
130
  if (attrHooks !== null) attrHooks.actionStepEnd(i);
140
131
  // A rejected iterator result (async generators) means the error already
141
132
  // escaped the generator body — it is completed, and throwing back in
142
133
  // would just reject again forever. Settle instead.
143
- if (isThenable(n)) return void n.then(run, t => done(undefined, t, true));
144
- run(n);
134
+ if (isThenable(o)) return void o.then(run, t => done(undefined, t, true));
135
+ run(o);
145
136
  };
146
137
  const run = t => {
147
138
  if (t.done) return done(t.value);
@@ -149,28 +140,34 @@ function restoreTransition(t, e, r) {
149
140
  // getter, or a `then()` method that throws — #2918). Match `await`
150
141
  // semantics: the failure is thrown back into the generator at the
151
142
  // yield point (catchable there); if uncaught, step()'s guard settles
152
- // the action so its iterator never leaks in the transition. The
153
- // settled flag implements A+ 2.3.3.3.4.1: a throw after the thenable
154
- // already called a callback is ignored.
155
- let e = false;
143
+ // the action. The settled flag implements A+ 2.3.3.3.4.1: a throw
144
+ // after the thenable already called a callback is ignored.
145
+ let n = false;
156
146
  try {
157
147
  if (isThenable(t.value)) return void t.value.then(t => {
158
- if (e) return;
159
- e = true;
160
- restoreTransition(o, s, () => step(t));
148
+ if (n) return;
149
+ n = true;
150
+ inTransaction(r, s, () => step(t));
161
151
  }, t => {
162
- if (e) return;
163
- e = true;
164
- restoreTransition(o, s, () => step(t, true));
152
+ if (n) return;
153
+ n = true;
154
+ inTransaction(r, s, () => step(t, true));
165
155
  });
166
156
  } catch (t) {
167
- if (e) return;
168
- e = true;
169
- return void restoreTransition(o, s, () => step(t, true));
157
+ if (n) return;
158
+ n = true;
159
+ return void inTransaction(r, s, () => step(t, true));
170
160
  }
171
- restoreTransition(o, s, () => step(t.value));
161
+ inTransaction(r, s, () => step(t.value));
172
162
  };
163
+ // The first slice's writes are carried by the tick's scheduled flush;
164
+ // the slice itself asks the action's question (its guesses are stamped
165
+ // at the write).
166
+ joinFuture(r);
167
+ const u = question;
168
+ setQuestion(s);
173
169
  step();
170
+ setQuestion(u);
174
171
  });
175
172
  }
176
173