@wardic/core 1.3.1 → 1.3.2
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/BaseValue.d.ts +1 -1
- package/dist/BaseValue.js +2 -2
- package/dist/BaseValue.js.map +1 -1
- package/dist/Batch.d.ts +5 -9
- package/dist/Batch.d.ts.map +1 -1
- package/dist/Batch.js +166 -20
- package/dist/Batch.js.map +1 -1
- package/dist/Clock.d.ts +16 -0
- package/dist/Clock.d.ts.map +1 -1
- package/dist/Clock.js +13 -0
- package/dist/Clock.js.map +1 -1
- package/dist/DragRecognizer.d.ts +10 -5
- package/dist/DragRecognizer.d.ts.map +1 -1
- package/dist/DragRecognizer.js +60 -24
- package/dist/DragRecognizer.js.map +1 -1
- package/dist/Frame.js +1 -1
- package/dist/Frame.js.map +1 -1
- package/dist/InputFeed.d.ts +10 -7
- package/dist/InputFeed.d.ts.map +1 -1
- package/dist/InputFeed.js +16 -35
- package/dist/InputFeed.js.map +1 -1
- package/dist/LiveValue.d.ts +9 -3
- package/dist/LiveValue.d.ts.map +1 -1
- package/dist/LiveValue.js +160 -14
- package/dist/LiveValue.js.map +1 -1
- package/dist/Machine.d.ts +16 -6
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +50 -27
- package/dist/Machine.js.map +1 -1
- package/dist/Playback.d.ts.map +1 -1
- package/dist/Playback.js +10 -8
- package/dist/Playback.js.map +1 -1
- package/dist/Recognizer.d.ts +1 -1
- package/dist/Recognizer.d.ts.map +1 -1
- package/dist/Recognizer.js +9 -4
- package/dist/Recognizer.js.map +1 -1
- package/dist/internal/frameLoop.d.ts +10 -2
- package/dist/internal/frameLoop.d.ts.map +1 -1
- package/dist/internal/frameLoop.js +148 -18
- package/dist/internal/frameLoop.js.map +1 -1
- package/dist/internal/guarded.d.ts +16 -0
- package/dist/internal/guarded.d.ts.map +1 -0
- package/dist/internal/guarded.js +68 -0
- package/dist/internal/guarded.js.map +1 -0
- package/dist/internal/stepper.d.ts +9 -3
- package/dist/internal/stepper.d.ts.map +1 -1
- package/dist/internal/stepper.js +5 -4
- package/dist/internal/stepper.js.map +1 -1
- package/dist/unstable/AnimationControls.d.ts +15 -8
- package/dist/unstable/AnimationControls.d.ts.map +1 -1
- package/dist/unstable/AnimationControls.js +36 -15
- package/dist/unstable/AnimationControls.js.map +1 -1
- package/dist/unstable/AppearHandoff.d.ts +6 -0
- package/dist/unstable/AppearHandoff.d.ts.map +1 -1
- package/dist/unstable/AppearHandoff.js.map +1 -1
- package/dist/unstable/Config.d.ts +5 -1
- package/dist/unstable/Config.d.ts.map +1 -1
- package/dist/unstable/Config.js.map +1 -1
- package/dist/unstable/FlushGate.d.ts +4 -2
- package/dist/unstable/FlushGate.d.ts.map +1 -1
- package/dist/unstable/FlushGate.js +155 -38
- package/dist/unstable/FlushGate.js.map +1 -1
- package/dist/unstable/FrameEffects.d.ts +4 -1
- package/dist/unstable/FrameEffects.d.ts.map +1 -1
- package/dist/unstable/FrameEffects.js +12 -1
- package/dist/unstable/FrameEffects.js.map +1 -1
- package/dist/unstable/Imperative.d.ts +13 -4
- package/dist/unstable/Imperative.d.ts.map +1 -1
- package/dist/unstable/Imperative.js +202 -43
- package/dist/unstable/Imperative.js.map +1 -1
- package/dist/unstable/MeasuredPairs.d.ts +6 -2
- package/dist/unstable/MeasuredPairs.d.ts.map +1 -1
- package/dist/unstable/MeasuredPairs.js.map +1 -1
- package/dist/unstable/PresenceRecord.d.ts +4 -0
- package/dist/unstable/PresenceRecord.d.ts.map +1 -1
- package/dist/unstable/PresenceRecord.js.map +1 -1
- package/dist/unstable/Report.d.ts +7 -0
- package/dist/unstable/Report.d.ts.map +1 -1
- package/dist/unstable/Report.js +17 -1
- package/dist/unstable/Report.js.map +1 -1
- package/dist/unstable/RetargetLegs.d.ts +6 -0
- package/dist/unstable/RetargetLegs.d.ts.map +1 -1
- package/dist/unstable/RetargetLegs.js +15 -0
- package/dist/unstable/RetargetLegs.js.map +1 -1
- package/dist/unstable/Spine.d.ts +53 -7
- package/dist/unstable/Spine.d.ts.map +1 -1
- package/dist/unstable/Spine.js +190 -40
- package/dist/unstable/Spine.js.map +1 -1
- package/dist/unstable/VariantTarget.d.ts +25 -3
- package/dist/unstable/VariantTarget.d.ts.map +1 -1
- package/dist/unstable/VariantTarget.js +66 -13
- package/dist/unstable/VariantTarget.js.map +1 -1
- package/dist/unstable/VariantTree.d.ts +37 -3
- package/dist/unstable/VariantTree.d.ts.map +1 -1
- package/dist/unstable/VariantTree.js +54 -7
- package/dist/unstable/VariantTree.js.map +1 -1
- package/package.json +1 -1
- package/src/BaseValue.ts +2 -2
- package/src/Batch.ts +167 -17
- package/src/Clock.ts +20 -0
- package/src/DragRecognizer.ts +82 -30
- package/src/Frame.ts +1 -1
- package/src/InputFeed.ts +37 -40
- package/src/LiveValue.ts +140 -14
- package/src/Machine.ts +67 -34
- package/src/Playback.ts +10 -8
- package/src/Recognizer.ts +9 -3
- package/src/internal/frameLoop.ts +165 -19
- package/src/internal/guarded.ts +69 -0
- package/src/internal/stepper.ts +14 -5
- package/src/unstable/AnimationControls.ts +49 -21
- package/src/unstable/AppearHandoff.ts +7 -0
- package/src/unstable/Config.ts +7 -1
- package/src/unstable/FlushGate.ts +169 -37
- package/src/unstable/FrameEffects.ts +15 -2
- package/src/unstable/Imperative.ts +219 -48
- package/src/unstable/MeasuredPairs.ts +7 -1
- package/src/unstable/PresenceRecord.ts +4 -0
- package/src/unstable/Report.ts +19 -1
- package/src/unstable/RetargetLegs.ts +14 -0
- package/src/unstable/Spine.ts +235 -40
- package/src/unstable/VariantTarget.ts +93 -14
- package/src/unstable/VariantTree.ts +87 -6
|
@@ -48,8 +48,10 @@
|
|
|
48
48
|
*
|
|
49
49
|
* Observability (CONTEXT.md convention): the hot path (`write`/`flush`) is the
|
|
50
50
|
* per-frame work, so — exactly like core's per-frame writes and the Clock's
|
|
51
|
-
* `tick` — it stays quiet (no span, no per-call log, no metric). A
|
|
52
|
-
* binding's hook,
|
|
51
|
+
* `tick` — it stays quiet (no span, no per-call log, no metric). A throw in one element's step (its
|
|
52
|
+
* binding's hook, the read of its own value, its Timeline values, its commit) is that element's: it
|
|
53
|
+
* commits nothing that frame, a run of them is reported once (`Report.failure`) until it commits again,
|
|
54
|
+
* and every other element still commits. Anything else a flush throws is reported and the gate
|
|
53
55
|
* goes on, so it can't fail the Frame loop's tick it runs in (ADR-0033).
|
|
54
56
|
*
|
|
55
57
|
* Unstable, for Wardic's own packages: public, with no semver promise.
|
|
@@ -58,6 +60,7 @@
|
|
|
58
60
|
*/
|
|
59
61
|
// Unstable: ADR-0071, decision 5. #672: dom's `internal/gate.ts`, moved for the spine to write through
|
|
60
62
|
// it in core; dom's `FlushGate` builds it with the DOM's edges (`DOM_GATE`) and gives it as a Layer.
|
|
63
|
+
// #969 (ADR-0033, *Amendment (#969)*): one element's failure in a flush is its own.
|
|
61
64
|
import * as FrameLoop from "../FrameLoop.ts"
|
|
62
65
|
import * as RefreshFrameSource from "../RefreshFrameSource.ts"
|
|
63
66
|
import * as Renderer from "../Renderer.ts"
|
|
@@ -109,8 +112,34 @@ export interface FlushSink {
|
|
|
109
112
|
readonly onCommit?: ((values: Readonly<Record<string, unknown>>) => void) | undefined
|
|
110
113
|
}
|
|
111
114
|
|
|
115
|
+
/**
|
|
116
|
+
* A flush's entries, in order, kept from one flush to the next (#895): `count` of them in use, the rest
|
|
117
|
+
* cleared. Emptied by its count, not `length = 0`, which V8 answers by dropping the array's storage, so it
|
|
118
|
+
* grew again every flush.
|
|
119
|
+
*/
|
|
120
|
+
interface EntryList {
|
|
121
|
+
readonly entries: Array<Entry | undefined>
|
|
122
|
+
count: number
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const entryListOf = (): EntryList => ({ entries: [], count: 0 })
|
|
126
|
+
|
|
127
|
+
/** `entry`, last in `list`. */
|
|
128
|
+
const addTo = (list: EntryList, entry: Entry): void => {
|
|
129
|
+
list.entries[list.count] = entry
|
|
130
|
+
list.count++
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** `list` cleared in place: its storage kept, its slots emptied, so it keeps no entry alive. */
|
|
134
|
+
const clear = (list: EntryList): void => {
|
|
135
|
+
for (let i = 0; i < list.count; i++) list.entries[i] = undefined
|
|
136
|
+
list.count = 0
|
|
137
|
+
}
|
|
138
|
+
|
|
112
139
|
/** Accumulated pre-`project` state for one registered element. */
|
|
113
140
|
interface Entry {
|
|
141
|
+
/** Its gate id: what a failure of its own is reported with (#969). */
|
|
142
|
+
readonly id: string
|
|
114
143
|
/** Merged value-map (partials `Object.assign`ed in by key). */
|
|
115
144
|
readonly values: Record<string, unknown>
|
|
116
145
|
/** Where this element's projected Patch goes. */
|
|
@@ -131,7 +160,14 @@ interface Entry {
|
|
|
131
160
|
* Whether its `onCommit` threw at its last call (#257 item 4): a run of throws is logged and
|
|
132
161
|
* reported at its first, so one that throws every frame logs once; a call that returns ends it.
|
|
133
162
|
*/
|
|
134
|
-
|
|
163
|
+
onCommitFailing: boolean
|
|
164
|
+
/**
|
|
165
|
+
* Whether one of its own steps threw at a flush since its last commit (#969): a run of them is reported
|
|
166
|
+
* at its first, so one that throws every frame logs once; a commit that lands ends it.
|
|
167
|
+
*/
|
|
168
|
+
stepFailing: boolean
|
|
169
|
+
/** Whether its sink's `onHeld` threw before it heard the keys held (#969): its next flush tells it again. */
|
|
170
|
+
heldUntold: boolean
|
|
135
171
|
/** Its patch, projected this flush and committed once the binding has heard the keys held. */
|
|
136
172
|
patch: Renderer.Patch | undefined
|
|
137
173
|
}
|
|
@@ -141,6 +177,8 @@ interface Output {
|
|
|
141
177
|
readonly atom: Atom.Writable<unknown>
|
|
142
178
|
last: unknown
|
|
143
179
|
readonly unmount: () => void
|
|
180
|
+
/** Whether its sets are throwing back a dependent's failure: reported at the first, again after a clean set. */
|
|
181
|
+
failing: boolean
|
|
144
182
|
}
|
|
145
183
|
|
|
146
184
|
/** What the gate calls of a key's Timeline value (#240): its sync with the values drawn, and its cancel. */
|
|
@@ -163,6 +201,9 @@ export interface GateEnvironment {
|
|
|
163
201
|
readonly templateKey: string
|
|
164
202
|
}
|
|
165
203
|
|
|
204
|
+
/** A step of one element's flush, as its failure is reported (#969): `prepare`'s report as its commit. */
|
|
205
|
+
type Step = "a commit" | "a beforeFirstCommit" | "an onHeld" | "a Timeline sync"
|
|
206
|
+
|
|
166
207
|
/** Each of `values` cancelled (#240). Per flush: a plain loop. */
|
|
167
208
|
const cancelEach = (values: Iterable<GateTimeline>): void => {
|
|
168
209
|
for (const value of values) value.cancel()
|
|
@@ -321,8 +362,8 @@ export const makeFlushGate = (runtime: FlushGateRuntime, options: FlushGateOptio
|
|
|
321
362
|
const endings = new Map<Entry, Array<GateTimeline>>()
|
|
322
363
|
// A frame flush's entries, in order, prepared and waiting for their commit; and those whose
|
|
323
364
|
// keys held changed, which the binding hears first. Reused each flush: the per-frame path.
|
|
324
|
-
const prepared
|
|
325
|
-
const heldChanged
|
|
365
|
+
const prepared = entryListOf()
|
|
366
|
+
const heldChanged = entryListOf()
|
|
326
367
|
|
|
327
368
|
/**
|
|
328
369
|
* Project one dirty entry's patch and restore the keys it dropped (once per element per flush),
|
|
@@ -330,11 +371,11 @@ export const makeFlushGate = (runtime: FlushGateRuntime, options: FlushGateOptio
|
|
|
330
371
|
* hears them. Its commit waits for the binding's `batch` of those (ADR-0034, *Amendment
|
|
331
372
|
* (#209)*). Plain calls only: this is the per-frame path.
|
|
332
373
|
*/
|
|
333
|
-
const prepare = (entry: Entry, into:
|
|
374
|
+
const prepare = (entry: Entry, into: EntryList, held: EntryList): void => {
|
|
334
375
|
const patch = project(entry.values)
|
|
335
376
|
entry.dirty = false
|
|
336
377
|
entry.patch = patch
|
|
337
|
-
into
|
|
378
|
+
addTo(into, entry)
|
|
338
379
|
const sink = entry.sink
|
|
339
380
|
const target = sink.target
|
|
340
381
|
const committed = entry.committed
|
|
@@ -357,12 +398,16 @@ export const makeFlushGate = (runtime: FlushGateRuntime, options: FlushGateOptio
|
|
|
357
398
|
if (key in patch) continue
|
|
358
399
|
if (Predicate.isUndefined(restore)) restore = {}
|
|
359
400
|
restore[key] = own
|
|
360
|
-
committed.delete(key)
|
|
361
401
|
}
|
|
362
402
|
}
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
403
|
+
// Committed before its keys are let go of, so a restore that throws is tried again at the next flush (#969).
|
|
404
|
+
if (Predicate.isNotUndefined(restore)) {
|
|
405
|
+
commit(target, restore)
|
|
406
|
+
for (const key in restore) committed.delete(key)
|
|
407
|
+
}
|
|
408
|
+
// The keys held changed (the usual frame changes none), or its sink threw before it heard them: the
|
|
409
|
+
// binding hears before the commit.
|
|
410
|
+
if ((added || Predicate.isNotUndefined(restore) || entry.heldUntold) && Predicate.isNotUndefined(sink.onHeld)) addTo(held, entry)
|
|
366
411
|
}
|
|
367
412
|
|
|
368
413
|
/**
|
|
@@ -375,11 +420,22 @@ export const makeFlushGate = (runtime: FlushGateRuntime, options: FlushGateOptio
|
|
|
375
420
|
for (const [entry, ended] of endings) {
|
|
376
421
|
if (Predicate.isUndefined(entry.patch)) continue
|
|
377
422
|
endings.delete(entry)
|
|
378
|
-
|
|
423
|
+
// Each on its own: one whose cancel throws stops none of the others (#969).
|
|
424
|
+
for (let i = 0; i < ended.length; i++) {
|
|
425
|
+
try {
|
|
426
|
+
ended[i].cancel()
|
|
427
|
+
} catch (defect) {
|
|
428
|
+
failedAt(entry, "a Timeline sync", defect)
|
|
429
|
+
}
|
|
430
|
+
}
|
|
379
431
|
}
|
|
380
432
|
for (const [entry, byKey] of timelines) {
|
|
381
433
|
if (Predicate.isUndefined(entry.patch)) continue
|
|
382
|
-
|
|
434
|
+
try {
|
|
435
|
+
for (const value of byKey.values()) value.sync(entry.values)
|
|
436
|
+
} catch (defect) {
|
|
437
|
+
failedAt(entry, "a Timeline sync", defect)
|
|
438
|
+
}
|
|
383
439
|
}
|
|
384
440
|
}
|
|
385
441
|
|
|
@@ -399,26 +455,60 @@ export const makeFlushGate = (runtime: FlushGateRuntime, options: FlushGateOptio
|
|
|
399
455
|
if (Predicate.isUndefined(patch)) return
|
|
400
456
|
entry.patch = undefined
|
|
401
457
|
commit(entry.sink.target, patch)
|
|
458
|
+
if (entry.stepFailing) entry.stepFailing = false
|
|
402
459
|
if (Predicate.isNotUndefined(entry.sink.onCommit)) committedSince.add(entry)
|
|
403
460
|
}
|
|
404
461
|
|
|
462
|
+
/**
|
|
463
|
+
* One of `entry`'s steps threw this flush (#969): its later steps skipped this frame, its patch with
|
|
464
|
+
* them, and the other elements' going on. A run of them is reported at its first, `step` naming it.
|
|
465
|
+
*/
|
|
466
|
+
// A failure's path, never the frame's: one place each loop's catch calls.
|
|
467
|
+
const failedAt = (entry: Entry, step: Step, defect: unknown): void => {
|
|
468
|
+
entry.patch = undefined
|
|
469
|
+
// Tried again at the gate's next flush, which it doesn't ask for itself: a Subject frozen for good would
|
|
470
|
+
// keep the host's frames running. A later write, its own or another element's, brings that flush.
|
|
471
|
+
entry.dirty = true
|
|
472
|
+
// Its sink's `onCommit` hears nothing of a frame it didn't commit in.
|
|
473
|
+
committedSince.delete(entry)
|
|
474
|
+
if (entry.stepFailing) return
|
|
475
|
+
entry.stepFailing = true
|
|
476
|
+
runtime.runFork(Effect.annotateLogs(Report.failure(`wardic.gate: ${step} failed`, Cause.die(defect)), { id: entry.id }))
|
|
477
|
+
}
|
|
478
|
+
|
|
405
479
|
/**
|
|
406
480
|
* The prepared entries, committed, after the binding has heard the keys held change, together, in
|
|
407
481
|
* its `batch` (#209); both lists emptied for the next flush.
|
|
408
482
|
*/
|
|
409
|
-
const commitAll = (entries:
|
|
410
|
-
if (held.
|
|
411
|
-
for (
|
|
412
|
-
entries.
|
|
413
|
-
|
|
483
|
+
const commitAll = (entries: EntryList, held: EntryList): void => {
|
|
484
|
+
if (held.count > 0) batch(() => tellHeld(held))
|
|
485
|
+
// A try for each element, its call direct (#969): a shared helper taking the step measured +20% a frame.
|
|
486
|
+
for (let i = 0; i < entries.count; i++) {
|
|
487
|
+
const entry = entries.entries[i] as Entry
|
|
488
|
+
try {
|
|
489
|
+
commitPrepared(entry)
|
|
490
|
+
} catch (defect) {
|
|
491
|
+
failedAt(entry, "a commit", defect)
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
clear(entries)
|
|
495
|
+
clear(held)
|
|
414
496
|
}
|
|
415
497
|
|
|
416
498
|
/** Each entry's `onHeld`, with every key the gate holds on its element now. */
|
|
417
|
-
const tellHeld = (held:
|
|
418
|
-
for (let i = 0; i < held.
|
|
419
|
-
const entry = held[i]
|
|
499
|
+
const tellHeld = (held: EntryList): void => {
|
|
500
|
+
for (let i = 0; i < held.count; i++) {
|
|
501
|
+
const entry = held.entries[i] as Entry
|
|
420
502
|
const onHeld = entry.sink.onHeld
|
|
421
|
-
if (Predicate.
|
|
503
|
+
if (Predicate.isUndefined(onHeld)) continue
|
|
504
|
+
try {
|
|
505
|
+
onHeld(Array.from(entry.committed.keys()))
|
|
506
|
+
if (entry.heldUntold) entry.heldUntold = false
|
|
507
|
+
} catch (defect) {
|
|
508
|
+
// Told again at its next flush, before its commit (#969).
|
|
509
|
+
entry.heldUntold = true
|
|
510
|
+
failedAt(entry, "an onHeld", defect)
|
|
511
|
+
}
|
|
422
512
|
}
|
|
423
513
|
}
|
|
424
514
|
|
|
@@ -441,10 +531,10 @@ export const makeFlushGate = (runtime: FlushGateRuntime, options: FlushGateOptio
|
|
|
441
531
|
delete latest[templateKey]
|
|
442
532
|
try {
|
|
443
533
|
onCommit(latest)
|
|
444
|
-
entry.
|
|
534
|
+
entry.onCommitFailing = false
|
|
445
535
|
} catch (defect) {
|
|
446
|
-
if (entry.
|
|
447
|
-
entry.
|
|
536
|
+
if (entry.onCommitFailing) continue
|
|
537
|
+
entry.onCommitFailing = true
|
|
448
538
|
runtime.runFork(Report.failure("wardic.gate: an onCommit failed", Cause.die(defect)))
|
|
449
539
|
}
|
|
450
540
|
}
|
|
@@ -457,6 +547,9 @@ export const makeFlushGate = (runtime: FlushGateRuntime, options: FlushGateOptio
|
|
|
457
547
|
* written in the same frame, and commits with it. An unchanged one skips the registry. Plain
|
|
458
548
|
* calls: a write is the per-frame path.
|
|
459
549
|
*/
|
|
550
|
+
// #979, group D (ADR-0074): an output's dependent that throws (an app's Atom over a ward's `read(key)`)
|
|
551
|
+
// is its own. The registry has set the output and told its other listeners before the throw comes back,
|
|
552
|
+
// so the write goes on, the element's other outputs with it: before, it came out of the ward's own leg.
|
|
460
553
|
const setOutputs = (entry: Entry): void => {
|
|
461
554
|
const outputs = entry.outputs
|
|
462
555
|
if (Predicate.isUndefined(outputs)) return
|
|
@@ -464,7 +557,20 @@ export const makeFlushGate = (runtime: FlushGateRuntime, options: FlushGateOptio
|
|
|
464
557
|
const value = entry.values[key]
|
|
465
558
|
if (value === output.last) continue
|
|
466
559
|
output.last = value
|
|
560
|
+
setOutput(entry.id, key, output, value)
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/** `output` set to `value`, its dependent's throw its own: reported once a run of throws, until a clean set. */
|
|
565
|
+
// The try is here, out of the loops that call it (`setOutputs`', `endOutputs`'): in the body of
|
|
566
|
+
// `setOutputs`' loop over the element's outputs Map, it measured +5–8% on Node's write.
|
|
567
|
+
const setOutput = (id: string, key: string, output: Output, value: unknown): void => {
|
|
568
|
+
try {
|
|
467
569
|
registry.set(output.atom, value)
|
|
570
|
+
if (output.failing) output.failing = false
|
|
571
|
+
} catch (defect) {
|
|
572
|
+
if (!output.failing) runtime.runFork(Effect.annotateLogs(Report.failure("wardic.gate: an output failed", Cause.die(defect)), { id, key }))
|
|
573
|
+
output.failing = true
|
|
468
574
|
}
|
|
469
575
|
}
|
|
470
576
|
|
|
@@ -477,9 +583,15 @@ export const makeFlushGate = (runtime: FlushGateRuntime, options: FlushGateOptio
|
|
|
477
583
|
for (const id of firstCommits) {
|
|
478
584
|
const entry = accumulator.get(id)
|
|
479
585
|
if (Predicate.isUndefined(entry) || !entry.dirty) continue
|
|
480
|
-
firstCommits.delete(id)
|
|
481
586
|
const hook = entry.sink.beforeFirstCommit
|
|
482
|
-
|
|
587
|
+
try {
|
|
588
|
+
if (Predicate.isNotUndefined(hook)) hook()
|
|
589
|
+
// Its own: a hook that registered the id again leaves the new entry's switch to come (#969).
|
|
590
|
+
if (accumulator.get(id) === entry) firstCommits.delete(id)
|
|
591
|
+
} catch (defect) {
|
|
592
|
+
// Kept, so the gate's next flush switches it; nothing of it commits before (#969).
|
|
593
|
+
failedAt(entry, "a beforeFirstCommit", defect)
|
|
594
|
+
}
|
|
483
595
|
}
|
|
484
596
|
}
|
|
485
597
|
|
|
@@ -490,13 +602,22 @@ export const makeFlushGate = (runtime: FlushGateRuntime, options: FlushGateOptio
|
|
|
490
602
|
if (firstCommits.size > 0) batch(runFirstCommits)
|
|
491
603
|
// Every dirty element, once. No auto-reschedule — the next write() does. A write()
|
|
492
604
|
// from an effect a sink's hook runs requests the next frame (it isn't stranded).
|
|
493
|
-
for (const entry of accumulator.values())
|
|
605
|
+
for (const entry of accumulator.values()) {
|
|
606
|
+
if (!entry.dirty) continue
|
|
607
|
+
// Its Starting-style switch threw this frame: it waits for the next flush's (#969).
|
|
608
|
+
if (firstCommits.size > 0 && firstCommits.has(entry.id)) continue
|
|
609
|
+
try {
|
|
610
|
+
prepare(entry, prepared, heldChanged)
|
|
611
|
+
} catch (defect) {
|
|
612
|
+
failedAt(entry, "a commit", defect)
|
|
613
|
+
}
|
|
614
|
+
}
|
|
494
615
|
if (timelines.size > 0 || endings.size > 0) syncTimelines()
|
|
495
616
|
commitAll(prepared, heldChanged)
|
|
496
617
|
if (committedSince.size > 0) tellCommitted()
|
|
497
618
|
} catch (defect) {
|
|
498
|
-
prepared
|
|
499
|
-
heldChanged
|
|
619
|
+
clear(prepared)
|
|
620
|
+
clear(heldChanged)
|
|
500
621
|
runtime.runFork(Report.failure("wardic.gate: a flush failed", Cause.die(defect)))
|
|
501
622
|
}
|
|
502
623
|
if (afterFlushes.length > 0) runAfterFlushes()
|
|
@@ -544,8 +665,11 @@ export const makeFlushGate = (runtime: FlushGateRuntime, options: FlushGateOptio
|
|
|
544
665
|
dirty: false,
|
|
545
666
|
committed: new Map(),
|
|
546
667
|
outputs: outputsById.get(id),
|
|
668
|
+
id,
|
|
547
669
|
latest: undefined,
|
|
548
|
-
|
|
670
|
+
onCommitFailing: false,
|
|
671
|
+
stepFailing: false,
|
|
672
|
+
heldUntold: false,
|
|
549
673
|
patch: undefined,
|
|
550
674
|
}
|
|
551
675
|
// An entry the id had: its Timeline values end with it (#240).
|
|
@@ -563,12 +687,15 @@ export const makeFlushGate = (runtime: FlushGateRuntime, options: FlushGateOptio
|
|
|
563
687
|
}
|
|
564
688
|
|
|
565
689
|
/** `id`'s live outputs, each set to `undefined` and forgotten: its element is gone. */
|
|
690
|
+
// #979, row 42 (ADR-0074): set through `setOutput`, so a dependent that throws as its element leaves is
|
|
691
|
+
// reported, and every output still ends: before, its throw came out of the unregister, a binding's
|
|
692
|
+
// cleanup, and left that output and the later ones mounted.
|
|
566
693
|
const endOutputs = (id: string): void => {
|
|
567
694
|
const outputs = outputsById.get(id)
|
|
568
695
|
if (Predicate.isUndefined(outputs)) return
|
|
569
696
|
outputsById.delete(id)
|
|
570
|
-
for (const output of outputs
|
|
571
|
-
|
|
697
|
+
for (const [key, output] of outputs) {
|
|
698
|
+
setOutput(id, key, output, undefined)
|
|
572
699
|
output.unmount()
|
|
573
700
|
}
|
|
574
701
|
}
|
|
@@ -593,7 +720,7 @@ export const makeFlushGate = (runtime: FlushGateRuntime, options: FlushGateOptio
|
|
|
593
720
|
// Made `undefined` and mounted until its element unregisters, not kept alive: a kept-alive
|
|
594
721
|
// Atom's node never leaves the registry, and one left behind reads `undefined` afresh.
|
|
595
722
|
const atom = Atom.make<unknown>(undefined)
|
|
596
|
-
const output: Output = { atom, last: undefined, unmount: registry.mount(atom) }
|
|
723
|
+
const output: Output = { atom, last: undefined, unmount: registry.mount(atom), failing: false }
|
|
597
724
|
outputs.set(key, output)
|
|
598
725
|
const value = committedValueOf(id, key)
|
|
599
726
|
if (Predicate.isNotUndefined(value)) {
|
|
@@ -627,11 +754,16 @@ export const makeFlushGate = (runtime: FlushGateRuntime, options: FlushGateOptio
|
|
|
627
754
|
// flush (a frame later for an element mounted inside a frame). The frame flush switches.
|
|
628
755
|
// A commit here is told at the frame flush (#233): the write that made it scheduled that flush.
|
|
629
756
|
// Its own lists: a pass may run from a hook the frame flush's `batch` runs.
|
|
630
|
-
const entries
|
|
631
|
-
const held
|
|
757
|
+
const entries = entryListOf()
|
|
758
|
+
const held = entryListOf()
|
|
632
759
|
for (const id of written) {
|
|
633
760
|
const entry = accumulator.get(id)
|
|
634
|
-
if (Predicate.
|
|
761
|
+
if (Predicate.isUndefined(entry) || !entry.dirty) continue
|
|
762
|
+
try {
|
|
763
|
+
prepare(entry, entries, held)
|
|
764
|
+
} catch (defect) {
|
|
765
|
+
failedAt(entry, "a commit", defect)
|
|
766
|
+
}
|
|
635
767
|
}
|
|
636
768
|
if (timelines.size > 0 || endings.size > 0) syncTimelines()
|
|
637
769
|
commitAll(entries, held)
|
|
@@ -30,7 +30,10 @@ import * as RefreshFrameSource from "../RefreshFrameSource.ts"
|
|
|
30
30
|
export interface FrameEffectsOptions {
|
|
31
31
|
/** Asks the Environment for a frame, whose end runs the effects. Called once a request, until the run. */
|
|
32
32
|
readonly requestFrame: () => void
|
|
33
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* What an effect that throws reports, at the first frame of a run of throws: its next frame that
|
|
35
|
+
* returns ends the run. The rest of the frame's effects still run.
|
|
36
|
+
*/
|
|
34
37
|
readonly report: (defect: unknown) => void
|
|
35
38
|
}
|
|
36
39
|
|
|
@@ -64,6 +67,13 @@ export const make = (options: FrameEffectsOptions): FrameEffects => {
|
|
|
64
67
|
let running = false
|
|
65
68
|
let removedInRun = 0
|
|
66
69
|
let asked = false
|
|
70
|
+
// #979 group I, row 22 (ADR-0074 decision 3): a run of throws is reported once, at its first. A throw is
|
|
71
|
+
// its run's first unless the entry threw at the run before, so a frame it returns from ends the run. The
|
|
72
|
+
// runs are numbered, and the run an entry last threw in is kept here, written only in the catch: the
|
|
73
|
+
// clean path does nothing. A flag on the entry cleared there cost Node 12% on a bare effect, and a number
|
|
74
|
+
// on the entry written in the catch 3% (group I's microbench); this one nothing.
|
|
75
|
+
let runs = 0
|
|
76
|
+
const threwAt = new Map<Entry, number>()
|
|
67
77
|
|
|
68
78
|
/** The entries no longer live taken out, in place, keeping the rest's order. */
|
|
69
79
|
const compact = (): void => {
|
|
@@ -81,6 +91,7 @@ export const make = (options: FrameEffectsOptions): FrameEffects => {
|
|
|
81
91
|
return () => {
|
|
82
92
|
if (!entry.live) return
|
|
83
93
|
entry.live = false
|
|
94
|
+
threwAt.delete(entry)
|
|
84
95
|
if (running) {
|
|
85
96
|
removedInRun++
|
|
86
97
|
return
|
|
@@ -98,6 +109,7 @@ export const make = (options: FrameEffectsOptions): FrameEffects => {
|
|
|
98
109
|
const run: FrameEffects["run"] = (time) => {
|
|
99
110
|
asked = false
|
|
100
111
|
running = true
|
|
112
|
+
runs++
|
|
101
113
|
// Those added before the run: one added in it waits for the next frame.
|
|
102
114
|
const count = entries.length
|
|
103
115
|
try {
|
|
@@ -107,7 +119,8 @@ export const make = (options: FrameEffectsOptions): FrameEffects => {
|
|
|
107
119
|
try {
|
|
108
120
|
entry.effect(time)
|
|
109
121
|
} catch (defect) {
|
|
110
|
-
report(defect)
|
|
122
|
+
if (threwAt.get(entry) !== runs - 1) report(defect)
|
|
123
|
+
threwAt.set(entry, runs)
|
|
111
124
|
}
|
|
112
125
|
}
|
|
113
126
|
} finally {
|