@solidjs/signals 2.0.0-rc.1 → 2.0.0-rc.11
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 +7155 -0
- package/dist/dev.attribution.js +3307 -0
- package/dist/dev.js +5765 -4496
- package/dist/observe/affects.js +129 -0
- package/dist/observe/attribution.js +7 -0
- package/dist/observe/boundaries.js +793 -0
- package/dist/observe/core/action.js +177 -0
- package/dist/observe/core/async.js +849 -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 +2904 -0
- package/dist/observe/core/constants.js +283 -0
- package/dist/{types-cjs/core/context.d.cts → observe/core/context.js} +37 -12
- package/dist/observe/core/core.js +1999 -0
- package/dist/observe/core/dev.js +343 -0
- package/dist/observe/core/effect.js +200 -0
- package/dist/observe/core/error-hooks.js +71 -0
- package/dist/observe/core/error.js +80 -0
- package/dist/observe/core/external.js +98 -0
- package/dist/observe/core/graph.js +155 -0
- package/dist/observe/core/heap.js +147 -0
- package/dist/observe/core/invariants.js +45 -0
- package/dist/observe/core/lanes.js +205 -0
- package/dist/observe/core/optimistic.js +669 -0
- package/dist/observe/core/owner.js +353 -0
- package/dist/observe/core/scheduler.js +1561 -0
- package/dist/observe/core/verdict.js +674 -0
- package/dist/observe/index.js +59 -0
- package/dist/observe/map.js +507 -0
- package/dist/observe/signals.js +731 -0
- package/dist/observe/store/index.js +44 -0
- package/dist/observe/store/next/optimistic.js +717 -0
- package/dist/observe/store/next/projection.js +266 -0
- package/dist/observe/store/next/reconcile.js +375 -0
- package/dist/observe/store/next/store.js +2480 -0
- package/dist/observe/store/next/target.js +51 -0
- package/dist/observe/store/store.js +331 -0
- package/dist/observe/store/storePath.js +103 -0
- package/dist/observe/store/utils.js +1070 -0
- package/dist/prod/affects.js +10 -9
- package/dist/prod/attribution.js +45 -0
- package/dist/prod/boundaries.js +388 -178
- package/dist/prod/core/action.js +65 -37
- package/dist/prod/core/async.js +378 -163
- package/dist/prod/core/attribution-hooks.js +3 -0
- package/dist/prod/core/constants.js +186 -1
- package/dist/prod/core/context.js +10 -16
- package/dist/prod/core/core.js +1546 -416
- package/dist/prod/core/dev.js +18 -1
- package/dist/prod/core/effect.js +119 -79
- package/dist/prod/core/error-hooks.js +71 -0
- package/dist/prod/core/error.js +13 -1
- package/dist/prod/core/external.js +4 -4
- package/dist/prod/core/graph.js +105 -54
- package/dist/prod/core/heap.js +72 -65
- package/dist/prod/core/invariants.js +3 -2
- package/dist/prod/core/lanes.js +117 -52
- package/dist/prod/core/optimistic.js +500 -104
- package/dist/prod/core/owner.js +131 -84
- package/dist/prod/core/scheduler.js +1012 -241
- package/dist/prod/core/verdict.js +417 -112
- package/dist/prod/index.js +20 -8
- package/dist/prod/map.js +355 -171
- package/dist/prod/signals.js +363 -32
- package/dist/prod/store/index.js +2 -0
- package/dist/prod/store/next/optimistic.js +530 -197
- package/dist/prod/store/next/projection.js +142 -57
- package/dist/prod/store/next/reconcile.js +149 -103
- package/dist/prod/store/next/store.js +1470 -346
- package/dist/prod/store/next/target.js +40 -9
- package/dist/prod/store/store.js +23 -19
- package/dist/prod/store/utils.js +997 -130
- package/dist/types/attribution.d.ts +19 -0
- package/dist/types/attribution.prod.d.ts +22 -0
- package/dist/types/boundaries.d.ts +78 -5
- package/dist/types/core/action.d.ts +12 -5
- package/dist/types/core/async.d.ts +3 -1
- 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 +304 -0
- package/dist/types/core/attribution-queries.d.ts +24 -0
- package/dist/types/core/attribution.d.ts +892 -0
- package/dist/types/core/constants.d.ts +179 -0
- package/dist/types/core/core.d.ts +299 -25
- package/dist/types/core/dev.d.ts +421 -8
- package/dist/types/core/effect.d.ts +8 -1
- package/dist/types/core/error-hooks.d.ts +71 -0
- package/dist/types/core/error.d.ts +9 -0
- package/dist/types/core/graph.d.ts +23 -0
- package/dist/types/core/heap.d.ts +5 -3
- package/dist/types/core/index.d.ts +6 -3
- package/dist/types/core/invariants.d.ts +5 -1
- package/dist/types/core/lanes.d.ts +51 -19
- package/dist/types/core/owner.d.ts +15 -3
- package/dist/types/core/scheduler.d.ts +252 -1
- package/dist/types/core/types.d.ts +124 -41
- package/dist/types/index.d.ts +18 -5
- package/dist/types/map.d.ts +2 -0
- package/dist/types/signals.d.ts +145 -13
- package/dist/types/store/index.d.ts +7 -6
- package/dist/types/store/next/optimistic.d.ts +18 -13
- package/dist/types/store/next/projection.d.ts +5 -2
- package/dist/types/store/next/reconcile.d.ts +7 -0
- package/dist/types/store/next/store.d.ts +83 -11
- package/dist/types/store/next/target.d.ts +108 -11
- package/dist/types/store/store.d.ts +20 -11
- package/dist/types/store/utils.d.ts +188 -0
- package/package.json +31 -26
- package/dist/node.cjs +0 -8137
- package/dist/types/store/optimistic.d.ts +0 -45
- package/dist/types/store/projection.d.ts +0 -70
- package/dist/types/store/reconcile.d.ts +0 -46
- 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/constants.d.cts +0 -71
- package/dist/types-cjs/core/core.d.cts +0 -156
- package/dist/types-cjs/core/dev.d.cts +0 -64
- 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 -5
- 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 -56
- 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 -172
- package/dist/types-cjs/core/types.d.cts +0 -148
- 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 -24
- package/dist/types-cjs/store/next/reconcile.d.cts +0 -3
- package/dist/types-cjs/store/next/store.d.cts +0 -71
- package/dist/types-cjs/store/next/target.d.cts +0 -99
- 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
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { computed
|
|
1
|
+
import { computed } from "../../core/core.js";
|
|
2
2
|
|
|
3
|
-
import { getOwner } from "../../core/owner.js";
|
|
3
|
+
import { isDisposed, getOwner } from "../../core/owner.js";
|
|
4
4
|
|
|
5
|
-
import { setProjectionWriteActive, projectionWriteActive } from "../../core/scheduler.js";
|
|
5
|
+
import { setProjectionWriteActive, projectionWriteActive, scheduleWithheld } from "../../core/scheduler.js";
|
|
6
6
|
|
|
7
7
|
import { handleAsync } from "../../core/async.js";
|
|
8
8
|
|
|
@@ -10,13 +10,13 @@ import "../../core/verdict.js";
|
|
|
10
10
|
|
|
11
11
|
import "../../core/effect.js";
|
|
12
12
|
|
|
13
|
-
import { CONFIG_AUTO_DISPOSE } from "../../core/constants.js";
|
|
13
|
+
import { CONFIG_AUTO_DISPOSE, STATUS_PENDING } from "../../core/constants.js";
|
|
14
14
|
|
|
15
|
-
import { $TARGET,
|
|
15
|
+
import { $TARGET, STORE_VALUE, markRawIngest, setWriteOverride } from "../store.js";
|
|
16
16
|
|
|
17
17
|
import { reconcileNextState } from "./reconcile.js";
|
|
18
18
|
|
|
19
|
-
import { wrapNext,
|
|
19
|
+
import { storeSetterNext, wrapNext, derivedStoreWrite } from "./store.js";
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* Store rewrite — projections (§7/§7b): a projection is a computed store.
|
|
@@ -33,68 +33,119 @@ import { wrapNext, storeSetterNext } from "./store.js";
|
|
|
33
33
|
* loading windows, handleAsync landings, commit-through-setter) on next
|
|
34
34
|
* primitives; the generic draft write-traps are reused from the legacy
|
|
35
35
|
* module unchanged.
|
|
36
|
-
*/
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
36
|
+
*/
|
|
37
|
+
/**
|
|
38
|
+
* Wrap a store proxy as a projection DRAFT: every operation carries the write
|
|
39
|
+
* override (the derive is the author — its ops must not hit the §6c firewall
|
|
40
|
+
* gate, even in a continuation after an `await`/`yield` where the sync write
|
|
41
|
+
* scope has closed).
|
|
42
|
+
*
|
|
43
|
+
* FAKE TARGET, not the store proxy itself (#3060): after a proxy trap
|
|
44
|
+
* returns, the engine runs spec invariant validation against the proxy's
|
|
45
|
+
* TARGET — [[OwnPropertyKeys]] after ownKeys, [[GetOwnProperty]] after
|
|
46
|
+
* set/getOwnPropertyDescriptor/defineProperty. With the store proxy as
|
|
47
|
+
* target those checks re-enter the store's traps OUTSIDE the override
|
|
48
|
+
* bracket (the trap's finally has already run), so `Object.keys(state)` in
|
|
49
|
+
* a derive continuation fired the firewall gate and re-threw the
|
|
50
|
+
* projection's own pending NotReadyError into the derive. A dummy of
|
|
51
|
+
* matching kind (array/object, same trick as the store's own TargetShape)
|
|
52
|
+
* keeps invariant validation away from the store entirely; the traps
|
|
53
|
+
* forward to the closed-over inner proxy inside the bracket.
|
|
54
|
+
*
|
|
55
|
+
* Save/restore projectionWriteActive, never hard-reset: the draft can be
|
|
56
|
+
* driven from inside an enclosing authoritative-write scope (next-store
|
|
57
|
+
* optimistic derives), and a hard `false` would clobber it mid-derive.
|
|
58
|
+
*/ function wrapDraft(e, t, r, o, i) {
|
|
59
|
+
// One bracket for the three mutating traps. A write to a superseded or
|
|
60
|
+
// disposed draft is dropped silently (proj R37 — the same fate as a
|
|
61
|
+
// superseded async run's pending draft writes, R26). `afterWrite` runs
|
|
62
|
+
// once the bracket has closed — outside it, so the scheduler's
|
|
63
|
+
// projectionWriteActive guard no longer applies — and only for the
|
|
64
|
+
// outermost bracket (a draft driven from inside an enclosing authoritative
|
|
65
|
+
// scope, the optimistic derive, leaves scheduling to that scope's caller).
|
|
66
|
+
const mutate = e => {
|
|
67
|
+
if (!t()) return true;
|
|
68
|
+
const o = projectionWriteActive;
|
|
69
|
+
setWriteOverride(true);
|
|
70
|
+
setProjectionWriteActive(true);
|
|
71
|
+
try {
|
|
72
|
+
r ? r(e) : e();
|
|
73
|
+
} finally {
|
|
74
|
+
setWriteOverride(false);
|
|
75
|
+
setProjectionWriteActive(o);
|
|
76
|
+
}
|
|
77
|
+
if (!o && i) i();
|
|
78
|
+
return true;
|
|
79
|
+
};
|
|
80
|
+
const n = {
|
|
81
|
+
get(n, c) {
|
|
82
|
+
let s;
|
|
83
|
+
const l = projectionWriteActive;
|
|
44
84
|
setWriteOverride(true);
|
|
45
85
|
setProjectionWriteActive(true);
|
|
46
86
|
try {
|
|
47
|
-
|
|
87
|
+
s = e[c];
|
|
48
88
|
} finally {
|
|
49
89
|
setWriteOverride(false);
|
|
50
|
-
setProjectionWriteActive(
|
|
90
|
+
setProjectionWriteActive(l);
|
|
51
91
|
}
|
|
52
|
-
|
|
53
|
-
|
|
92
|
+
// A shallow store's leaves are raw by contract (#3498): no draft proxy
|
|
93
|
+
// over them, so identity holds and a frozen leaf is never trapped.
|
|
94
|
+
return !o && typeof s === "object" && s !== null && c !== $TARGET ? wrapDraft(s, t, r, false, i) : s;
|
|
54
95
|
},
|
|
55
|
-
has(
|
|
56
|
-
let
|
|
57
|
-
const
|
|
96
|
+
has(t, r) {
|
|
97
|
+
let o;
|
|
98
|
+
const i = projectionWriteActive;
|
|
58
99
|
setWriteOverride(true);
|
|
59
100
|
setProjectionWriteActive(true);
|
|
60
101
|
try {
|
|
61
|
-
|
|
102
|
+
o = r in e;
|
|
62
103
|
} finally {
|
|
63
104
|
setWriteOverride(false);
|
|
64
|
-
setProjectionWriteActive(
|
|
105
|
+
setProjectionWriteActive(i);
|
|
65
106
|
}
|
|
66
|
-
return
|
|
107
|
+
return o;
|
|
67
108
|
},
|
|
68
|
-
set(r, o
|
|
69
|
-
|
|
70
|
-
|
|
109
|
+
set: (t, r, o) => mutate(() => {
|
|
110
|
+
e[r] = o;
|
|
111
|
+
}),
|
|
112
|
+
deleteProperty: (t, r) => mutate(() => {
|
|
113
|
+
delete e[r];
|
|
114
|
+
}),
|
|
115
|
+
ownKeys() {
|
|
116
|
+
const t = projectionWriteActive;
|
|
71
117
|
setWriteOverride(true);
|
|
72
118
|
setProjectionWriteActive(true);
|
|
73
119
|
try {
|
|
74
|
-
|
|
75
|
-
t?.();
|
|
120
|
+
return Reflect.ownKeys(e);
|
|
76
121
|
} finally {
|
|
77
122
|
setWriteOverride(false);
|
|
78
|
-
setProjectionWriteActive(
|
|
123
|
+
setProjectionWriteActive(t);
|
|
79
124
|
}
|
|
80
|
-
return true;
|
|
81
125
|
},
|
|
82
|
-
|
|
83
|
-
|
|
126
|
+
getOwnPropertyDescriptor(t, r) {
|
|
127
|
+
let o;
|
|
84
128
|
const i = projectionWriteActive;
|
|
85
129
|
setWriteOverride(true);
|
|
86
130
|
setProjectionWriteActive(true);
|
|
87
131
|
try {
|
|
88
|
-
|
|
89
|
-
t?.();
|
|
132
|
+
o = Reflect.getOwnPropertyDescriptor(e, r);
|
|
90
133
|
} finally {
|
|
91
134
|
setWriteOverride(false);
|
|
92
135
|
setProjectionWriteActive(i);
|
|
93
136
|
}
|
|
94
|
-
|
|
95
|
-
|
|
137
|
+
// The dummy target doesn't hold the key, so a non-configurable report
|
|
138
|
+
// would violate the proxy invariant. Store descriptors are already
|
|
139
|
+
// normalized configurable; enforce it for raw leaves too.
|
|
140
|
+
if (o) o.configurable = true;
|
|
141
|
+
return o;
|
|
142
|
+
},
|
|
143
|
+
defineProperty: (t, r, o) => mutate(() => {
|
|
144
|
+
Reflect.defineProperty(e, r, o);
|
|
145
|
+
})
|
|
96
146
|
};
|
|
97
|
-
|
|
147
|
+
// Matching-kind dummy so Array.isArray(draft) answers like the store.
|
|
148
|
+
return new Proxy(Array.isArray(e) ? [] : {}, n);
|
|
98
149
|
}
|
|
99
150
|
|
|
100
151
|
function createProjectionNextInternal(e, t, r) {
|
|
@@ -118,7 +169,7 @@ function createProjectionNextInternal(e, t, r) {
|
|
|
118
169
|
if (!o.node) o.node = getOwner();
|
|
119
170
|
runProjectionComputedNext(i, e, r?.key === undefined ? "id" : r.key);
|
|
120
171
|
}, n);
|
|
121
|
-
c.
|
|
172
|
+
c.C &= ~CONFIG_AUTO_DISPOSE;
|
|
122
173
|
o.node = c;
|
|
123
174
|
return {
|
|
124
175
|
store: i,
|
|
@@ -132,39 +183,73 @@ function createProjectionNext(e, t, r) {
|
|
|
132
183
|
|
|
133
184
|
/** Derived writable store (legacy parity): a projection whose public setter
|
|
134
185
|
* masks the recompute for the tick (core R31 — the manual write wins over a
|
|
135
|
-
* same-flush dependency change).
|
|
186
|
+
* same-flush dependency change). Across a hold the write is not a proposal:
|
|
187
|
+
* a leaf another transaction holds as the fold's result re-runs the fold
|
|
188
|
+
* under it, the write being the draft's prior state (A34 amendment, #3612;
|
|
189
|
+
* core derivedWrite). */ function createStoreDerivedNext(e, t, r) {
|
|
136
190
|
const {store: o, node: i} = createProjectionNextInternal(e, t, r);
|
|
137
|
-
return [ o, e =>
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
191
|
+
return [ o, e => derivedStoreWrite(i, o, e) ];
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// A detached copy of projection state: the root container alone for a shallow
|
|
195
|
+
// store — its leaves are raw references by contract and stay so (#3498) — the
|
|
196
|
+
// whole tree otherwise.
|
|
197
|
+
function cloneState(e, t) {
|
|
198
|
+
return t ? Array.isArray(e) ? e.slice() : {
|
|
199
|
+
...e
|
|
200
|
+
} : JSON.parse(JSON.stringify(e));
|
|
142
201
|
}
|
|
143
202
|
|
|
144
203
|
function runProjectionComputedNext(e, t, r, o, i) {
|
|
145
204
|
const n = getOwner();
|
|
146
|
-
|
|
147
|
-
|
|
205
|
+
const c = e[$TARGET];
|
|
206
|
+
const s = c.fam;
|
|
207
|
+
// Draft validity is per run (R37): live from here until the NEXT run starts
|
|
208
|
+
// — this counter moves, whatever that run does (lands, throws NotReady,
|
|
209
|
+
// awaits) — or the owner is disposed. Not "until no longer in flight": a
|
|
210
|
+
// sync derive that subscribes to an external source and pushes into the
|
|
211
|
+
// draft from the callback (#3585) is the model use, and the old gate
|
|
212
|
+
// (`owner._x?._inFlight === result`) only admitted it by accident — while
|
|
213
|
+
// nothing had read the projection yet (no `_x`), `undefined === undefined`.
|
|
214
|
+
const l = s.run = (s.run || 0) + 1;
|
|
215
|
+
let u;
|
|
148
216
|
// Open loading window (seedLoadingValue): the observable store IS commit #0
|
|
149
217
|
// for the whole first flight — the derive works a detached shadow of the
|
|
150
218
|
// seed so draft writes cannot tear through to readers (#2988). Every commit
|
|
151
|
-
// point reconciles the shadow through the normal commit path.
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
219
|
+
// point reconciles the shadow through the normal commit path. (A callback
|
|
220
|
+
// that closes over the shadow writes into a dead clone once the window has
|
|
221
|
+
// closed — the one carve-out from R37's one-draft-per-run model.)
|
|
222
|
+
const a = n.ve ? cloneState(c[STORE_VALUE], c.s) : null;
|
|
223
|
+
const f = wrapDraft(e, () => s.run === l && !isDisposed(n), i, c.s,
|
|
224
|
+
// A write after the run returned takes the override channel (pending
|
|
225
|
+
// backing + per-op notify + fold) and arms the drain itself when no
|
|
226
|
+
// landing will: a flight still up — pending, or the loading window's
|
|
227
|
+
// first flight — drains at its landing, and must not be drained early.
|
|
228
|
+
// Not gated on the run having returned: the body's own writes withhold
|
|
229
|
+
// the microtask too, and a derive body only ever runs outside a flush at
|
|
230
|
+
// creation (reruns are flush-driven) — a top-level sync projection in a
|
|
231
|
+
// createRoot stranded the scheduler until an explicit flush(). Arming
|
|
232
|
+
// mid-body is safe: the microtask fires after this synchronous slice,
|
|
233
|
+
// when the body has returned or parked, and an initial async run's
|
|
234
|
+
// pre-await half drains before its landing exactly as it does when the
|
|
235
|
+
// creation ran inside a flush — nothing reads it before the landing
|
|
236
|
+
// (the node is uninitialized, proj R23).
|
|
237
|
+
() => {
|
|
238
|
+
if (!(n.h & STATUS_PENDING) && !n.ve) scheduleWithheld();
|
|
239
|
+
});
|
|
240
|
+
storeSetterNext(f, i => {
|
|
241
|
+
u = t(a ?? i);
|
|
157
242
|
const commit = t => {
|
|
158
243
|
// Shadow run: commit a detached snapshot, never the shadow itself
|
|
159
244
|
// (adoption takes the value by identity — handing it the live shadow
|
|
160
245
|
// would fuse the draft to the observable store).
|
|
161
|
-
if (
|
|
246
|
+
if (a && (t === undefined || t === a)) t = cloneState(a, c.s);
|
|
162
247
|
if (t === i || t === undefined) return;
|
|
163
248
|
const write = () => storeSetterNext(e, e => reconcileNextState(t, e, r, true), false);
|
|
164
|
-
o ? o(write) : write();
|
|
249
|
+
o ? o(write, t) : write();
|
|
165
250
|
};
|
|
166
|
-
const
|
|
167
|
-
if (!n.
|
|
251
|
+
const s = handleAsync(n, u, commit);
|
|
252
|
+
if (!n.ve) commit(s);
|
|
168
253
|
}, false);
|
|
169
254
|
return n;
|
|
170
255
|
}
|