@solidjs/signals 2.0.0-rc.11 → 2.0.0-rc.14

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 (118) hide show
  1. package/dist/dev-shared.js +2056 -3773
  2. package/dist/dev.attribution.js +159 -91
  3. package/dist/dev.js +7263 -8384
  4. package/dist/observe/affects.js +125 -104
  5. package/dist/observe/boundaries.js +458 -665
  6. package/dist/observe/core/action.js +63 -66
  7. package/dist/observe/core/async.js +240 -383
  8. package/dist/observe/core/attribution-queries.js +1 -1
  9. package/dist/observe/core/attribution.js +271 -199
  10. package/dist/observe/core/constants.js +115 -178
  11. package/dist/observe/core/context.js +3 -3
  12. package/dist/observe/core/core.js +840 -1428
  13. package/dist/observe/core/dev.js +41 -18
  14. package/dist/observe/core/effect.js +75 -86
  15. package/dist/observe/core/external.js +5 -5
  16. package/dist/observe/core/graph.js +61 -70
  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 +704 -181
  20. package/dist/observe/core/owner.js +80 -101
  21. package/dist/observe/core/scheduler.js +708 -1351
  22. package/dist/observe/core/verdict.js +302 -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 +133 -215
  28. package/dist/observe/store/affects.js +135 -0
  29. package/dist/observe/store/index.js +29 -24
  30. package/dist/observe/store/optimistic.js +538 -0
  31. package/dist/observe/store/projection.js +302 -0
  32. package/dist/observe/store/reconcile.js +257 -0
  33. package/dist/observe/store/store.js +1945 -277
  34. package/dist/observe/store/storePath.js +1 -1
  35. package/dist/{prod/store/next → observe/store}/target.js +17 -18
  36. package/dist/observe/store/types.js +73 -0
  37. package/dist/observe/store/utils.js +1 -13
  38. package/dist/prod/affects.js +127 -106
  39. package/dist/prod/boundaries.js +442 -654
  40. package/dist/prod/core/action.js +71 -74
  41. package/dist/prod/core/async.js +307 -442
  42. package/dist/prod/core/constants.js +112 -177
  43. package/dist/prod/core/context.js +3 -3
  44. package/dist/prod/core/core.js +852 -1448
  45. package/dist/prod/core/effect.js +88 -99
  46. package/dist/prod/core/external.js +5 -5
  47. package/dist/prod/core/graph.js +61 -70
  48. package/dist/prod/core/heap.js +75 -98
  49. package/dist/prod/core/invariants.js +1 -32
  50. package/dist/prod/core/lanes.js +666 -181
  51. package/dist/prod/core/owner.js +75 -96
  52. package/dist/prod/core/scheduler.js +677 -1332
  53. package/dist/prod/core/verdict.js +297 -621
  54. package/dist/prod/flatten.js +77 -0
  55. package/dist/prod/index.js +15 -13
  56. package/dist/prod/map.js +143 -146
  57. package/dist/prod/reveal.js +212 -0
  58. package/dist/prod/signals.js +144 -226
  59. package/dist/prod/store/affects.js +135 -0
  60. package/dist/prod/store/index.js +28 -19
  61. package/dist/prod/store/optimistic.js +533 -0
  62. package/dist/prod/store/projection.js +295 -0
  63. package/dist/prod/store/reconcile.js +257 -0
  64. package/dist/prod/store/store.js +1840 -272
  65. package/dist/prod/store/storePath.js +1 -1
  66. package/dist/{observe/store/next → prod/store}/target.js +13 -17
  67. package/dist/prod/store/types.js +73 -0
  68. package/dist/prod/store/utils.js +1 -11
  69. package/dist/types/affects.d.ts +11 -30
  70. package/dist/types/boundaries.d.ts +62 -176
  71. package/dist/types/carved.d.ts +1 -0
  72. package/dist/types/core/action.d.ts +5 -6
  73. package/dist/types/core/async.d.ts +10 -5
  74. package/dist/types/core/attribution-hooks.d.ts +48 -1
  75. package/dist/types/core/attribution.d.ts +29 -9
  76. package/dist/types/core/constants.d.ts +125 -171
  77. package/dist/types/core/core.d.ts +104 -264
  78. package/dist/types/core/dev.d.ts +60 -7
  79. package/dist/types/core/effect.d.ts +0 -7
  80. package/dist/types/core/graph.d.ts +7 -1
  81. package/dist/types/core/heap.d.ts +5 -7
  82. package/dist/types/core/index.d.ts +6 -6
  83. package/dist/types/core/invariants.d.ts +0 -29
  84. package/dist/types/core/lanes.d.ts +65 -87
  85. package/dist/types/core/owner.d.ts +3 -3
  86. package/dist/types/core/scheduler.d.ts +249 -331
  87. package/dist/types/core/types.d.ts +51 -85
  88. package/dist/types/core/verdict.d.ts +3 -0
  89. package/dist/types/flatten.d.ts +8 -0
  90. package/dist/types/index.d.ts +7 -5
  91. package/dist/types/reveal.d.ts +19 -0
  92. package/dist/types/signals.d.ts +53 -92
  93. package/dist/types/store/affects.d.ts +1 -0
  94. package/dist/types/store/index.d.ts +35 -15
  95. package/dist/types/store/optimistic.d.ts +23 -0
  96. package/dist/types/store/projection.d.ts +18 -0
  97. package/dist/types/store/reconcile.d.ts +3 -0
  98. package/dist/types/store/store.d.ts +165 -143
  99. package/dist/types/store/storePath.d.ts +1 -1
  100. package/dist/types/store/target.d.ts +151 -0
  101. package/dist/types/store/types.d.ts +84 -0
  102. package/package.json +1 -1
  103. package/dist/observe/core/optimistic.js +0 -669
  104. package/dist/observe/store/next/optimistic.js +0 -717
  105. package/dist/observe/store/next/projection.js +0 -266
  106. package/dist/observe/store/next/reconcile.js +0 -375
  107. package/dist/observe/store/next/store.js +0 -2480
  108. package/dist/prod/core/optimistic.js +0 -658
  109. package/dist/prod/store/next/optimistic.js +0 -710
  110. package/dist/prod/store/next/projection.js +0 -257
  111. package/dist/prod/store/next/reconcile.js +0 -373
  112. package/dist/prod/store/next/store.js +0 -2356
  113. package/dist/types/core/optimistic.d.ts +0 -6
  114. package/dist/types/store/next/optimistic.d.ts +0 -25
  115. package/dist/types/store/next/projection.d.ts +0 -27
  116. package/dist/types/store/next/reconcile.d.ts +0 -10
  117. package/dist/types/store/next/store.d.ts +0 -143
  118. package/dist/types/store/next/target.d.ts +0 -196
