@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.
- package/dist/dev-shared.js +6505 -0
- package/dist/dev.attribution.js +3484 -0
- package/dist/dev.js +10227 -9508
- package/dist/observe/affects-marks.js +86 -0
- package/dist/observe/affects.js +112 -0
- package/dist/observe/attribution.js +7 -0
- package/dist/observe/boundaries.js +696 -0
- package/dist/observe/core/action.js +182 -0
- package/dist/observe/core/async.js +824 -0
- package/dist/observe/core/attribution-costs.js +66 -0
- package/dist/observe/core/attribution-feedback.js +280 -0
- package/dist/observe/core/attribution-hooks.js +83 -0
- package/dist/observe/core/attribution-queries.js +43 -0
- package/dist/observe/core/attribution.js +3079 -0
- package/dist/observe/core/constants.js +269 -0
- package/dist/observe/core/context.js +63 -0
- package/dist/observe/core/copies.js +10 -0
- package/dist/observe/core/core.js +1707 -0
- package/dist/observe/core/dev.js +394 -0
- package/dist/observe/core/effect.js +193 -0
- package/dist/observe/core/error-hooks.js +71 -0
- package/dist/observe/core/error.js +82 -0
- package/dist/observe/core/external.js +97 -0
- package/dist/observe/core/graph.js +162 -0
- package/dist/observe/core/heap.js +124 -0
- package/dist/observe/core/identities.js +62 -0
- package/dist/observe/core/invariants.js +12 -0
- package/dist/observe/core/lanes.js +972 -0
- package/dist/observe/core/owner.js +371 -0
- package/dist/observe/core/scheduler.js +1157 -0
- package/dist/observe/core/truth.js +47 -0
- package/dist/observe/core/verdict.js +470 -0
- package/dist/observe/deferred.js +186 -0
- package/dist/observe/flatten.js +79 -0
- package/dist/observe/from.js +248 -0
- package/dist/observe/index.js +71 -0
- package/dist/observe/map.js +593 -0
- package/dist/observe/reveal.js +212 -0
- package/dist/observe/signals.js +717 -0
- package/dist/observe/store/affects.js +142 -0
- package/dist/observe/store/edges.js +39 -0
- package/dist/observe/store/hooks.js +16 -0
- package/dist/observe/store/index.js +47 -0
- package/dist/observe/store/optimistic.js +713 -0
- package/dist/observe/store/projection.js +345 -0
- package/dist/observe/store/reconcile.js +281 -0
- package/dist/observe/store/store.js +2127 -0
- package/dist/observe/store/storePath.js +103 -0
- package/dist/observe/store/target.js +46 -0
- package/dist/observe/store/types.js +83 -0
- package/dist/observe/store/utils.js +1063 -0
- package/dist/prod/affects-marks.js +86 -0
- package/dist/prod/affects.js +98 -112
- package/dist/prod/attribution.js +45 -0
- package/dist/prod/boundaries.js +578 -468
- package/dist/prod/core/action.js +92 -59
- package/dist/prod/core/async.js +522 -336
- package/dist/prod/core/attribution-hooks.js +3 -0
- package/dist/prod/core/constants.js +168 -44
- package/dist/prod/core/context.js +12 -16
- package/dist/prod/core/copies.js +10 -0
- package/dist/prod/core/core.js +1345 -627
- package/dist/prod/core/dev.js +123 -1
- package/dist/prod/core/effect.js +113 -80
- package/dist/prod/core/error-hooks.js +71 -0
- package/dist/prod/core/error.js +18 -4
- package/dist/prod/core/external.js +6 -7
- package/dist/prod/core/graph.js +119 -72
- package/dist/prod/core/heap.js +85 -109
- package/dist/prod/core/identities.js +62 -0
- package/dist/prod/core/invariants.js +1 -32
- package/dist/prod/core/lanes.js +931 -132
- package/dist/prod/core/owner.js +192 -129
- package/dist/prod/core/scheduler.js +948 -642
- package/dist/prod/core/truth.js +47 -0
- package/dist/prod/core/verdict.js +409 -420
- package/dist/prod/deferred.js +184 -0
- package/dist/prod/flatten.js +77 -0
- package/dist/prod/from.js +248 -0
- package/dist/prod/index.js +40 -16
- package/dist/prod/map.js +481 -211
- package/dist/prod/reveal.js +212 -0
- package/dist/prod/signals.js +401 -84
- package/dist/prod/store/affects.js +142 -0
- package/dist/prod/store/edges.js +39 -0
- package/dist/prod/store/hooks.js +16 -0
- package/dist/prod/store/index.js +27 -18
- package/dist/prod/store/optimistic.js +707 -0
- package/dist/prod/store/projection.js +331 -0
- package/dist/prod/store/reconcile.js +281 -0
- package/dist/prod/store/store.js +1952 -267
- package/dist/prod/store/storePath.js +1 -1
- package/dist/prod/store/target.js +43 -0
- package/dist/prod/store/types.js +83 -0
- package/dist/prod/store/utils.js +997 -138
- package/dist/types/affects-marks.d.ts +14 -0
- package/dist/types/affects.d.ts +12 -30
- package/dist/types/attribution.d.ts +19 -0
- package/dist/types/attribution.prod.d.ts +22 -0
- package/dist/types/boundaries.d.ts +99 -124
- package/dist/types/carved.d.ts +1 -0
- package/dist/types/core/action.d.ts +23 -9
- package/dist/types/core/async.d.ts +34 -6
- package/dist/types/core/attribution-costs.d.ts +35 -0
- package/dist/types/core/attribution-feedback.d.ts +133 -0
- package/dist/types/core/attribution-hooks.d.ts +307 -8
- package/dist/types/core/attribution-queries.d.ts +24 -0
- package/dist/types/core/attribution.d.ts +802 -72
- package/dist/types/core/constants.d.ts +195 -38
- package/dist/types/core/copies.d.ts +54 -0
- package/dist/types/core/core.d.ts +295 -65
- package/dist/types/core/dev.d.ts +509 -22
- package/dist/types/core/effect.d.ts +1 -1
- package/dist/types/core/error-hooks.d.ts +71 -0
- package/dist/types/core/error.d.ts +18 -1
- package/dist/types/core/graph.d.ts +40 -1
- package/dist/types/core/heap.d.ts +5 -5
- package/dist/types/core/identities.d.ts +17 -0
- package/dist/types/core/index.d.ts +11 -7
- package/dist/types/core/invariants.d.ts +1 -26
- package/dist/types/core/lanes.d.ts +74 -43
- package/dist/types/core/owner.d.ts +27 -9
- package/dist/types/core/scheduler.d.ts +353 -102
- package/dist/types/core/truth.d.ts +18 -0
- package/dist/types/core/types.d.ts +97 -71
- package/dist/types/core/verdict.d.ts +35 -0
- package/dist/types/deferred.d.ts +28 -0
- package/dist/types/flatten.d.ts +8 -0
- package/dist/types/from.d.ts +47 -0
- package/dist/types/index.d.ts +33 -7
- package/dist/types/map.d.ts +4 -2
- package/dist/types/reveal.d.ts +19 -0
- package/dist/types/signals.d.ts +196 -45
- package/dist/types/store/affects.d.ts +12 -0
- package/dist/types/store/edges.d.ts +9 -0
- package/dist/types/store/hooks.d.ts +62 -0
- package/dist/types/store/index.d.ts +42 -15
- package/dist/types/store/optimistic.d.ts +24 -45
- package/dist/types/store/projection.d.ts +17 -68
- package/dist/types/store/reconcile.d.ts +3 -46
- package/dist/types/store/store.d.ts +133 -136
- package/dist/types/store/storePath.d.ts +1 -1
- package/dist/types/store/target.d.ts +166 -0
- package/dist/types/store/types.d.ts +105 -0
- package/dist/types/store/utils.d.ts +188 -0
- package/package.json +31 -26
- package/dist/node.cjs +0 -8745
- package/dist/prod/core/optimistic.js +0 -265
- package/dist/prod/store/next/optimistic.js +0 -385
- package/dist/prod/store/next/projection.js +0 -172
- package/dist/prod/store/next/reconcile.js +0 -331
- package/dist/prod/store/next/store.js +0 -1499
- package/dist/prod/store/next/target.js +0 -20
- package/dist/types/core/optimistic.d.ts +0 -6
- package/dist/types/store/next/optimistic.d.ts +0 -20
- package/dist/types/store/next/projection.d.ts +0 -8
- package/dist/types/store/next/reconcile.d.ts +0 -3
- package/dist/types/store/next/store.d.ts +0 -77
- package/dist/types/store/next/target.d.ts +0 -117
- package/dist/types-cjs/affects.d.cts +0 -47
- package/dist/types-cjs/boundaries.d.cts +0 -175
- package/dist/types-cjs/core/action.d.cts +0 -64
- package/dist/types-cjs/core/async.d.cts +0 -21
- package/dist/types-cjs/core/attribution-hooks.d.cts +0 -52
- package/dist/types-cjs/core/attribution.d.cts +0 -186
- package/dist/types-cjs/core/constants.d.cts +0 -97
- package/dist/types-cjs/core/context.d.cts +0 -36
- package/dist/types-cjs/core/core.d.cts +0 -163
- package/dist/types-cjs/core/dev.d.cts +0 -81
- package/dist/types-cjs/core/effect.d.cts +0 -30
- package/dist/types-cjs/core/error.d.cts +0 -47
- package/dist/types-cjs/core/external.d.cts +0 -15
- package/dist/types-cjs/core/graph.d.cts +0 -6
- package/dist/types-cjs/core/heap.d.cts +0 -22
- package/dist/types-cjs/core/index.d.cts +0 -13
- package/dist/types-cjs/core/invariants.d.cts +0 -59
- package/dist/types-cjs/core/lanes.d.cts +0 -44
- package/dist/types-cjs/core/optimistic.d.cts +0 -6
- package/dist/types-cjs/core/owner.d.cts +0 -124
- package/dist/types-cjs/core/scheduler.d.cts +0 -180
- package/dist/types-cjs/core/types.d.cts +0 -192
- package/dist/types-cjs/core/verdict.d.cts +0 -2
- package/dist/types-cjs/index.d.cts +0 -10
- package/dist/types-cjs/map.d.cts +0 -69
- package/dist/types-cjs/package.json +0 -3
- package/dist/types-cjs/signals.d.cts +0 -624
- package/dist/types-cjs/store/index.d.cts +0 -19
- package/dist/types-cjs/store/next/optimistic.d.cts +0 -20
- package/dist/types-cjs/store/next/projection.d.cts +0 -8
- package/dist/types-cjs/store/next/reconcile.d.cts +0 -3
- package/dist/types-cjs/store/next/store.d.cts +0 -77
- package/dist/types-cjs/store/next/target.d.cts +0 -117
- package/dist/types-cjs/store/optimistic.d.cts +0 -45
- package/dist/types-cjs/store/projection.d.cts +0 -70
- package/dist/types-cjs/store/reconcile.d.cts +0 -46
- package/dist/types-cjs/store/store.d.cts +0 -138
- package/dist/types-cjs/store/storePath.d.cts +0 -58
- package/dist/types-cjs/store/utils.d.cts +0 -74
package/dist/prod/core/action.js
CHANGED
|
@@ -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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
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
|
|
40
|
-
*
|
|
41
|
-
* immediately
|
|
42
|
-
*
|
|
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
|
-
*
|
|
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(
|
|
77
|
-
return (...
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
|
|
115
|
+
o ? i(n) : e(t);
|
|
94
116
|
};
|
|
95
|
-
const step = (
|
|
96
|
-
let
|
|
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
|
-
|
|
99
|
-
} catch (
|
|
100
|
-
|
|
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(
|
|
106
|
-
run(
|
|
132
|
+
if (isThenable(e)) return void e.then(run, t => done(undefined, t, true));
|
|
133
|
+
run(e);
|
|
107
134
|
};
|
|
108
|
-
const run =
|
|
109
|
-
if (
|
|
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
|
|
115
|
-
//
|
|
116
|
-
|
|
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(
|
|
120
|
-
if (
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
},
|
|
124
|
-
if (
|
|
125
|
-
|
|
126
|
-
|
|
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 (
|
|
129
|
-
if (
|
|
130
|
-
|
|
131
|
-
return void
|
|
154
|
+
} catch (t) {
|
|
155
|
+
if (n) return;
|
|
156
|
+
n = true;
|
|
157
|
+
return void inTransaction(r, s, () => step(t, true));
|
|
132
158
|
}
|
|
133
|
-
|
|
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
|
|