@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.
- package/dist/dev-shared.js +2056 -3773
- package/dist/dev.attribution.js +159 -91
- package/dist/dev.js +7263 -8384
- package/dist/observe/affects.js +125 -104
- package/dist/observe/boundaries.js +458 -665
- package/dist/observe/core/action.js +63 -66
- package/dist/observe/core/async.js +240 -383
- package/dist/observe/core/attribution-queries.js +1 -1
- package/dist/observe/core/attribution.js +271 -199
- package/dist/observe/core/constants.js +115 -178
- package/dist/observe/core/context.js +3 -3
- package/dist/observe/core/core.js +840 -1428
- package/dist/observe/core/dev.js +41 -18
- package/dist/observe/core/effect.js +75 -86
- package/dist/observe/core/external.js +5 -5
- package/dist/observe/core/graph.js +61 -70
- package/dist/observe/core/heap.js +75 -98
- package/dist/observe/core/invariants.js +1 -34
- package/dist/observe/core/lanes.js +704 -181
- package/dist/observe/core/owner.js +80 -101
- package/dist/observe/core/scheduler.js +708 -1351
- package/dist/observe/core/verdict.js +302 -621
- package/dist/observe/flatten.js +79 -0
- package/dist/observe/index.js +15 -13
- package/dist/observe/map.js +232 -235
- package/dist/observe/reveal.js +212 -0
- package/dist/observe/signals.js +133 -215
- package/dist/observe/store/affects.js +135 -0
- package/dist/observe/store/index.js +29 -24
- package/dist/observe/store/optimistic.js +538 -0
- package/dist/observe/store/projection.js +302 -0
- package/dist/observe/store/reconcile.js +257 -0
- package/dist/observe/store/store.js +1945 -277
- package/dist/observe/store/storePath.js +1 -1
- package/dist/{prod/store/next → observe/store}/target.js +17 -18
- package/dist/observe/store/types.js +73 -0
- package/dist/observe/store/utils.js +1 -13
- package/dist/prod/affects.js +127 -106
- package/dist/prod/boundaries.js +442 -654
- package/dist/prod/core/action.js +71 -74
- package/dist/prod/core/async.js +307 -442
- package/dist/prod/core/constants.js +112 -177
- package/dist/prod/core/context.js +3 -3
- package/dist/prod/core/core.js +852 -1448
- package/dist/prod/core/effect.js +88 -99
- package/dist/prod/core/external.js +5 -5
- package/dist/prod/core/graph.js +61 -70
- package/dist/prod/core/heap.js +75 -98
- package/dist/prod/core/invariants.js +1 -32
- package/dist/prod/core/lanes.js +666 -181
- package/dist/prod/core/owner.js +75 -96
- package/dist/prod/core/scheduler.js +677 -1332
- package/dist/prod/core/verdict.js +297 -621
- package/dist/prod/flatten.js +77 -0
- package/dist/prod/index.js +15 -13
- package/dist/prod/map.js +143 -146
- package/dist/prod/reveal.js +212 -0
- package/dist/prod/signals.js +144 -226
- package/dist/prod/store/affects.js +135 -0
- package/dist/prod/store/index.js +28 -19
- package/dist/prod/store/optimistic.js +533 -0
- package/dist/prod/store/projection.js +295 -0
- package/dist/prod/store/reconcile.js +257 -0
- package/dist/prod/store/store.js +1840 -272
- package/dist/prod/store/storePath.js +1 -1
- package/dist/{observe/store/next → prod/store}/target.js +13 -17
- package/dist/prod/store/types.js +73 -0
- package/dist/prod/store/utils.js +1 -11
- package/dist/types/affects.d.ts +11 -30
- package/dist/types/boundaries.d.ts +62 -176
- package/dist/types/carved.d.ts +1 -0
- package/dist/types/core/action.d.ts +5 -6
- package/dist/types/core/async.d.ts +10 -5
- package/dist/types/core/attribution-hooks.d.ts +48 -1
- package/dist/types/core/attribution.d.ts +29 -9
- package/dist/types/core/constants.d.ts +125 -171
- package/dist/types/core/core.d.ts +104 -264
- package/dist/types/core/dev.d.ts +60 -7
- package/dist/types/core/effect.d.ts +0 -7
- package/dist/types/core/graph.d.ts +7 -1
- package/dist/types/core/heap.d.ts +5 -7
- package/dist/types/core/index.d.ts +6 -6
- package/dist/types/core/invariants.d.ts +0 -29
- package/dist/types/core/lanes.d.ts +65 -87
- package/dist/types/core/owner.d.ts +3 -3
- package/dist/types/core/scheduler.d.ts +249 -331
- package/dist/types/core/types.d.ts +51 -85
- package/dist/types/core/verdict.d.ts +3 -0
- package/dist/types/flatten.d.ts +8 -0
- package/dist/types/index.d.ts +7 -5
- package/dist/types/reveal.d.ts +19 -0
- package/dist/types/signals.d.ts +53 -92
- package/dist/types/store/affects.d.ts +1 -0
- package/dist/types/store/index.d.ts +35 -15
- package/dist/types/store/optimistic.d.ts +23 -0
- package/dist/types/store/projection.d.ts +18 -0
- package/dist/types/store/reconcile.d.ts +3 -0
- package/dist/types/store/store.d.ts +165 -143
- package/dist/types/store/storePath.d.ts +1 -1
- package/dist/types/store/target.d.ts +151 -0
- package/dist/types/store/types.d.ts +84 -0
- package/package.json +1 -1
- package/dist/observe/core/optimistic.js +0 -669
- package/dist/observe/store/next/optimistic.js +0 -717
- package/dist/observe/store/next/projection.js +0 -266
- package/dist/observe/store/next/reconcile.js +0 -375
- package/dist/observe/store/next/store.js +0 -2480
- package/dist/prod/core/optimistic.js +0 -658
- package/dist/prod/store/next/optimistic.js +0 -710
- package/dist/prod/store/next/projection.js +0 -257
- package/dist/prod/store/next/reconcile.js +0 -373
- package/dist/prod/store/next/store.js +0 -2356
- package/dist/types/core/optimistic.d.ts +0 -6
- package/dist/types/store/next/optimistic.d.ts +0 -25
- package/dist/types/store/next/projection.d.ts +0 -27
- package/dist/types/store/next/reconcile.d.ts +0 -10
- package/dist/types/store/next/store.d.ts +0 -143
- package/dist/types/store/next/target.d.ts +0 -196
package/dist/observe/signals.js
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
import { TimeoutError } from "./core/error.js";
|
|
1
|
+
import { NotReadyError, unwrapStatusError, TimeoutError } from "./core/error.js";
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
import { cleanup, createRoot, getOwner, dispose, getObserver } from "./core/owner.js";
|
|
6
|
-
|
|
7
|
-
import { globalQueue, dirtyQueue, Queue, entangleConfirmingTransitions, activeTransition } from "./core/scheduler.js";
|
|
3
|
+
import "./core/verdict.js";
|
|
8
4
|
|
|
9
|
-
import {
|
|
5
|
+
import { CONFIG_CHILDREN_FORBIDDEN, EFFECT_USER, $REFRESH, CONFIG_REDERIVE, REACTIVE_JOINED, CONFIG_AUTO_DISPOSE, CONFIG_FRESH_READ, CONFIG_AUTHORITATIVE } from "./core/constants.js";
|
|
10
6
|
|
|
11
|
-
import "./core/
|
|
7
|
+
import { computed, signal, runWithOwner, setMemo, setSignal, markRefresh, read, untrack } from "./core/core.js";
|
|
12
8
|
|
|
13
9
|
import { registerGraph } from "./core/dev.js";
|
|
14
10
|
|
|
15
|
-
import "./core/
|
|
11
|
+
import { globalQueue, flushTransaction, resolveTx, passTx, staleReader, dirtyQueue, joinFuture } from "./core/scheduler.js";
|
|
12
|
+
|
|
13
|
+
import { cleanup, createRoot, getOwner, dispose } from "./core/owner.js";
|
|
16
14
|
|
|
17
15
|
import { effect, trackedEffect } from "./core/effect.js";
|
|
18
16
|
|
|
19
|
-
import {
|
|
17
|
+
import { optimisticWrite } from "./core/lanes.js";
|
|
20
18
|
|
|
21
19
|
/**
|
|
22
20
|
* Low-level reactive-cleanup primitive. Registers a callback that runs when
|
|
@@ -75,7 +73,7 @@ function accessor(e) {
|
|
|
75
73
|
function createSignal(e, t) {
|
|
76
74
|
if (typeof e === "function") {
|
|
77
75
|
const r = computed(e, t);
|
|
78
|
-
r.
|
|
76
|
+
r.u &= ~CONFIG_AUTO_DISPOSE;
|
|
79
77
|
return [ accessor(r), setMemo.bind(null, r) ];
|
|
80
78
|
}
|
|
81
79
|
const r = signal(e, t);
|
|
@@ -83,6 +81,17 @@ function createSignal(e, t) {
|
|
|
83
81
|
return [ accessor(r), setSignal.bind(null, r) ];
|
|
84
82
|
}
|
|
85
83
|
|
|
84
|
+
function createOptimistic(e, t) {
|
|
85
|
+
if (typeof e === "function") {
|
|
86
|
+
const r = computed(e, t);
|
|
87
|
+
r.u &= ~CONFIG_AUTO_DISPOSE;
|
|
88
|
+
return [ accessor(r), optimisticWrite.bind(null, r) ];
|
|
89
|
+
}
|
|
90
|
+
const r = signal(e, t);
|
|
91
|
+
registerGraph(r, getOwner());
|
|
92
|
+
return [ accessor(r), optimisticWrite.bind(null, r) ];
|
|
93
|
+
}
|
|
94
|
+
|
|
86
95
|
function createMemo(e, t) {
|
|
87
96
|
return accessor(computed(e, t));
|
|
88
97
|
}
|
|
@@ -275,15 +284,15 @@ function createMemo(e, t) {
|
|
|
275
284
|
// sources stayed live (firing the callback for replaced dependencies), each
|
|
276
285
|
// accumulated arm delivered its own fire, and un-fired arms leaked as live
|
|
277
286
|
// effect nodes until the owner disposed (#2861).
|
|
278
|
-
let
|
|
279
|
-
return
|
|
280
|
-
if (
|
|
281
|
-
dispose(
|
|
282
|
-
|
|
287
|
+
let o;
|
|
288
|
+
return c => {
|
|
289
|
+
if (o) {
|
|
290
|
+
dispose(o);
|
|
291
|
+
o = undefined;
|
|
283
292
|
}
|
|
284
293
|
runWithOwner(n, () => {
|
|
285
|
-
effect(() => (
|
|
286
|
-
|
|
294
|
+
effect(() => (c(), o = getOwner()), t => {
|
|
295
|
+
o = undefined;
|
|
287
296
|
r?.();
|
|
288
297
|
const n = (e.effect || e)?.();
|
|
289
298
|
if (false && n !== undefined && typeof n !== "function") ;
|
|
@@ -298,10 +307,48 @@ function createMemo(e, t) {
|
|
|
298
307
|
};
|
|
299
308
|
}
|
|
300
309
|
|
|
301
|
-
/**
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
310
|
+
/** A promise over a reactive expression (`resolve`, `until`): a pass that
|
|
311
|
+
* runs the expression and settles on a microtask. Not an effect — an
|
|
312
|
+
* effect's run is the flush's effect phase, and a flush parked by the
|
|
313
|
+
* action that is `yield`ing on this promise stashes its runs with the
|
|
314
|
+
* transaction (#2930); the heap runs a pass parked or not. A pending read
|
|
315
|
+
* re-runs it when the source lands (the pass is pending itself); the
|
|
316
|
+
* expression throwing settles the rejection. */
|
|
317
|
+
/** The promise-delivery readers' pass (`resolve`, `until`, `refresh`'s
|
|
318
|
+
* waiter): delivers what it read on a microtask. By posture (#3482, #3490):
|
|
319
|
+
* - the reader of the transaction it was created in (`own`: an action's
|
|
320
|
+
* body, a `refresh()` called there — the waiter reads its slice's frame on
|
|
321
|
+
* a later microtask) delivers that frame — the staged landing an action
|
|
322
|
+
* holds (the action awaits the promise that would otherwise wait on its
|
|
323
|
+
* own settle);
|
|
324
|
+
* - a mainline reader whose pass read a frame another transaction holds
|
|
325
|
+
* joined it (L2, born held — A29) and delivers at that commit: the
|
|
326
|
+
* committed view, never a foreign hold's unrevealed frame. */ function watch(e, t, r, n = 0, o, c = flushTransaction) {
|
|
327
|
+
// `config` is on the node for its first pass too (the pass runs inside
|
|
328
|
+
// `computed()`): `until`'s predicate is authoritative from its first read,
|
|
329
|
+
// or an already-displayed guess would satisfy it in a later slice. (REDERIVE
|
|
330
|
+
// after: the first pass's own error is the promise's rejection.)
|
|
331
|
+
computed(() => {
|
|
332
|
+
let n;
|
|
333
|
+
try {
|
|
334
|
+
n = e();
|
|
335
|
+
} catch (e) {
|
|
336
|
+
if (e instanceof NotReadyError) throw e;
|
|
337
|
+
queueMicrotask(() => r(unwrapStatusError(e)));
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
const i = getOwner();
|
|
341
|
+
// (Outside a flush a mainline pass joins through `passTx`.)
|
|
342
|
+
const u = flushTransaction ?? passTx;
|
|
343
|
+
if (i.R & REACTIVE_JOINED && u !== null && (c === null || resolveTx(c) !== resolveTx(u))) {
|
|
344
|
+
staleReader(i, resolveTx(u));
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
o?.(n);
|
|
348
|
+
queueMicrotask(() => t(n));
|
|
349
|
+
}, {
|
|
350
|
+
dt: n
|
|
351
|
+
}).u |= CONFIG_REDERIVE;
|
|
305
352
|
}
|
|
306
353
|
|
|
307
354
|
/**
|
|
@@ -326,41 +373,7 @@ function createMemo(e, t) {
|
|
|
326
373
|
* @param fn a reactive expression to resolve
|
|
327
374
|
*/ function resolve(e) {
|
|
328
375
|
return new Promise((t, r) => {
|
|
329
|
-
createRoot(n =>
|
|
330
|
-
// Deliver effect applies on a microtask instead of the owner queue: an
|
|
331
|
-
// incomplete transition stashes its effect queues until it settles, but
|
|
332
|
-
// an action yielding this promise is itself what keeps the transition
|
|
333
|
-
// open — the stashed res() deadlocked the action (#2930). The compute
|
|
334
|
-
// still runs in place (under the transaction's view when created inside
|
|
335
|
-
// an action step), and status/boundary notifications keep their normal
|
|
336
|
-
// route through the inherited queue.
|
|
337
|
-
const i = getOwner();
|
|
338
|
-
const o = new MicrotaskQueue;
|
|
339
|
-
o._parent = i.T;
|
|
340
|
-
// notify() forwards up the normal chain
|
|
341
|
-
i.T = o;
|
|
342
|
-
// A user effect rather than a bare computed: computeds are pull-based and
|
|
343
|
-
// are only re-enqueued when a pending source *resolves* — a rejection just
|
|
344
|
-
// marks them errored, so nothing would re-run and the promise would never
|
|
345
|
-
// settle (#2842). The effect's error channel is notified on rejection.
|
|
346
|
-
effect(e, e => {
|
|
347
|
-
t(e);
|
|
348
|
-
n();
|
|
349
|
-
}, e => {
|
|
350
|
-
// The error arm already unwraps StatusError (#2840) — `err` is the
|
|
351
|
-
// user's original error, matching what error boundaries expose.
|
|
352
|
-
r(e);
|
|
353
|
-
n();
|
|
354
|
-
},
|
|
355
|
-
// DIRECT_COMMIT: a source settling INTO the held transaction (e.g. a
|
|
356
|
-
// refresh this action issued) stages its landing; the effect's own
|
|
357
|
-
// recompute must not stage too, or the microtask apply reads the
|
|
358
|
-
// stale mainline value and resolves with old data.
|
|
359
|
-
{
|
|
360
|
-
user: true,
|
|
361
|
-
Qt: CONFIG_DIRECT_COMMIT
|
|
362
|
-
});
|
|
363
|
-
});
|
|
376
|
+
createRoot(n => watch(e, e => (t(e), n()), e => (r(e), n())));
|
|
364
377
|
});
|
|
365
378
|
}
|
|
366
379
|
|
|
@@ -380,19 +393,10 @@ function createMemo(e, t) {
|
|
|
380
393
|
* read:
|
|
381
394
|
* - Accessor targets resolve with the settled value; store targets resolve
|
|
382
395
|
* with the store node passed (reads through it are fresh after the await).
|
|
383
|
-
* - A failed re-ask rejects with the error
|
|
384
|
-
* `yield refresh(x)` throws back at the yield point and the action reverts
|
|
385
|
-
* like any other failure).
|
|
396
|
+
* - A failed re-ask rejects with the error.
|
|
386
397
|
* - Semantics are quiescence, not flight identity: if another refresh (or
|
|
387
398
|
* any invalidation) supersedes this one mid-flight, the promise waits for
|
|
388
399
|
* — and delivers — whatever finally lands.
|
|
389
|
-
* - Inside an action, truth landing into the held transaction is STAGED;
|
|
390
|
-
* the promise still settles then (matching `resolve()`/`until()`, #2930)
|
|
391
|
-
* and delivers the staged value — the caller's own optimistic override is
|
|
392
|
-
* never the delivered value.
|
|
393
|
-
* - The re-ask itself stays verdict-quiet exactly as before: `isPending`
|
|
394
|
-
* does not flip for a bare refresh (pair with `affects()` for a visible
|
|
395
|
-
* pending window).
|
|
396
400
|
*
|
|
397
401
|
* @example
|
|
398
402
|
* ```ts
|
|
@@ -419,59 +423,40 @@ function createMemo(e, t) {
|
|
|
419
423
|
// no-ops, so N waiters cost one pull; this also closes the race where a
|
|
420
424
|
// waiter reads the PRE-re-ask value as settled and delivers stale), after
|
|
421
425
|
// which the read either parks on the re-ask's pending window (async — the
|
|
422
|
-
// settle walk re-runs it on every landing, equal-value and
|
|
423
|
-
//
|
|
424
|
-
//
|
|
425
|
-
//
|
|
426
|
-
//
|
|
427
|
-
|
|
428
|
-
//
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
// that reader bit must install it — until() does, and this waiter is the
|
|
433
|
-
// other one (#3303: refresh of an optimistic in an app that never called
|
|
434
|
-
// until() dereferenced the null hook).
|
|
435
|
-
installAuthoritativeRead();
|
|
436
|
-
markRefresh(t);
|
|
437
|
-
const r = new Promise((r, n) => {
|
|
426
|
+
// settle walk re-runs it on every landing, equal-value included, and a
|
|
427
|
+
// rejection arrives through the effect's error channel) or serves the sync
|
|
428
|
+
// answer. resolve()'s own eager compute is untouched: created after a
|
|
429
|
+
// refresh it still settles stale-while-revalidate (#2930) — its contract is
|
|
430
|
+
// "first settled value", not "next quiescent state".
|
|
431
|
+
markRefresh(t);
|
|
432
|
+
// The transaction `refresh()` is called in (an action's slice): the
|
|
433
|
+
// waiter, created on the microtask below, is its reader (`watch`).
|
|
434
|
+
const r = flushTransaction;
|
|
435
|
+
const n = new Promise((n, o) => {
|
|
438
436
|
queueMicrotask(() => {
|
|
439
|
-
// No createRoot: the microtask has no ambient owner, so the
|
|
440
|
-
// naturally detached, and settle disposes the node directly
|
|
441
|
-
//
|
|
442
|
-
//
|
|
443
|
-
//
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
// effect's own compute, where the ambient owner IS the effect —
|
|
448
|
-
// exactly what dispose() takes.
|
|
449
|
-
let i = null;
|
|
450
|
-
const make = () => effect(() => {
|
|
451
|
-
if (i === null) {
|
|
452
|
-
i = getOwner();
|
|
453
|
-
const e = new MicrotaskQueue;
|
|
454
|
-
e._parent = i.T;
|
|
455
|
-
i.T = e;
|
|
456
|
-
}
|
|
437
|
+
// No createRoot: the microtask has no ambient owner, so the watcher is
|
|
438
|
+
// naturally detached, and settle disposes the node directly (dev keeps
|
|
439
|
+
// a root husk purely to stay quiet about the missing owner). The
|
|
440
|
+
// capture runs inside the watcher's own pass, where the ambient owner
|
|
441
|
+
// IS the watcher — exactly what dispose() takes.
|
|
442
|
+
let c = null;
|
|
443
|
+
const make = () => watch(() => {
|
|
444
|
+
if (c === null) c = getOwner();
|
|
457
445
|
return read(t);
|
|
458
446
|
}, t => {
|
|
459
|
-
|
|
460
|
-
dispose(
|
|
447
|
+
n(typeof e === "function" ? t : e);
|
|
448
|
+
dispose(c);
|
|
461
449
|
}, e => {
|
|
462
|
-
|
|
463
|
-
dispose(
|
|
464
|
-
},
|
|
465
|
-
user: true,
|
|
466
|
-
Qt: CONFIG_DIRECT_COMMIT | CONFIG_AUTHORITATIVE_READ | CONFIG_FRESH_READ
|
|
467
|
-
});
|
|
450
|
+
o(e);
|
|
451
|
+
dispose(c);
|
|
452
|
+
}, CONFIG_FRESH_READ, undefined, r);
|
|
468
453
|
make();
|
|
469
454
|
});
|
|
470
455
|
});
|
|
471
456
|
// Fire-and-forget refresh must not turn a failed refetch into an unhandled
|
|
472
457
|
// rejection; awaiting callers attach their own handlers to `promise`.
|
|
473
|
-
|
|
474
|
-
return
|
|
458
|
+
n.catch(() => {});
|
|
459
|
+
return n;
|
|
475
460
|
}
|
|
476
461
|
|
|
477
462
|
/**
|
|
@@ -483,115 +468,63 @@ function createMemo(e, t) {
|
|
|
483
468
|
*
|
|
484
469
|
* Where {@link resolve} answers "what is this value" (first settled value,
|
|
485
470
|
* whatever it is), `until` answers "when does the world confirm this
|
|
486
|
-
* condition".
|
|
487
|
-
* holds the action's transaction — and any optimistic state riding it — open
|
|
488
|
-
* until the condition is independently true.
|
|
489
|
-
*
|
|
490
|
-
* To make that sound, `until`'s predicate reads the AUTHORITATIVE view — and
|
|
491
|
-
* this is the one read-semantics difference from `resolve`, which reads the
|
|
492
|
-
* normal (transaction's own) view where overrides are visible:
|
|
493
|
-
*
|
|
494
|
-
* - **Optimistic overrides are invisible** to the predicate. Your own
|
|
495
|
-
* tentative write can never satisfy your own ack, even on the
|
|
496
|
-
* single-primitive shape where the optimistic store IS the live-fed store.
|
|
497
|
-
* (Derived computeds serve their normal cached values — express the
|
|
498
|
-
* condition over sources of truth, not derived views of the overlay.)
|
|
499
|
-
* - **Everything else reads normally, including uncommitted transition-staged
|
|
500
|
-
* data.** Real data is real wherever it currently lives. This is
|
|
501
|
-
* load-bearing, not a loophole: truth that arrives *into* the open
|
|
502
|
-
* transaction (a `refresh()` this action issued, an entangled landing)
|
|
503
|
-
* stages and cannot commit until the hold releases — a predicate that
|
|
504
|
-
* refused staged reads would deadlock on the very data it is waiting for.
|
|
471
|
+
* condition".
|
|
505
472
|
*
|
|
506
473
|
* This is the acknowledgment mechanism for mutations confirmed on a live data
|
|
507
474
|
* channel (sockets, subscriptions, live queries) rather than by the mutation's
|
|
508
475
|
* own response: correlate by a client-generated id or version in the predicate,
|
|
509
476
|
* and let truth arrive however it arrives — push, refetch, or another tab.
|
|
510
477
|
*
|
|
511
|
-
* Failure composes with action semantics: a rejection is thrown back into the
|
|
512
|
-
* generator at the `yield` point — catchable there, or the action fails and
|
|
513
|
-
* its optimistic state reverts.
|
|
514
|
-
*
|
|
515
478
|
* Must be called *outside* a tracking scope.
|
|
516
479
|
*
|
|
517
|
-
* Inside an action, call it from a step: after an `await`, put a bare `yield`
|
|
518
|
-
* before `yield until(...)`. The runtime cannot hook an async generator's
|
|
519
|
-
* `await` continuation, so the `until(...)` expression — which CREATES the
|
|
520
|
-
* predicate's reader — would otherwise run outside the transaction; created
|
|
521
|
-
* there it is born held (A29) and replays only at the commit its own promise
|
|
522
|
-
* holds open (#3482). See {@link action}.
|
|
523
|
-
*
|
|
524
480
|
* @example
|
|
525
481
|
* ```ts
|
|
526
|
-
* const
|
|
527
|
-
*
|
|
528
|
-
*
|
|
529
|
-
*
|
|
530
|
-
* yield; // re-enter the transaction after the await
|
|
531
|
-
* // Hold until the live source echoes the write (authoritative view —
|
|
532
|
-
* // the optimistic row above cannot satisfy this):
|
|
533
|
-
* yield until(() => messages.some(m => m.clientId === clientId), { timeout: 10_000 });
|
|
534
|
-
* });
|
|
482
|
+
* const clientId = crypto.randomUUID();
|
|
483
|
+
* await socket.send({ clientId, text }); // fire-and-forget transport
|
|
484
|
+
* // Wait until the live source echoes the write:
|
|
485
|
+
* await until(() => messages.some(m => m.clientId === clientId), { timeout: 10_000 });
|
|
535
486
|
* ```
|
|
536
487
|
*
|
|
537
|
-
* @param fn a reactive predicate
|
|
488
|
+
* @param fn a reactive predicate
|
|
538
489
|
* @param options optional `timeout` (ms) and abort `signal`
|
|
539
490
|
*/ function until(e, t) {
|
|
540
|
-
|
|
541
|
-
// apps that never call until() never retain it).
|
|
542
|
-
installAuthoritativeRead();
|
|
543
|
-
// Flip-entanglement (#3164 follow-up): the transaction this until() holds
|
|
544
|
-
// open (the action's, when yielded from one). The predicate is the user's
|
|
545
|
-
// declaration of what confirms it — when a foreign transition's staged
|
|
546
|
-
// write flips it truthy, that transition merges here and reveals at the
|
|
547
|
-
// joint settle instead of painting the confirmation under live optimism.
|
|
548
|
-
const r = activeTransition;
|
|
549
|
-
return new Promise((n, i) => {
|
|
491
|
+
return new Promise((r, n) => {
|
|
550
492
|
const o = t?.signal;
|
|
551
|
-
if (o?.aborted) return
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
let
|
|
562
|
-
let
|
|
493
|
+
if (o?.aborted) return n(o.reason);
|
|
494
|
+
// The awaiting action's transaction, if any (its body runs joined to
|
|
495
|
+
// it). `until()` is a declaration of relatedness (#3164 follow-up): the
|
|
496
|
+
// predicate names the condition that confirms the action, so the frame
|
|
497
|
+
// whose landing flips it truthy is the confirming event by the user's
|
|
498
|
+
// own definition — it reveals WITH the action's settle, not before
|
|
499
|
+
// (`saving=true` beside the confirmed `version=1` is a tear no timeline
|
|
500
|
+
// contains). Updates that do not flip the predicate reveal freely.
|
|
501
|
+
const c = flushTransaction;
|
|
502
|
+
createRoot(i => {
|
|
503
|
+
let u;
|
|
504
|
+
let s;
|
|
563
505
|
const settle = e => {
|
|
564
|
-
if (
|
|
565
|
-
if (
|
|
506
|
+
if (u !== undefined) clearTimeout(u);
|
|
507
|
+
if (s !== undefined) o.removeEventListener("abort", s);
|
|
566
508
|
e();
|
|
567
|
-
|
|
509
|
+
i();
|
|
568
510
|
};
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
// the merge lands before any reveal. Falsy evaluations skip —
|
|
574
|
-
// non-flipping updates were never named as the confirmation.
|
|
575
|
-
if (t) entangleConfirmingTransitions(getObserver(), r);
|
|
576
|
-
return t;
|
|
577
|
-
}, e => {
|
|
511
|
+
// Authoritative: the predicate sees the truth, never the action's own
|
|
512
|
+
// optimistic guess — a guess cannot satisfy the wait for its own
|
|
513
|
+
// confirmation.
|
|
514
|
+
watch(e, e => {
|
|
578
515
|
// Falsy is "not yet": keep the subscription live and wait for the
|
|
579
516
|
// next evaluation. Only a truthy settled value resolves.
|
|
580
|
-
if (e) settle(() =>
|
|
581
|
-
}, e => settle(() =>
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
// the hold itself is keeping uncommitted.
|
|
587
|
-
{
|
|
588
|
-
user: true,
|
|
589
|
-
Qt: CONFIG_AUTHORITATIVE_READ | CONFIG_DIRECT_COMMIT
|
|
517
|
+
if (e) settle(() => r(e));
|
|
518
|
+
}, e => settle(() => n(e)), CONFIG_AUTHORITATIVE, e => {
|
|
519
|
+
// The flip, inside the pass of the flush carrying it: the flush
|
|
520
|
+
// joins the action's transaction, and what it staged is held and
|
|
521
|
+
// revealed with the action.
|
|
522
|
+
if (e && c !== null && globalQueue.ee && resolveTx(c).tt !== 0) joinFuture(c);
|
|
590
523
|
});
|
|
591
|
-
if (t?.timeout !== undefined)
|
|
524
|
+
if (t?.timeout !== undefined) u = setTimeout(() => settle(() => n(new TimeoutError)), t.timeout);
|
|
592
525
|
if (o !== undefined) {
|
|
593
|
-
|
|
594
|
-
o.addEventListener("abort",
|
|
526
|
+
s = () => settle(() => n(o.reason));
|
|
527
|
+
o.addEventListener("abort", s, {
|
|
595
528
|
once: true
|
|
596
529
|
});
|
|
597
530
|
}
|
|
@@ -599,21 +532,6 @@ function createMemo(e, t) {
|
|
|
599
532
|
});
|
|
600
533
|
}
|
|
601
534
|
|
|
602
|
-
function createOptimistic(e, t) {
|
|
603
|
-
// Install before the node exists: only engine-installed programs can carry
|
|
604
|
-
// an _overrideValue slot (same runtime-install pattern as
|
|
605
|
-
// GlobalQueue._clearOptimisticStore in createOptimisticStore).
|
|
606
|
-
installOptimisticEngine();
|
|
607
|
-
if (typeof e === "function") {
|
|
608
|
-
const r = optimisticComputed(e, t);
|
|
609
|
-
r.C &= ~CONFIG_AUTO_DISPOSE;
|
|
610
|
-
return [ accessor(r), setSignal.bind(null, r) ];
|
|
611
|
-
}
|
|
612
|
-
const r = optimisticSignal(e, t);
|
|
613
|
-
registerGraph(r, getOwner());
|
|
614
|
-
return [ accessor(r), setSignal.bind(null, r) ];
|
|
615
|
-
}
|
|
616
|
-
|
|
617
535
|
/**
|
|
618
536
|
* Schedules `callback` to run **once** after the reactive graph has fully
|
|
619
537
|
* settled — i.e. once every pending async read inside the current owner has
|
|
@@ -709,7 +627,7 @@ function createOptimistic(e, t) {
|
|
|
709
627
|
* on owner disposal
|
|
710
628
|
*/ function onSettled(e) {
|
|
711
629
|
const t = getOwner();
|
|
712
|
-
t && !(t.
|
|
630
|
+
t && !(t.u & CONFIG_CHILDREN_FORBIDDEN) ? trackedEffect(() => untrack(e), {
|
|
713
631
|
name: "onSettled"
|
|
714
632
|
}) : globalQueue.enqueue(EFFECT_USER, function fire() {
|
|
715
633
|
// Settled means derived. A settle that reverts optimism (or replays
|
|
@@ -719,7 +637,7 @@ function createOptimistic(e, t) {
|
|
|
719
637
|
// still holding the optimistic value — reads do not pull (#3411). Fall
|
|
720
638
|
// to the next pass while the heap has work; `run` swapped the queue,
|
|
721
639
|
// so this lands there, and `enqueue` keeps the drain alive.
|
|
722
|
-
if (dirtyQueue.
|
|
640
|
+
if (dirtyQueue.Kt >= dirtyQueue.ut) return globalQueue.enqueue(EFFECT_USER, fire);
|
|
723
641
|
// Unowned, out-of-band fire (no owner, or a children-forbidden one this
|
|
724
642
|
// one-shot must not bind to): a returned cleanup has no lifecycle to
|
|
725
643
|
// attach to. Reject it in dev; in production the return is simply
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { GlobalQueue } from "../core/scheduler.js";
|
|
2
|
+
|
|
3
|
+
import { installAffectsHooks, getNode, optHooks } from "./store.js";
|
|
4
|
+
|
|
5
|
+
import { lookupTarget, $OWNER } from "./target.js";
|
|
6
|
+
|
|
7
|
+
import { isWrappable, $TARGET } from "./types.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Store — the store half of `affects()` (plan sec. 29, plan sec. 37; A24 (4), #2882,
|
|
11
|
+
* #2893, #2904).
|
|
12
|
+
*
|
|
13
|
+
* A mark on a store is a mark on nodes (affects.ts: a count on the node, a
|
|
14
|
+
* dependency walk at probe time): `affects(record, key)` marks the slot's
|
|
15
|
+
* leaf; `affects(record)` marks a carrier (the record's `$AFFECTS` leaf)
|
|
16
|
+
* and every live node in the record's subtree — the edges existing readers
|
|
17
|
+
* subscribed through. Coverage is by RAW IDENTITY, not read path (#2882: a
|
|
18
|
+
* captured row proxy, a derived store sharing the source's raw, never read
|
|
19
|
+
* through the declaration's proxy): the identities reachable at the
|
|
20
|
+
* declaration are the mark's `scope`, so a node born inside the window on
|
|
21
|
+
* a covered record inherits the mark (released with the carrier's last),
|
|
22
|
+
* and an untracked probe through a record with no nodes is witnessed into
|
|
23
|
+
* the verdict. A mark declared on a draft (inside a setter) or over an
|
|
24
|
+
* optimistic family walks the view the writer sees.
|
|
25
|
+
*
|
|
26
|
+
* Installed by `store/index.ts`: a program with stores carries it; one
|
|
27
|
+
* without pays nothing (affects.ts asks `GlobalQueue._storeMarks`).
|
|
28
|
+
*/
|
|
29
|
+
/** The keyless mark's carrier key: a leaf of the record no read serves. */ const $AFFECTS = Symbol(0);
|
|
30
|
+
|
|
31
|
+
const scopes = new Map;
|
|
32
|
+
|
|
33
|
+
/** The nodes an `affects(store[, key])` declaration marks (affects.ts
|
|
34
|
+
* registers each). */ function storeMarks(e, n) {
|
|
35
|
+
if (n === undefined) {
|
|
36
|
+
const n = getNode(e, $AFFECTS);
|
|
37
|
+
let o = scopes.get(n);
|
|
38
|
+
if (o === undefined) scopes.set(n, o = {
|
|
39
|
+
scope: new Set,
|
|
40
|
+
inherited: []
|
|
41
|
+
});
|
|
42
|
+
const t = [ n ];
|
|
43
|
+
walk(e.px, o, t, e.fam, new Set);
|
|
44
|
+
return t;
|
|
45
|
+
}
|
|
46
|
+
const o = e.n?.[n] ?? getNode(e, n);
|
|
47
|
+
let t = scopes.get(o);
|
|
48
|
+
if (t === undefined) scopes.set(o, t = {
|
|
49
|
+
scope: new Set,
|
|
50
|
+
inherited: [],
|
|
51
|
+
key: n
|
|
52
|
+
});
|
|
53
|
+
t.scope.add(e.v);
|
|
54
|
+
if (e.pb !== null) t.scope.add(e.pb);
|
|
55
|
+
return [ o ];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The identities reachable from `value` into the scope (the draft's and
|
|
59
|
+
* the committed backing both, when a draft is open; an optimistic family's
|
|
60
|
+
* view), every live node under each record into `found`. Untracked by
|
|
61
|
+
* construction: raws, never traps. */ function walk(e, n, o, t, s) {
|
|
62
|
+
if (!isWrappable(e)) return;
|
|
63
|
+
const f = e[$TARGET] ?? lookupTarget(e, t);
|
|
64
|
+
let i = f !== undefined ? f.pb ?? f.v : e;
|
|
65
|
+
if (s.has(i)) return;
|
|
66
|
+
s.add(i);
|
|
67
|
+
n.scope.add(i);
|
|
68
|
+
if (f !== undefined) {
|
|
69
|
+
if (f.pb !== null) n.scope.add(f.v);
|
|
70
|
+
// The writer's view: the tick's own unflushed guesses are in motion too.
|
|
71
|
+
if (f.fam?.opt === true) i = optHooks.view(f, i, true);
|
|
72
|
+
const e = f.n;
|
|
73
|
+
if (e !== null) for (const n of Reflect.ownKeys(e))
|
|
74
|
+
// Another mark's carrier is its own channel: counting it here would
|
|
75
|
+
// extend that scope's lifetime to this declaration's.
|
|
76
|
+
if (n !== $AFFECTS) o.push(e[n]);
|
|
77
|
+
const s = f.h;
|
|
78
|
+
if (s !== null) for (const e of Reflect.ownKeys(s)) o.push(s[e]);
|
|
79
|
+
if (f.k !== null) o.push(f.k);
|
|
80
|
+
if (f.dk !== null) o.push(f.dk);
|
|
81
|
+
t = f.fam ?? t;
|
|
82
|
+
}
|
|
83
|
+
for (const e of Reflect.ownKeys(i)) {
|
|
84
|
+
if (e === $OWNER) continue;
|
|
85
|
+
const f = Object.getOwnPropertyDescriptor(i, e);
|
|
86
|
+
if (f === undefined || f.get !== undefined) continue;
|
|
87
|
+
walk(f.value, n, o, t, s);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** A live scope covering `t`'s identity (keyed: for `key`). Chained
|
|
92
|
+
* backings (§7b): a view's backing is another store's proxy — marks cover
|
|
93
|
+
* the BASE raw, so every identity along the chain is checked. */ function covering(e, n, o) {
|
|
94
|
+
for (const [t, s] of scopes) {
|
|
95
|
+
if (t === o || s.key !== undefined && s.key !== n) continue;
|
|
96
|
+
for (let n = e.v; ;) {
|
|
97
|
+
if (s.scope.has(n)) return t;
|
|
98
|
+
const e = n?.[$TARGET];
|
|
99
|
+
if (e === undefined) break;
|
|
100
|
+
const o = e.pb ?? e.v;
|
|
101
|
+
if (o === n) break;
|
|
102
|
+
n = o;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
installAffectsHooks({
|
|
109
|
+
// A node born on a record a live mark covers inherits it (released with
|
|
110
|
+
// the carrier's last registration).
|
|
111
|
+
born(e, n, o) {
|
|
112
|
+
if (o === $AFFECTS) return;
|
|
113
|
+
const t = covering(e, o, n);
|
|
114
|
+
if (t === null) return;
|
|
115
|
+
GlobalQueue.h(n);
|
|
116
|
+
scopes.get(t).inherited.push(n);
|
|
117
|
+
},
|
|
118
|
+
// An untracked probe (`isPending(() => s.x)` with no observer) reading a
|
|
119
|
+
// record a live mark covers: no node carries the mark for it — the
|
|
120
|
+
// verdict is told directly.
|
|
121
|
+
witness(e, n) {
|
|
122
|
+
const o = e.n?.[$AFFECTS];
|
|
123
|
+
if (o !== undefined && o.m !== null && o.m.T !== 0 || covering(e, n) !== null) GlobalQueue.Bt();
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
GlobalQueue.O = storeMarks;
|
|
128
|
+
|
|
129
|
+
/** The carrier's last mark released (affects.ts): its scope dies, and the
|
|
130
|
+
* nodes that inherited the mark release theirs. */ GlobalQueue.N = e => {
|
|
131
|
+
const n = scopes.get(e);
|
|
132
|
+
if (n === undefined) return;
|
|
133
|
+
scopes.delete(e);
|
|
134
|
+
GlobalQueue.A(n.inherited);
|
|
135
|
+
};
|