@@ -1,25 +1,27 @@
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
- /** 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;
5
+ import { joinFuture, newTransaction, enterAction, exitAction, resolveTx, schedule, actionDepth, flush, nextQuestion, setQuestion, question } from "./scheduler.js";
11
6
 
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;
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;
23
25
  }
24
26
 
25
27
  /**
@@ -40,9 +42,9 @@ function restoreTransition(e, t, n) {
40
42
  * submission tracking layered on top. The shared name is deliberate.
41
43
  *
42
44
  * Wraps a generator function so each invocation runs as a single transaction
43
- * (a "transition") that batches every signal/store write between yields. The
44
- * surrounding UI sees one atomic update per yielded step; nothing is committed
45
- * 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.
46
48
  *
47
49
  * `yield` is the transaction-safe suspension point: the action waits for a
48
50
  * yielded promise and re-enters the transaction before running the code after
@@ -52,8 +54,7 @@ function restoreTransition(e, t, n) {
52
54
  * commit immediately, and anything that creates a reader there — `until()`,
53
55
  * `latest()`, a memo or effect, a mount — is created mainline, where a read of
54
56
  * 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
+ * transaction and replayed at its commit. `await` is still the ergonomic
57
58
  * choice for typed results; just put a bare `yield` before any write or
58
59
  * reader creation that follows it — including the expression of the next
59
60
  * `yield`, which is evaluated before the step re-enters:
@@ -66,7 +67,7 @@ function restoreTransition(e, t, n) {
66
67
  * ```
67
68
  *
68
69
  * (For the same reason, don't call `flush()` inside an action body — it
69
- * drains the transaction mid-step.)
70
+ * cannot reveal the held writes and is refused.)
70
71
  *
71
72
  * Each call returns a `Promise` that resolves with the generator's return
72
73
  * value, or rejects if it throws. Pair with `createOptimistic` /
@@ -91,76 +92,72 @@ function restoreTransition(e, t, n) {
91
92
  *
92
93
  * await addTodo("buy milk");
93
94
  * ```
94
- */ function action(e) {
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);
101
- globalQueue.initTransition();
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);
109
- // Re-adopt through initTransition like every other resumption site:
110
- // a bare setActiveTransition leaves globalQueue._batch as a detached
111
- // ambient batch, and anything registered before the scheduled flush
112
- // (held writes on a merging transition, optimistic overrides,
113
- // affects() marks) lands there with nothing to ever finalize it.
114
- globalQueue.initTransition(s);
95
+ */ function action(t) {
96
+ return (...n) => new Promise((e, i) => {
97
+ const o = t(...n);
98
+ // The action's transaction, held open until the body returns. The
99
+ // first slice's writes are carried by the tick's scheduled flush.
100
+ const r = newTransaction(false);
101
+ r.tt = 1;
102
+ r.nt = true;
103
+ const s = nextQuestion();
104
+ const done = (t, n, o = false) => {
105
+ resolveTx(r).tt--;
115
106
  schedule();
116
- o ? r(t) : n(e);
107
+ o ? i(n) : e(t);
117
108
  };
118
- const step = (e, t) => {
119
- let n;
109
+ const step = (t, n) => {
110
+ let e;
120
111
  // The body is on the stack between these brackets: flush() is
121
112
  // refused inside (FLUSH_IN_ACTION, scheduler.ts).
122
- enterActionStep();
113
+ enterAction();
123
114
  try {
124
- n = t ? i.throw(e) : i.next(e);
125
- } catch (e) {
126
- exitActionStep();
127
- return done(undefined, e, true);
115
+ e = n ? o.throw(t) : o.next(t);
116
+ } catch (t) {
117
+ exitAction();
118
+ return done(undefined, t, true);
128
119
  }
129
- exitActionStep();
120
+ exitAction();
130
121
  // A rejected iterator result (async generators) means the error already
131
122
  // escaped the generator body — it is completed, and throwing back in
132
123
  // would just reject again forever. Settle instead.
133
- if (isThenable(n)) return void n.then(run, e => done(undefined, e, true));
134
- run(n);
124
+ if (isThenable(e)) return void e.then(run, t => done(undefined, t, true));
125
+ run(e);
135
126
  };
136
- const run = e => {
137
- if (e.done) return done(e.value);
127
+ const run = t => {
128
+ if (t.done) return done(t.value);
138
129
  // Thenable assimilation can itself throw synchronously (a `then`
139
130
  // getter, or a `then()` method that throws — #2918). Match `await`
140
131
  // semantics: the failure is thrown back into the generator at the
141
132
  // yield point (catchable there); if uncaught, step()'s guard settles
142
- // the action so its iterator never leaks in the transition. The
143
- // settled flag implements A+ 2.3.3.3.4.1: a throw after the thenable
144
- // already called a callback is ignored.
145
- let t = false;
133
+ // the action. The settled flag implements A+ 2.3.3.3.4.1: a throw
134
+ // after the thenable already called a callback is ignored.
135
+ let n = false;
146
136
  try {
147
- if (isThenable(e.value)) return void e.value.then(e => {
148
- if (t) return;
149
- t = true;
150
- restoreTransition(o, s, () => step(e));
151
- }, e => {
152
- if (t) return;
153
- t = true;
154
- restoreTransition(o, s, () => step(e, true));
137
+ if (isThenable(t.value)) return void t.value.then(t => {
138
+ if (n) return;
139
+ n = true;
140
+ inTransaction(r, s, () => step(t));
141
+ }, t => {
142
+ if (n) return;
143
+ n = true;
144
+ inTransaction(r, s, () => step(t, true));
155
145
  });
156
- } catch (e) {
157
- if (t) return;
158
- t = true;
159
- return void restoreTransition(o, s, () => step(e, true));
146
+ } catch (t) {
147
+ if (n) return;
148
+ n = true;
149
+ return void inTransaction(r, s, () => step(t, true));
160
150
  }
161
- restoreTransition(o, s, () => step(e.value));
151
+ inTransaction(r, s, () => step(t.value));
162
152
  };
153
+ // The first slice's writes are carried by the tick's scheduled flush;
154
+ // the slice itself asks the action's question (its guesses are stamped
155
+ // at the write).
156
+ joinFuture(r);
157
+ const u = question;
158
+ setQuestion(s);
163
159
  step();
160
+ setQuestion(u);
164
161
  });
165
162
  }
166
163