@wardic/core 1.3.1 → 1.4.0
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/Arc.d.ts +2 -2
- package/dist/Arc.js +1 -1
- package/dist/BaseValue.d.ts +11 -10
- package/dist/BaseValue.d.ts.map +1 -1
- package/dist/BaseValue.js +12 -15
- package/dist/BaseValue.js.map +1 -1
- package/dist/Batch.d.ts +12 -6
- package/dist/Batch.d.ts.map +1 -1
- package/dist/Batch.js +374 -30
- 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 +22 -8
- package/dist/Clock.js.map +1 -1
- package/dist/DefaultTransition.d.ts +3 -2
- package/dist/DefaultTransition.d.ts.map +1 -1
- package/dist/DefaultTransition.js +5 -3
- package/dist/DefaultTransition.js.map +1 -1
- package/dist/Drag.d.ts +24 -9
- package/dist/Drag.d.ts.map +1 -1
- package/dist/Drag.js +10 -10
- package/dist/Drag.js.map +1 -1
- package/dist/DragActivity.js +3 -3
- package/dist/DragRecognizer.d.ts +14 -8
- package/dist/DragRecognizer.d.ts.map +1 -1
- package/dist/DragRecognizer.js +93 -34
- package/dist/DragRecognizer.js.map +1 -1
- package/dist/Easing.d.ts +1 -1
- package/dist/Easing.js +1 -1
- package/dist/Frame.d.ts.map +1 -1
- package/dist/Frame.js +5 -3
- package/dist/Frame.js.map +1 -1
- package/dist/InputFeed.d.ts +11 -8
- package/dist/InputFeed.d.ts.map +1 -1
- package/dist/InputFeed.js +18 -37
- package/dist/InputFeed.js.map +1 -1
- package/dist/InputSource.d.ts +3 -3
- package/dist/InputSource.js +2 -2
- package/dist/Interpolator.d.ts +2 -2
- package/dist/Interpolator.js +2 -2
- package/dist/InterpolatorRegistry.d.ts +29 -15
- package/dist/InterpolatorRegistry.d.ts.map +1 -1
- package/dist/InterpolatorRegistry.js +17 -8
- package/dist/InterpolatorRegistry.js.map +1 -1
- package/dist/LiveValue.d.ts +16 -9
- package/dist/LiveValue.d.ts.map +1 -1
- package/dist/LiveValue.js +204 -27
- package/dist/LiveValue.js.map +1 -1
- package/dist/Machine.d.ts +21 -8
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +184 -60
- package/dist/Machine.js.map +1 -1
- package/dist/Playback.d.ts.map +1 -1
- package/dist/Playback.js +16 -9
- package/dist/Playback.js.map +1 -1
- package/dist/Projection.d.ts +9 -9
- package/dist/Projection.js +2 -2
- package/dist/Recognizer.d.ts +2 -2
- package/dist/Recognizer.d.ts.map +1 -1
- package/dist/Recognizer.js +15 -10
- package/dist/Recognizer.js.map +1 -1
- package/dist/ReducedMotion.d.ts +4 -4
- package/dist/ReducedMotion.js +6 -6
- package/dist/Renderer.d.ts +5 -5
- package/dist/Renderer.js +6 -6
- package/dist/Renderer.js.map +1 -1
- package/dist/Reorder.d.ts +1 -1
- package/dist/Reorder.d.ts.map +1 -1
- package/dist/Reorder.js +2 -1
- package/dist/Reorder.js.map +1 -1
- package/dist/ScrollSource.d.ts +1 -1
- package/dist/ScrollSource.d.ts.map +1 -1
- package/dist/Sequence.d.ts +1 -1
- package/dist/SharedSource.d.ts +3 -3
- package/dist/SharedSource.js +5 -5
- package/dist/SharedSource.js.map +1 -1
- package/dist/Spring.d.ts.map +1 -1
- package/dist/Spring.js +2 -1
- package/dist/Spring.js.map +1 -1
- package/dist/Values.d.ts +2 -2
- package/dist/Values.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/internal/carried.d.ts +13 -0
- package/dist/internal/carried.d.ts.map +1 -0
- package/dist/internal/carried.js +23 -0
- package/dist/internal/carried.js.map +1 -0
- package/dist/internal/firstSteps.d.ts +66 -0
- package/dist/internal/firstSteps.d.ts.map +1 -0
- package/dist/internal/firstSteps.js +107 -0
- package/dist/internal/firstSteps.js.map +1 -0
- package/dist/internal/frameLoop.d.ts +11 -3
- package/dist/internal/frameLoop.d.ts.map +1 -1
- package/dist/internal/frameLoop.js +190 -39
- 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/lerpsNumbers.d.ts +11 -0
- package/dist/internal/lerpsNumbers.d.ts.map +1 -0
- package/dist/internal/lerpsNumbers.js +38 -0
- package/dist/internal/lerpsNumbers.js.map +1 -0
- package/dist/internal/options.d.ts +7 -7
- package/dist/internal/options.d.ts.map +1 -1
- package/dist/internal/options.js +10 -10
- package/dist/internal/options.js.map +1 -1
- package/dist/internal/stepper.d.ts +21 -4
- package/dist/internal/stepper.d.ts.map +1 -1
- package/dist/internal/stepper.js +21 -5
- package/dist/internal/stepper.js.map +1 -1
- package/dist/internal/tracing.d.ts +1 -1
- package/dist/internal/tracing.js +1 -1
- package/dist/unstable/AnimationControls.d.ts +45 -39
- package/dist/unstable/AnimationControls.d.ts.map +1 -1
- package/dist/unstable/AnimationControls.js +59 -35
- package/dist/unstable/AnimationControls.js.map +1 -1
- package/dist/unstable/AppearHandoff.d.ts +11 -5
- package/dist/unstable/AppearHandoff.d.ts.map +1 -1
- package/dist/unstable/AppearHandoff.js.map +1 -1
- package/dist/unstable/BatchCalls.d.ts +2 -2
- package/dist/unstable/BatchCalls.js +5 -5
- package/dist/unstable/Config.d.ts +21 -17
- package/dist/unstable/Config.d.ts.map +1 -1
- package/dist/unstable/Config.js.map +1 -1
- package/dist/unstable/FirstSteps.d.ts +25 -0
- package/dist/unstable/FirstSteps.d.ts.map +1 -0
- package/dist/unstable/FirstSteps.js +2 -0
- package/dist/unstable/FirstSteps.js.map +1 -0
- package/dist/unstable/FlushGate.d.ts +54 -50
- package/dist/unstable/FlushGate.d.ts.map +1 -1
- package/dist/unstable/FlushGate.js +201 -77
- package/dist/unstable/FlushGate.js.map +1 -1
- package/dist/unstable/FrameEffects.d.ts +6 -3
- package/dist/unstable/FrameEffects.d.ts.map +1 -1
- package/dist/unstable/FrameEffects.js +14 -3
- package/dist/unstable/FrameEffects.js.map +1 -1
- package/dist/unstable/FrameTime.d.ts +1 -1
- package/dist/unstable/FrameTime.js +1 -1
- package/dist/unstable/Imperative.d.ts +42 -13
- package/dist/unstable/Imperative.d.ts.map +1 -1
- package/dist/unstable/Imperative.js +279 -88
- 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/OwnValues.js +1 -1
- package/dist/unstable/PresenceRecord.d.ts +30 -26
- package/dist/unstable/PresenceRecord.d.ts.map +1 -1
- package/dist/unstable/PresenceRecord.js +8 -8
- package/dist/unstable/PresenceRecord.js.map +1 -1
- package/dist/unstable/Projector.d.ts +34 -0
- package/dist/unstable/Projector.d.ts.map +1 -0
- package/dist/unstable/Projector.js +9 -0
- package/dist/unstable/Projector.js.map +1 -0
- package/dist/unstable/Report.d.ts +8 -1
- package/dist/unstable/Report.d.ts.map +1 -1
- package/dist/unstable/Report.js +18 -2
- package/dist/unstable/Report.js.map +1 -1
- package/dist/unstable/RetargetLegs.d.ts +7 -1
- package/dist/unstable/RetargetLegs.d.ts.map +1 -1
- package/dist/unstable/RetargetLegs.js +24 -8
- package/dist/unstable/RetargetLegs.js.map +1 -1
- package/dist/unstable/Spine.d.ts +123 -68
- package/dist/unstable/Spine.d.ts.map +1 -1
- package/dist/unstable/Spine.js +319 -167
- package/dist/unstable/Spine.js.map +1 -1
- package/dist/unstable/Stops.d.ts +3 -3
- package/dist/unstable/Stops.js +4 -4
- package/dist/unstable/Subject.d.ts +2 -2
- package/dist/unstable/Subject.js +2 -2
- package/dist/unstable/Timelines.d.ts +11 -11
- package/dist/unstable/Timelines.d.ts.map +1 -1
- package/dist/unstable/Timelines.js +3 -3
- package/dist/unstable/VariantTarget.d.ts +32 -10
- package/dist/unstable/VariantTarget.d.ts.map +1 -1
- package/dist/unstable/VariantTarget.js +73 -20
- package/dist/unstable/VariantTarget.js.map +1 -1
- package/dist/unstable/VariantTree.d.ts +68 -34
- package/dist/unstable/VariantTree.d.ts.map +1 -1
- package/dist/unstable/VariantTree.js +83 -36
- package/dist/unstable/VariantTree.js.map +1 -1
- package/dist/unstable/WardicConfigValue.d.ts +13 -13
- package/dist/unstable/WardicConfigValue.d.ts.map +1 -1
- package/dist/unstable/WardicConfigValue.js +4 -4
- package/dist/unstable/WardicConfigValue.js.map +1 -1
- package/package.json +1 -1
- package/src/Arc.ts +3 -3
- package/src/BaseValue.ts +18 -21
- package/src/Batch.ts +391 -27
- package/src/Clock.ts +29 -8
- package/src/DefaultTransition.ts +5 -3
- package/src/Drag.ts +32 -14
- package/src/DragActivity.ts +3 -3
- package/src/DragRecognizer.ts +118 -41
- package/src/Easing.ts +1 -1
- package/src/Frame.ts +5 -3
- package/src/InputFeed.ts +39 -42
- package/src/InputSource.ts +5 -5
- package/src/Interpolator.ts +3 -3
- package/src/InterpolatorRegistry.ts +22 -13
- package/src/LiveValue.ts +186 -30
- package/src/Machine.ts +252 -81
- package/src/Playback.ts +15 -9
- package/src/Projection.ts +9 -9
- package/src/Recognizer.ts +16 -10
- package/src/ReducedMotion.ts +6 -6
- package/src/Renderer.ts +6 -6
- package/src/Reorder.ts +3 -2
- package/src/ScrollSource.ts +1 -1
- package/src/Sequence.ts +1 -1
- package/src/SharedSource.ts +5 -5
- package/src/Spring.ts +2 -1
- package/src/Values.ts +2 -2
- package/src/index.ts +1 -1
- package/src/internal/carried.ts +22 -0
- package/src/internal/firstSteps.ts +139 -0
- package/src/internal/frameLoop.ts +203 -41
- package/src/internal/guarded.ts +69 -0
- package/src/internal/lerpsNumbers.ts +53 -0
- package/src/internal/options.ts +10 -10
- package/src/internal/stepper.ts +33 -6
- package/src/internal/tracing.ts +1 -1
- package/src/unstable/AnimationControls.ts +88 -57
- package/src/unstable/AppearHandoff.ts +13 -6
- package/src/unstable/BatchCalls.ts +5 -5
- package/src/unstable/Config.ts +23 -17
- package/src/unstable/FirstSteps.ts +26 -0
- package/src/unstable/FlushGate.ts +250 -108
- package/src/unstable/FrameEffects.ts +17 -4
- package/src/unstable/FrameTime.ts +1 -1
- package/src/unstable/Imperative.ts +342 -101
- package/src/unstable/MeasuredPairs.ts +7 -1
- package/src/unstable/OwnValues.ts +1 -1
- package/src/unstable/PresenceRecord.ts +33 -29
- package/src/unstable/Projector.ts +45 -0
- package/src/unstable/Report.ts +20 -2
- package/src/unstable/RetargetLegs.ts +24 -9
- package/src/unstable/Spine.ts +399 -202
- package/src/unstable/Stops.ts +6 -6
- package/src/unstable/Subject.ts +2 -2
- package/src/unstable/Timelines.ts +12 -12
- package/src/unstable/VariantTarget.ts +102 -23
- package/src/unstable/VariantTree.ts +123 -42
- package/src/unstable/WardicConfigValue.ts +13 -13
|
@@ -4,52 +4,55 @@
|
|
|
4
4
|
* sinks, and its Environment the edges it reads (`GateEnvironment`); the gate imports nothing from a
|
|
5
5
|
* framework.
|
|
6
6
|
*
|
|
7
|
-
* Per ADR-0006, per-frame writes never reach their
|
|
7
|
+
* Per ADR-0006, per-frame writes never reach their Subject directly. Each source
|
|
8
8
|
* `write(id, partialValues)`s into a provider-owned gate that:
|
|
9
9
|
*
|
|
10
|
-
* 1. Accumulates *value-maps* (NOT already-projected Patches) per
|
|
11
|
-
* merging partials by key — so multiple sources can feed one
|
|
10
|
+
* 1. Accumulates *value-maps* (NOT already-projected Patches) per Subject,
|
|
11
|
+
* merging partials by key — so multiple sources can feed one Subject
|
|
12
12
|
* (e.g. a drag setting `x`/`y` while a spring drives `scale`, all
|
|
13
13
|
* collapsing into one grouped `transform`). Projecting per source would
|
|
14
14
|
* clobber the grouped transform.
|
|
15
15
|
* 2. Resolves the Renderer's PURE `project` ONCE at creation and uses it to
|
|
16
|
-
* turn each dirty
|
|
17
|
-
* per
|
|
18
|
-
*
|
|
19
|
-
*
|
|
16
|
+
* turn each dirty Subject's merged value-map into a `Patch` exactly once
|
|
17
|
+
* per Subject per frame; or, for a Renderer with a projector (`unstable/Projector`),
|
|
18
|
+
* the Subject's own, made when it registers, whose patch it rewrites in place.
|
|
19
|
+
* 3. Commits each resulting Patch onto its Subject with the Renderer's `commit`, a plain
|
|
20
|
+
* call (ADR-0034) — one pass over the Subjects per frame, shared by every Subject: at the end of the
|
|
20
21
|
* Frame loop's tick, in the Refresh frame that computed the values (ADR-0033). No
|
|
21
|
-
* framework runs per frame: a binding's render carries
|
|
22
|
+
* framework runs per frame: a binding's render carries a Subject's style only until its
|
|
22
23
|
* first commit (ADR-0021, decision 6), and after it only the keys the gate doesn't hold.
|
|
23
24
|
*
|
|
24
25
|
* Three locked design decisions (this session's grills):
|
|
25
26
|
* - FLUSHED at the end of the Frame loop's tick (ADR-0033): the gate registers a hook on
|
|
26
27
|
* the Environment's loop (`afterTick`), so everything a tick writes is applied at the end
|
|
27
|
-
* of that tick, inside the Clock's callback, and
|
|
28
|
+
* of that tick, inside the Clock's callback, and drawn in that Refresh frame. A write
|
|
28
29
|
* made outside a tick (a drag's move, a `release` from a task, an effect a sink's hook ran,
|
|
29
30
|
* a Tier 2 `Stream` on `Clock.ticks` subscribed after the loop) still requests a
|
|
30
31
|
* Refresh frame, only if one is not already pending, and the hook withdraws that request
|
|
31
32
|
* when it flushes first. `flush` does NOT auto-reschedule, so an idle accumulator
|
|
32
33
|
* requests no frames — the next `write` does. The frames come from the Environment's
|
|
33
34
|
* `RefreshFrameSource` (ADR-0031): `@wardic/dom`'s is its runtime's frame callback. No binding
|
|
34
|
-
* asks its runtime for frames itself. A Tier 2 `Stream` that writes here
|
|
35
|
+
* asks its runtime for frames itself. A Tier 2 `Stream` that writes here is drawn in
|
|
35
36
|
* the loop's frame or the next one, by its subscription order (ADR-0033): run it on the
|
|
36
|
-
* loop (`Machine.run`) to
|
|
37
|
-
* - ONE flush per frame: all dirty
|
|
37
|
+
* loop (`Machine.run`) to be drawn with it.
|
|
38
|
+
* - ONE flush per frame: all dirty Subjects flush together. The one exception
|
|
38
39
|
* is `flushPass` (ADR-0018): a projection Measure pass's own writes are applied
|
|
39
|
-
* at the end of its task, so a new layout never
|
|
40
|
-
* - ONE sink shape (ADR-0034): a sink is the
|
|
41
|
-
* also removes a key its last patch had and this one doesn't (a dragged
|
|
42
|
-
* once it's dropped, ADR-0016 *Amendment (Reorder)*), restoring the
|
|
40
|
+
* at the end of its task, so a new layout is never drawn without its projection.
|
|
41
|
+
* - ONE sink shape (ADR-0034): a sink is the Subject its patch is committed onto. The gate
|
|
42
|
+
* also removes a key its last patch had and this one doesn't (a dragged Subject's raise
|
|
43
|
+
* once it's dropped, ADR-0016 *Amendment (Reorder)*), restoring the Subject's own
|
|
43
44
|
* value, saved before the gate first wrote the key. Two hooks reach the binding,
|
|
44
45
|
* outside the commits, each in the binding's `batch` (ADR-0034, *Amendment (#209)*): the
|
|
45
|
-
* Starting-style switch before
|
|
46
|
-
* the gate holds on the
|
|
46
|
+
* Starting-style switch before a Subject's first commit (`beforeFirstCommit`), and the keys
|
|
47
|
+
* the gate holds on the Subject whenever they change (`onHeld`), so the binding's `style`
|
|
47
48
|
* leaves them to Wardic.
|
|
48
49
|
*
|
|
49
50
|
* Observability (CONTEXT.md convention): the hot path (`write`/`flush`) is the
|
|
50
51
|
* 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,
|
|
52
|
+
* `tick` — it stays quiet (no span, no per-call log, no metric). A throw in one Subject's step (its
|
|
53
|
+
* binding's hook, the read of its own value, its Timeline values, its commit) is that Subject's: it
|
|
54
|
+
* commits nothing that frame, a run of them is reported once (`Report.failure`) until it commits again,
|
|
55
|
+
* and every other Subject still commits. Anything else a flush throws is reported and the gate
|
|
53
56
|
* goes on, so it can't fail the Frame loop's tick it runs in (ADR-0033).
|
|
54
57
|
*
|
|
55
58
|
* Unstable, for Wardic's own packages: public, with no semver promise.
|
|
@@ -58,14 +61,17 @@
|
|
|
58
61
|
*/
|
|
59
62
|
// Unstable: ADR-0071, decision 5. #672: dom's `internal/gate.ts`, moved for the spine to write through
|
|
60
63
|
// it in core; dom's `FlushGate` builds it with the DOM's edges (`DOM_GATE`) and gives it as a Layer.
|
|
64
|
+
// #969 (ADR-0033, *Amendment (#969)*): one Subject's failure in a flush is its own.
|
|
61
65
|
import * as FrameLoop from "../FrameLoop.ts"
|
|
62
66
|
import * as RefreshFrameSource from "../RefreshFrameSource.ts"
|
|
63
67
|
import * as Renderer from "../Renderer.ts"
|
|
68
|
+
import * as Projector from "./Projector.ts"
|
|
64
69
|
import * as Cause from "effect/Cause"
|
|
65
70
|
import * as Atom from "effect/reactivity/Atom"
|
|
66
71
|
import * as AtomRegistry from "effect/reactivity/AtomRegistry"
|
|
67
72
|
import * as Effect from "effect/Effect"
|
|
68
73
|
import * as Exit from "effect/Exit"
|
|
74
|
+
import * as Option from "effect/Option"
|
|
69
75
|
import type * as Fiber from "effect/Fiber"
|
|
70
76
|
import * as Predicate from "effect/Predicate"
|
|
71
77
|
import * as UndefinedOr from "effect/UndefinedOr"
|
|
@@ -77,48 +83,77 @@ import * as Report from "./Report.ts"
|
|
|
77
83
|
* at flush time.
|
|
78
84
|
*/
|
|
79
85
|
export interface FlushSink {
|
|
80
|
-
/** The
|
|
86
|
+
/** The Subject the patch is committed onto. */
|
|
81
87
|
readonly target: unknown
|
|
82
88
|
/**
|
|
83
|
-
* Called once, just before the
|
|
84
|
-
* pass's `flushPass`), inside the binding's `batch` with every other
|
|
89
|
+
* Called once, just before the Subject's first commit in a frame flush (not a Measure
|
|
90
|
+
* pass's `flushPass`), inside the binding's `batch` with every other Subject's switch that
|
|
85
91
|
* flush: a binding drops its Starting style from its `style` here,
|
|
86
92
|
* so its framework removes those keys and the commit writes the first frame in the same
|
|
87
|
-
* Refresh frame, with
|
|
93
|
+
* Refresh frame, with nothing drawn in between.
|
|
88
94
|
*/
|
|
89
95
|
readonly beforeFirstCommit?: (() => void) | undefined
|
|
90
96
|
/**
|
|
91
|
-
* Called with every key the gate now holds on the
|
|
97
|
+
* Called with every key the gate now holds on the Subject, each time that set changes: after the
|
|
92
98
|
* gate restores a key it dropped, and before the commit that first
|
|
93
|
-
* writes a key. A binding whose `style` reaches the
|
|
99
|
+
* writes a key. A binding whose `style` reaches the Subject leaves these keys out of it,
|
|
94
100
|
* so its framework never writes over Wardic's value (`style` is a key's fallback). Called in
|
|
95
|
-
* the binding's `batch`, with every other
|
|
96
|
-
* binding changes reaches the
|
|
101
|
+
* the binding's `batch`, with every other Subject's whose keys changed that flush, so what the
|
|
102
|
+
* binding changes reaches the Subject before the commit, a framework that applies an update later
|
|
97
103
|
* (Solid 2) included.
|
|
98
104
|
*/
|
|
99
105
|
// ADR-0034, *Amendment (#209)*.
|
|
100
106
|
readonly onHeld?: ((keys: ReadonlyArray<string>) => void) | undefined
|
|
101
107
|
/**
|
|
102
|
-
* Called once per frame in which the
|
|
108
|
+
* Called once per frame in which the Subject's values were committed, after every commit of that
|
|
103
109
|
* frame (Motion's `onUpdate`), with its values before
|
|
104
|
-
* projection (`x` as a number). The object is the
|
|
110
|
+
* projection (`x` as a number). The object is the Subject's own, reused each call: valid during
|
|
105
111
|
* the call, copied to keep. A Measure pass's commits are told at the frame flush after them, so
|
|
106
|
-
* a frame tells each
|
|
112
|
+
* a frame tells each Subject once. A write it makes is the next frame's. A throw is reported,
|
|
107
113
|
* and the others are still told.
|
|
108
114
|
*/
|
|
109
115
|
readonly onCommit?: ((values: Readonly<Record<string, unknown>>) => void) | undefined
|
|
110
116
|
}
|
|
111
117
|
|
|
112
|
-
/**
|
|
118
|
+
/**
|
|
119
|
+
* A flush's entries, in order, kept from one flush to the next (#895): `count` of them in use, the rest
|
|
120
|
+
* cleared. Emptied by its count, not `length = 0`, which V8 answers by dropping the array's storage, so it
|
|
121
|
+
* grew again every flush.
|
|
122
|
+
*/
|
|
123
|
+
interface EntryList {
|
|
124
|
+
readonly entries: Array<Entry | undefined>
|
|
125
|
+
count: number
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const entryListOf = (): EntryList => ({ entries: [], count: 0 })
|
|
129
|
+
|
|
130
|
+
/** `entry`, last in `list`. */
|
|
131
|
+
const addTo = (list: EntryList, entry: Entry): void => {
|
|
132
|
+
list.entries[list.count] = entry
|
|
133
|
+
list.count++
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** `list` cleared in place: its storage kept, its slots emptied, so it keeps no entry alive. */
|
|
137
|
+
const clear = (list: EntryList): void => {
|
|
138
|
+
for (let i = 0; i < list.count; i++) list.entries[i] = undefined
|
|
139
|
+
list.count = 0
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Accumulated pre-`project` state for one registered Subject. */
|
|
113
143
|
interface Entry {
|
|
144
|
+
/** Its gate id: what a failure of its own is reported with (#969). */
|
|
145
|
+
readonly id: string
|
|
146
|
+
/** What projects its values: its Renderer's projector, made for it, or else the Renderer's `project`. */
|
|
147
|
+
// #1030: its own, so a moving Subject's frames make no patch.
|
|
148
|
+
readonly projector: Projector.Projector
|
|
114
149
|
/** Merged value-map (partials `Object.assign`ed in by key). */
|
|
115
150
|
readonly values: Record<string, unknown>
|
|
116
|
-
/** Where this
|
|
151
|
+
/** Where this Subject's projected Patch goes. */
|
|
117
152
|
readonly sink: FlushSink
|
|
118
153
|
/** Whether a `write` has landed since the last flush. */
|
|
119
154
|
dirty: boolean
|
|
120
155
|
/**
|
|
121
|
-
* The keys the gate holds on the
|
|
156
|
+
* The keys the gate holds on the Subject: its last patch's, each with the Subject's own
|
|
122
157
|
* value from before the gate first wrote it (`""` for none), to restore when the
|
|
123
158
|
* key drops out.
|
|
124
159
|
*/
|
|
@@ -131,7 +166,14 @@ interface Entry {
|
|
|
131
166
|
* Whether its `onCommit` threw at its last call (#257 item 4): a run of throws is logged and
|
|
132
167
|
* reported at its first, so one that throws every frame logs once; a call that returns ends it.
|
|
133
168
|
*/
|
|
134
|
-
|
|
169
|
+
onCommitFailing: boolean
|
|
170
|
+
/**
|
|
171
|
+
* Whether one of its own steps threw at a flush since its last commit (#969): a run of them is reported
|
|
172
|
+
* at its first, so one that throws every frame logs once; a commit that lands ends it.
|
|
173
|
+
*/
|
|
174
|
+
stepFailing: boolean
|
|
175
|
+
/** Whether its sink's `onHeld` threw before it heard the keys held (#969): its next flush tells it again. */
|
|
176
|
+
heldUntold: boolean
|
|
135
177
|
/** Its patch, projected this flush and committed once the binding has heard the keys held. */
|
|
136
178
|
patch: Renderer.Patch | undefined
|
|
137
179
|
}
|
|
@@ -141,6 +183,8 @@ interface Output {
|
|
|
141
183
|
readonly atom: Atom.Writable<unknown>
|
|
142
184
|
last: unknown
|
|
143
185
|
readonly unmount: () => void
|
|
186
|
+
/** Whether its sets are throwing back a dependent's failure: reported at the first, again after a clean set. */
|
|
187
|
+
failing: boolean
|
|
144
188
|
}
|
|
145
189
|
|
|
146
190
|
/** What the gate calls of a key's Timeline value (#240): its sync with the values drawn, and its cancel. */
|
|
@@ -153,7 +197,7 @@ export interface GateTimeline {
|
|
|
153
197
|
/**
|
|
154
198
|
* What the gate reads of its Environment's targets, and what it keeps from a sink: a target's value
|
|
155
199
|
* for a key before the gate first writes it there (`""` for none), which it gives back at the key's
|
|
156
|
-
* release, and the key its Renderer reserves for
|
|
200
|
+
* release, and the key its Renderer reserves for a Subject's Transform template, which `onCommit`
|
|
157
201
|
* never sees.
|
|
158
202
|
*/
|
|
159
203
|
// #672 (PR2-Q1): the gate's two edges of its Environment, given by `FlushGate.make`, its only builder,
|
|
@@ -163,23 +207,26 @@ export interface GateEnvironment {
|
|
|
163
207
|
readonly templateKey: string
|
|
164
208
|
}
|
|
165
209
|
|
|
210
|
+
/** A step of one Subject's flush, as its failure is reported (#969): `prepare`'s report as its commit. */
|
|
211
|
+
type Step = "a commit" | "a beforeFirstCommit" | "an onHeld" | "a Timeline sync"
|
|
212
|
+
|
|
166
213
|
/** Each of `values` cancelled (#240). Per flush: a plain loop. */
|
|
167
214
|
const cancelEach = (values: Iterable<GateTimeline>): void => {
|
|
168
215
|
for (const value of values) value.cancel()
|
|
169
216
|
}
|
|
170
217
|
|
|
171
|
-
/** A Flush gate: what a binding registers its
|
|
218
|
+
/** A Flush gate: what a binding registers its Subjects with and writes their values into, one per provider. */
|
|
172
219
|
export interface FlushGate {
|
|
173
220
|
/**
|
|
174
|
-
* Register
|
|
175
|
-
* that removes the
|
|
221
|
+
* Register a Subject under `id` with its `sink`. Returns an unregister fn
|
|
222
|
+
* that removes the Subject from the accumulator (a subsequent `write` is a
|
|
176
223
|
* no-op). `values` start its value-map, unflushed: drawn with its first `write`, so they never
|
|
177
224
|
* commit alone.
|
|
178
225
|
*/
|
|
179
226
|
// #443: its Transform template, which mustn't take its Starting style off early.
|
|
180
227
|
readonly register: (id: string, sink: FlushSink, values?: Readonly<Record<string, unknown>>) => () => void
|
|
181
228
|
/**
|
|
182
|
-
* Merge `partial` into the
|
|
229
|
+
* Merge `partial` into the Subject's value-map by key, mark it dirty, and
|
|
183
230
|
* schedule a flush: the end of the Frame loop's tick, for a write made in one, or else the
|
|
184
231
|
* next Refresh frame. A `write` for an unregistered (or unregistered-since) id
|
|
185
232
|
* is a no-op.
|
|
@@ -191,13 +238,13 @@ export interface FlushGate {
|
|
|
191
238
|
* `pass()` runs are recorded; each recorded entry is `project`ed and committed once, and
|
|
192
239
|
* marked clean. Everything else stays dirty for its flush. A write made by an effect a sink's
|
|
193
240
|
* hook runs (a Solid effect) takes the ordinary path. The Projection system calls it at the
|
|
194
|
-
* end of a task, so a new layout never
|
|
241
|
+
* end of a task, so a new layout is never drawn without its projection.
|
|
195
242
|
*/
|
|
196
243
|
readonly flushPass: (pass: () => void) => void
|
|
197
244
|
/**
|
|
198
|
-
* Hand `keys` back to the
|
|
245
|
+
* Hand `keys` back to the Subject's own style: drop each from the Subject's
|
|
199
246
|
* value-map and schedule a flush, which writes `restore[key]` (its Environment's text form) for a key it had
|
|
200
|
-
* written, or else the
|
|
247
|
+
* written, or else the Subject's own value it overwrote, and tells the sink (`onHeld`). A key the
|
|
201
248
|
* entry doesn't hold, or an unknown id, is a no-op. A binding releases a key back at its `style`
|
|
202
249
|
* value, so a later `style` change shows at rest. A later `write` brings the key back. A property in
|
|
203
250
|
* `keep` (`transform` for its keys) is left as it's drawn when it drops out: another writer draws it next.
|
|
@@ -205,28 +252,28 @@ export interface FlushGate {
|
|
|
205
252
|
// `keep`: #665's PR 4, a Batch member's group handed back to its Batch, whose writer draws it from then on.
|
|
206
253
|
readonly release: (id: string, keys: ReadonlyArray<string>, restore?: Readonly<Record<string, string>>, keep?: ReadonlyArray<string>) => void
|
|
207
254
|
/**
|
|
208
|
-
* The
|
|
255
|
+
* The Subject's value for `id`'s `key`, live: an `Atom` set as each write that
|
|
209
256
|
* changes it lands, so it's the value the next commit draws, before the Renderer projects it
|
|
210
257
|
* (`x` as a number, not a `transform`). Set at the write, not the commit, so a value derived
|
|
211
258
|
* from it (another key following it through a binding) is written in the same frame and
|
|
212
259
|
* commits with it. `undefined` before the key's first write, and once it's released or the
|
|
213
|
-
*
|
|
260
|
+
* Subject unregisters. One Atom for an id and a key, made on first ask, so per frame only the
|
|
214
261
|
* keys asked for cost anything.
|
|
215
262
|
*/
|
|
216
263
|
readonly valueOf: (id: string, key: string) => Atom.Atom<unknown>
|
|
217
264
|
/**
|
|
218
|
-
* Run `key`'s Timeline value on `id`'s
|
|
265
|
+
* Run `key`'s Timeline value on `id`'s Subject (#240), or stop it (`undefined`): a binding sets one
|
|
219
266
|
* while the key shows its Live value, and clears it when an entry of the Override stack takes the
|
|
220
|
-
* key. The gate goes on writing the key: at each flush that commits the
|
|
267
|
+
* key. The gate goes on writing the key: at each flush that commits the Subject, before the commit,
|
|
221
268
|
* it starts the value's animation over it, or cancels it while something else adds to its property
|
|
222
269
|
* (a projection, a Transform template, another transform key off its identity), so a frame shows one
|
|
223
270
|
* or the other. A cleared or replaced one is cancelled at the next flush; a released key's, an
|
|
224
|
-
* unregistered
|
|
271
|
+
* unregistered Subject's and a disposed gate's, at once. Setting one schedules a flush.
|
|
225
272
|
*/
|
|
226
273
|
readonly timeline: (id: string, key: string, timeline: GateTimeline | undefined) => void
|
|
227
274
|
/**
|
|
228
275
|
* Call `fn` once, after the gate's next flush: the end of the Frame loop's tick, for a call
|
|
229
|
-
* made in one, else the next Refresh frame's, so what was written before it is on the
|
|
276
|
+
* made in one, else the next Refresh frame's, so what was written before it is on the Subjects.
|
|
230
277
|
* It schedules that flush if none is pending. A binding tells an animation's end here, as Motion's
|
|
231
278
|
* `onAnimationComplete` comes with the final value set. One that throws is reported, and the rest
|
|
232
279
|
* still run.
|
|
@@ -241,7 +288,7 @@ export interface FlushGate {
|
|
|
241
288
|
// #672: named here, as dom's `FlushGate` names it, so the spine reads the gate's own types in core.
|
|
242
289
|
export type Shape = Omit<FlushGate, "dispose">
|
|
243
290
|
|
|
244
|
-
/**
|
|
291
|
+
/** A Subject's commit target and hooks, given to `register`. */
|
|
245
292
|
export type Sink = FlushSink
|
|
246
293
|
|
|
247
294
|
/** What a flush gate needs from its Environment: the `Renderer`, the Frame loop it flushes at the end of each tick of, and the `RefreshFrameSource`. */
|
|
@@ -263,11 +310,11 @@ export interface FlushGateRuntime {
|
|
|
263
310
|
export interface FlushGateOptions {
|
|
264
311
|
/**
|
|
265
312
|
* Runs a flush's hooks together: calls `apply`, and returns once every update inside it has reached
|
|
266
|
-
* the
|
|
313
|
+
* the Subjects, before the gate commits. Solid 1 passes its `batch`, Solid 2 runs `apply` then
|
|
267
314
|
* `flush()`, and React would pass `flushSync`, untried; a binding with nothing to batch passes
|
|
268
315
|
* `(apply) => apply()`. Called at most twice a flush: once for the starting-style switches
|
|
269
|
-
* (`beforeFirstCommit`) of the
|
|
270
|
-
*
|
|
316
|
+
* (`beforeFirstCommit`) of the Subjects committing for the first time, before anything is read off the
|
|
317
|
+
* Subjects; and once for the held keys (`onHeld`) of the Subjects whose held keys changed.
|
|
271
318
|
*/
|
|
272
319
|
// ADR-0031, decision 3, ADR-0034; *Amendment (#209)*.
|
|
273
320
|
readonly batch: (apply: () => void) => void
|
|
@@ -278,7 +325,8 @@ export interface FlushGateOptions {
|
|
|
278
325
|
* switches through the binding's `batch`.
|
|
279
326
|
*
|
|
280
327
|
* Resolves both ONCE here: `project` is pure and `commit` a plain call (both called directly at
|
|
281
|
-
* flush, ADR-0034),
|
|
328
|
+
* flush, ADR-0034), and a Renderer's projector maker makes each Subject's projector as it registers;
|
|
329
|
+
* `requestFrame` /
|
|
282
330
|
* `cancelFrame` schedule and cancel the flush of a write made outside a tick, and the Frame
|
|
283
331
|
* loop's `afterTick` takes the gate's hook for its lifetime. All come from whichever env the
|
|
284
332
|
* provider was given (`DomLive` / `TestLive`), so the gate inherits that environment's
|
|
@@ -291,14 +339,16 @@ export const makeFlushGate = (runtime: FlushGateRuntime, options: FlushGateOptio
|
|
|
291
339
|
// `requestFrame` and `cancelFrame` are called detached, never as `frames.requestFrame(cb)`: a
|
|
292
340
|
// browser throws "Illegal invocation" when `requestAnimationFrame` runs with `this` bound to
|
|
293
341
|
// anything but the window (ADR-0031, decision 7).
|
|
294
|
-
const { commit, project, requestFrame, cancelFrame, afterTick } = runtime.runSync(
|
|
342
|
+
const { commit, project, maker, requestFrame, cancelFrame, afterTick } = runtime.runSync(
|
|
295
343
|
Effect.gen(function* () {
|
|
296
|
-
const
|
|
344
|
+
const renderer = yield* Renderer.Renderer
|
|
297
345
|
const { requestFrame, cancelFrame } = yield* RefreshFrameSource.RefreshFrameSource
|
|
298
346
|
const { afterTick } = yield* FrameLoop.FrameLoop
|
|
299
|
-
return { commit, project, requestFrame, cancelFrame, afterTick }
|
|
347
|
+
return { commit: renderer.commit, project: renderer.project, maker: Projector.makerOf(renderer), requestFrame, cancelFrame, afterTick }
|
|
300
348
|
}),
|
|
301
349
|
)
|
|
350
|
+
// What makes a new Subject's projector, at its register: its Renderer's maker, or the Renderer's `project` for all.
|
|
351
|
+
const projectorOf: Projector.Make = Option.getOrElse(maker, () => () => project)
|
|
302
352
|
|
|
303
353
|
const accumulator = new Map<string, Entry>()
|
|
304
354
|
// Every live output asked for (`valueOf`), by id: an entry registered later picks its map up.
|
|
@@ -315,26 +365,26 @@ export const makeFlushGate = (runtime: FlushGateRuntime, options: FlushGateOptio
|
|
|
315
365
|
let recording: Set<string> | undefined
|
|
316
366
|
// The entries committed since the last frame flush whose sink has an `onCommit` (#233).
|
|
317
367
|
const committedSince = new Set<Entry>()
|
|
318
|
-
// Each
|
|
319
|
-
// its next: only the
|
|
368
|
+
// Each Subject's Timeline values by key (#240), and those let go of since its last flush, cancelled at
|
|
369
|
+
// its next: only the Subjects that have one, so the per-frame path checks their sizes alone.
|
|
320
370
|
const timelines = new Map<Entry, Map<string, GateTimeline>>()
|
|
321
371
|
const endings = new Map<Entry, Array<GateTimeline>>()
|
|
322
372
|
// A frame flush's entries, in order, prepared and waiting for their commit; and those whose
|
|
323
373
|
// keys held changed, which the binding hears first. Reused each flush: the per-frame path.
|
|
324
|
-
const prepared
|
|
325
|
-
const heldChanged
|
|
374
|
+
const prepared = entryListOf()
|
|
375
|
+
const heldChanged = entryListOf()
|
|
326
376
|
|
|
327
377
|
/**
|
|
328
|
-
* Project one dirty entry's patch and restore the keys it dropped (once per
|
|
378
|
+
* Project one dirty entry's patch and restore the keys it dropped (once per Subject per flush),
|
|
329
379
|
* marking it clean: into `into`, and into `held` when the keys it holds change and its sink
|
|
330
380
|
* hears them. Its commit waits for the binding's `batch` of those (ADR-0034, *Amendment
|
|
331
381
|
* (#209)*). Plain calls only: this is the per-frame path.
|
|
332
382
|
*/
|
|
333
|
-
const prepare = (entry: Entry, into:
|
|
334
|
-
const patch =
|
|
383
|
+
const prepare = (entry: Entry, into: EntryList, held: EntryList): void => {
|
|
384
|
+
const patch = entry.projector(entry.values)
|
|
335
385
|
entry.dirty = false
|
|
336
386
|
entry.patch = patch
|
|
337
|
-
into
|
|
387
|
+
addTo(into, entry)
|
|
338
388
|
const sink = entry.sink
|
|
339
389
|
const target = sink.target
|
|
340
390
|
const committed = entry.committed
|
|
@@ -349,7 +399,7 @@ export const makeFlushGate = (runtime: FlushGateRuntime, options: FlushGateOptio
|
|
|
349
399
|
committed.set(key, valueBeforeOf(target, key))
|
|
350
400
|
added = true
|
|
351
401
|
}
|
|
352
|
-
// A key the last patch wrote and this one doesn't: the
|
|
402
|
+
// A key the last patch wrote and this one doesn't: the Subject gets its own value
|
|
353
403
|
// back. Only looked for when one dropped out (the usual frame keeps every key).
|
|
354
404
|
let restore: Renderer.Patch | undefined
|
|
355
405
|
if (kept < before) {
|
|
@@ -357,33 +407,48 @@ export const makeFlushGate = (runtime: FlushGateRuntime, options: FlushGateOptio
|
|
|
357
407
|
if (key in patch) continue
|
|
358
408
|
if (Predicate.isUndefined(restore)) restore = {}
|
|
359
409
|
restore[key] = own
|
|
360
|
-
committed.delete(key)
|
|
361
410
|
}
|
|
362
411
|
}
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
412
|
+
// Committed before its keys are let go of, so a restore that throws is tried again at the next flush (#969).
|
|
413
|
+
if (Predicate.isNotUndefined(restore)) {
|
|
414
|
+
commit(target, restore)
|
|
415
|
+
for (const key in restore) committed.delete(key)
|
|
416
|
+
}
|
|
417
|
+
// The keys held changed (the usual frame changes none), or its sink threw before it heard them: the
|
|
418
|
+
// binding hears before the commit.
|
|
419
|
+
if ((added || Predicate.isNotUndefined(restore) || entry.heldUntold) && Predicate.isNotUndefined(sink.onHeld)) addTo(held, entry)
|
|
366
420
|
}
|
|
367
421
|
|
|
368
422
|
/**
|
|
369
|
-
* Before a flush's commits (#240): cancel the Timeline values each
|
|
423
|
+
* Before a flush's commits (#240): cancel the Timeline values each Subject committing now let go of,
|
|
370
424
|
* and sync the rest with its values, so each starts or stops as nothing else adds to its property.
|
|
371
425
|
* An entry is committing while it holds a prepared patch. Kept beside the entries, not on them, so an
|
|
372
|
-
*
|
|
426
|
+
* Subject with none pays nothing per frame: the flush checks two sizes. Per flush: plain loops.
|
|
373
427
|
*/
|
|
374
428
|
const syncTimelines = (): void => {
|
|
375
429
|
for (const [entry, ended] of endings) {
|
|
376
430
|
if (Predicate.isUndefined(entry.patch)) continue
|
|
377
431
|
endings.delete(entry)
|
|
378
|
-
|
|
432
|
+
// Each on its own: one whose cancel throws stops none of the others (#969).
|
|
433
|
+
for (let i = 0; i < ended.length; i++) {
|
|
434
|
+
try {
|
|
435
|
+
ended[i].cancel()
|
|
436
|
+
} catch (defect) {
|
|
437
|
+
failedAt(entry, "a Timeline sync", defect)
|
|
438
|
+
}
|
|
439
|
+
}
|
|
379
440
|
}
|
|
380
441
|
for (const [entry, byKey] of timelines) {
|
|
381
442
|
if (Predicate.isUndefined(entry.patch)) continue
|
|
382
|
-
|
|
443
|
+
try {
|
|
444
|
+
for (const value of byKey.values()) value.sync(entry.values)
|
|
445
|
+
} catch (defect) {
|
|
446
|
+
failedAt(entry, "a Timeline sync", defect)
|
|
447
|
+
}
|
|
383
448
|
}
|
|
384
449
|
}
|
|
385
450
|
|
|
386
|
-
/** Every Timeline value of `entry`, cancelled at once: its
|
|
451
|
+
/** Every Timeline value of `entry`, cancelled at once: its Subject is gone, or the gate is. */
|
|
387
452
|
const cancelTimelines = (entry: Entry): void => {
|
|
388
453
|
const ended = endings.get(entry)
|
|
389
454
|
endings.delete(entry)
|
|
@@ -393,32 +458,66 @@ export const makeFlushGate = (runtime: FlushGateRuntime, options: FlushGateOptio
|
|
|
393
458
|
if (Predicate.isNotUndefined(byKey)) cancelEach(byKey.values())
|
|
394
459
|
}
|
|
395
460
|
|
|
396
|
-
/** Commit a prepared entry's patch onto its
|
|
461
|
+
/** Commit a prepared entry's patch onto its Subject. */
|
|
397
462
|
const commitPrepared = (entry: Entry): void => {
|
|
398
463
|
const patch = entry.patch
|
|
399
464
|
if (Predicate.isUndefined(patch)) return
|
|
400
465
|
entry.patch = undefined
|
|
401
466
|
commit(entry.sink.target, patch)
|
|
467
|
+
if (entry.stepFailing) entry.stepFailing = false
|
|
402
468
|
if (Predicate.isNotUndefined(entry.sink.onCommit)) committedSince.add(entry)
|
|
403
469
|
}
|
|
404
470
|
|
|
471
|
+
/**
|
|
472
|
+
* One of `entry`'s steps threw this flush (#969): its later steps skipped this frame, its patch with
|
|
473
|
+
* them, and the other Subjects' going on. A run of them is reported at its first, `step` naming it.
|
|
474
|
+
*/
|
|
475
|
+
// A failure's path, never the frame's: one place each loop's catch calls.
|
|
476
|
+
const failedAt = (entry: Entry, step: Step, defect: unknown): void => {
|
|
477
|
+
entry.patch = undefined
|
|
478
|
+
// Tried again at the gate's next flush, which it doesn't ask for itself: a Subject frozen for good would
|
|
479
|
+
// keep the host's frames running. A later write, its own or another Subject's, brings that flush.
|
|
480
|
+
entry.dirty = true
|
|
481
|
+
// Its sink's `onCommit` hears nothing of a frame it didn't commit in.
|
|
482
|
+
committedSince.delete(entry)
|
|
483
|
+
if (entry.stepFailing) return
|
|
484
|
+
entry.stepFailing = true
|
|
485
|
+
runtime.runFork(Effect.annotateLogs(Report.failure(`wardic.gate: ${step} failed`, Cause.die(defect)), { id: entry.id }))
|
|
486
|
+
}
|
|
487
|
+
|
|
405
488
|
/**
|
|
406
489
|
* The prepared entries, committed, after the binding has heard the keys held change, together, in
|
|
407
490
|
* its `batch` (#209); both lists emptied for the next flush.
|
|
408
491
|
*/
|
|
409
|
-
const commitAll = (entries:
|
|
410
|
-
if (held.
|
|
411
|
-
for (
|
|
412
|
-
entries.
|
|
413
|
-
|
|
492
|
+
const commitAll = (entries: EntryList, held: EntryList): void => {
|
|
493
|
+
if (held.count > 0) batch(() => tellHeld(held))
|
|
494
|
+
// A try for each Subject, its call direct (#969): a shared helper taking the step measured +20% a frame.
|
|
495
|
+
for (let i = 0; i < entries.count; i++) {
|
|
496
|
+
const entry = entries.entries[i] as Entry
|
|
497
|
+
try {
|
|
498
|
+
commitPrepared(entry)
|
|
499
|
+
} catch (defect) {
|
|
500
|
+
failedAt(entry, "a commit", defect)
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
clear(entries)
|
|
504
|
+
clear(held)
|
|
414
505
|
}
|
|
415
506
|
|
|
416
|
-
/** Each entry's `onHeld`, with every key the gate holds on its
|
|
417
|
-
const tellHeld = (held:
|
|
418
|
-
for (let i = 0; i < held.
|
|
419
|
-
const entry = held[i]
|
|
507
|
+
/** Each entry's `onHeld`, with every key the gate holds on its Subject now. */
|
|
508
|
+
const tellHeld = (held: EntryList): void => {
|
|
509
|
+
for (let i = 0; i < held.count; i++) {
|
|
510
|
+
const entry = held.entries[i] as Entry
|
|
420
511
|
const onHeld = entry.sink.onHeld
|
|
421
|
-
if (Predicate.
|
|
512
|
+
if (Predicate.isUndefined(onHeld)) continue
|
|
513
|
+
try {
|
|
514
|
+
onHeld(Array.from(entry.committed.keys()))
|
|
515
|
+
if (entry.heldUntold) entry.heldUntold = false
|
|
516
|
+
} catch (defect) {
|
|
517
|
+
// Told again at its next flush, before its commit (#969).
|
|
518
|
+
entry.heldUntold = true
|
|
519
|
+
failedAt(entry, "an onHeld", defect)
|
|
520
|
+
}
|
|
422
521
|
}
|
|
423
522
|
}
|
|
424
523
|
|
|
@@ -441,10 +540,10 @@ export const makeFlushGate = (runtime: FlushGateRuntime, options: FlushGateOptio
|
|
|
441
540
|
delete latest[templateKey]
|
|
442
541
|
try {
|
|
443
542
|
onCommit(latest)
|
|
444
|
-
entry.
|
|
543
|
+
entry.onCommitFailing = false
|
|
445
544
|
} catch (defect) {
|
|
446
|
-
if (entry.
|
|
447
|
-
entry.
|
|
545
|
+
if (entry.onCommitFailing) continue
|
|
546
|
+
entry.onCommitFailing = true
|
|
448
547
|
runtime.runFork(Report.failure("wardic.gate: an onCommit failed", Cause.die(defect)))
|
|
449
548
|
}
|
|
450
549
|
}
|
|
@@ -457,6 +556,9 @@ export const makeFlushGate = (runtime: FlushGateRuntime, options: FlushGateOptio
|
|
|
457
556
|
* written in the same frame, and commits with it. An unchanged one skips the registry. Plain
|
|
458
557
|
* calls: a write is the per-frame path.
|
|
459
558
|
*/
|
|
559
|
+
// #979, group D (ADR-0074): an output's dependent that throws (an app's Atom over a ward's `read(key)`)
|
|
560
|
+
// is its own. The registry has set the output and told its other listeners before the throw comes back,
|
|
561
|
+
// so the write goes on, the Subject's other outputs with it: before, it came out of the ward's own leg.
|
|
460
562
|
const setOutputs = (entry: Entry): void => {
|
|
461
563
|
const outputs = entry.outputs
|
|
462
564
|
if (Predicate.isUndefined(outputs)) return
|
|
@@ -464,7 +566,20 @@ export const makeFlushGate = (runtime: FlushGateRuntime, options: FlushGateOptio
|
|
|
464
566
|
const value = entry.values[key]
|
|
465
567
|
if (value === output.last) continue
|
|
466
568
|
output.last = value
|
|
569
|
+
setOutput(entry.id, key, output, value)
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
/** `output` set to `value`, its dependent's throw its own: reported once a run of throws, until a clean set. */
|
|
574
|
+
// The try is here, out of the loops that call it (`setOutputs`', `endOutputs`'): in the body of
|
|
575
|
+
// `setOutputs`' loop over the Subject's outputs Map, it measured +5–8% on Node's write.
|
|
576
|
+
const setOutput = (id: string, key: string, output: Output, value: unknown): void => {
|
|
577
|
+
try {
|
|
467
578
|
registry.set(output.atom, value)
|
|
579
|
+
if (output.failing) output.failing = false
|
|
580
|
+
} catch (defect) {
|
|
581
|
+
if (!output.failing) runtime.runFork(Effect.annotateLogs(Report.failure("wardic.gate: an output failed", Cause.die(defect)), { id, key }))
|
|
582
|
+
output.failing = true
|
|
468
583
|
}
|
|
469
584
|
}
|
|
470
585
|
|
|
@@ -477,26 +592,41 @@ export const makeFlushGate = (runtime: FlushGateRuntime, options: FlushGateOptio
|
|
|
477
592
|
for (const id of firstCommits) {
|
|
478
593
|
const entry = accumulator.get(id)
|
|
479
594
|
if (Predicate.isUndefined(entry) || !entry.dirty) continue
|
|
480
|
-
firstCommits.delete(id)
|
|
481
595
|
const hook = entry.sink.beforeFirstCommit
|
|
482
|
-
|
|
596
|
+
try {
|
|
597
|
+
if (Predicate.isNotUndefined(hook)) hook()
|
|
598
|
+
// Its own: a hook that registered the id again leaves the new entry's switch to come (#969).
|
|
599
|
+
if (accumulator.get(id) === entry) firstCommits.delete(id)
|
|
600
|
+
} catch (defect) {
|
|
601
|
+
// Kept, so the gate's next flush switches it; nothing of it commits before (#969).
|
|
602
|
+
failedAt(entry, "a beforeFirstCommit", defect)
|
|
603
|
+
}
|
|
483
604
|
}
|
|
484
605
|
}
|
|
485
606
|
|
|
486
607
|
const flush = (): void => {
|
|
487
608
|
scheduled = false
|
|
488
609
|
try {
|
|
489
|
-
// The switches first:
|
|
610
|
+
// The switches first: a Subject's own values are read once its Starting style is gone.
|
|
490
611
|
if (firstCommits.size > 0) batch(runFirstCommits)
|
|
491
|
-
// Every dirty
|
|
612
|
+
// Every dirty Subject, once. No auto-reschedule — the next write() does. A write()
|
|
492
613
|
// from an effect a sink's hook runs requests the next frame (it isn't stranded).
|
|
493
|
-
for (const entry of accumulator.values())
|
|
614
|
+
for (const entry of accumulator.values()) {
|
|
615
|
+
if (!entry.dirty) continue
|
|
616
|
+
// Its Starting-style switch threw this frame: it waits for the next flush's (#969).
|
|
617
|
+
if (firstCommits.size > 0 && firstCommits.has(entry.id)) continue
|
|
618
|
+
try {
|
|
619
|
+
prepare(entry, prepared, heldChanged)
|
|
620
|
+
} catch (defect) {
|
|
621
|
+
failedAt(entry, "a commit", defect)
|
|
622
|
+
}
|
|
623
|
+
}
|
|
494
624
|
if (timelines.size > 0 || endings.size > 0) syncTimelines()
|
|
495
625
|
commitAll(prepared, heldChanged)
|
|
496
626
|
if (committedSince.size > 0) tellCommitted()
|
|
497
627
|
} catch (defect) {
|
|
498
|
-
prepared
|
|
499
|
-
heldChanged
|
|
628
|
+
clear(prepared)
|
|
629
|
+
clear(heldChanged)
|
|
500
630
|
runtime.runFork(Report.failure("wardic.gate: a flush failed", Cause.die(defect)))
|
|
501
631
|
}
|
|
502
632
|
if (afterFlushes.length > 0) runAfterFlushes()
|
|
@@ -544,8 +674,12 @@ export const makeFlushGate = (runtime: FlushGateRuntime, options: FlushGateOptio
|
|
|
544
674
|
dirty: false,
|
|
545
675
|
committed: new Map(),
|
|
546
676
|
outputs: outputsById.get(id),
|
|
677
|
+
id,
|
|
678
|
+
projector: projectorOf(),
|
|
547
679
|
latest: undefined,
|
|
548
|
-
|
|
680
|
+
onCommitFailing: false,
|
|
681
|
+
stepFailing: false,
|
|
682
|
+
heldUntold: false,
|
|
549
683
|
patch: undefined,
|
|
550
684
|
}
|
|
551
685
|
// An entry the id had: its Timeline values end with it (#240).
|
|
@@ -562,13 +696,16 @@ export const makeFlushGate = (runtime: FlushGateRuntime, options: FlushGateOptio
|
|
|
562
696
|
}
|
|
563
697
|
}
|
|
564
698
|
|
|
565
|
-
/** `id`'s live outputs, each set to `undefined` and forgotten: its
|
|
699
|
+
/** `id`'s live outputs, each set to `undefined` and forgotten: its Subject is gone. */
|
|
700
|
+
// #979, row 42 (ADR-0074): set through `setOutput`, so a dependent that throws as its Subject leaves is
|
|
701
|
+
// reported, and every output still ends: before, its throw came out of the unregister, a binding's
|
|
702
|
+
// cleanup, and left that output and the later ones mounted.
|
|
566
703
|
const endOutputs = (id: string): void => {
|
|
567
704
|
const outputs = outputsById.get(id)
|
|
568
705
|
if (Predicate.isUndefined(outputs)) return
|
|
569
706
|
outputsById.delete(id)
|
|
570
|
-
for (const output of outputs
|
|
571
|
-
|
|
707
|
+
for (const [key, output] of outputs) {
|
|
708
|
+
setOutput(id, key, output, undefined)
|
|
572
709
|
output.unmount()
|
|
573
710
|
}
|
|
574
711
|
}
|
|
@@ -590,10 +727,10 @@ export const makeFlushGate = (runtime: FlushGateRuntime, options: FlushGateOptio
|
|
|
590
727
|
}
|
|
591
728
|
const known = outputs.get(key)
|
|
592
729
|
if (Predicate.isNotUndefined(known)) return known.atom
|
|
593
|
-
// Made `undefined` and mounted until its
|
|
730
|
+
// Made `undefined` and mounted until its Subject unregisters, not kept alive: a kept-alive
|
|
594
731
|
// Atom's node never leaves the registry, and one left behind reads `undefined` afresh.
|
|
595
732
|
const atom = Atom.make<unknown>(undefined)
|
|
596
|
-
const output: Output = { atom, last: undefined, unmount: registry.mount(atom) }
|
|
733
|
+
const output: Output = { atom, last: undefined, unmount: registry.mount(atom), failing: false }
|
|
597
734
|
outputs.set(key, output)
|
|
598
735
|
const value = committedValueOf(id, key)
|
|
599
736
|
if (Predicate.isNotUndefined(value)) {
|
|
@@ -624,14 +761,19 @@ export const makeFlushGate = (runtime: FlushGateRuntime, options: FlushGateOptio
|
|
|
624
761
|
if (written.size === 0) return
|
|
625
762
|
// No `beforeFirstCommit` here: a Measure pass may write only a node's projection, and
|
|
626
763
|
// dropping the Starting style then would leave its animated keys unset until the frame
|
|
627
|
-
// flush (a frame later for
|
|
764
|
+
// flush (a frame later for a Subject mounted inside a frame). The frame flush switches.
|
|
628
765
|
// A commit here is told at the frame flush (#233): the write that made it scheduled that flush.
|
|
629
766
|
// Its own lists: a pass may run from a hook the frame flush's `batch` runs.
|
|
630
|
-
const entries
|
|
631
|
-
const held
|
|
767
|
+
const entries = entryListOf()
|
|
768
|
+
const held = entryListOf()
|
|
632
769
|
for (const id of written) {
|
|
633
770
|
const entry = accumulator.get(id)
|
|
634
|
-
if (Predicate.
|
|
771
|
+
if (Predicate.isUndefined(entry) || !entry.dirty) continue
|
|
772
|
+
try {
|
|
773
|
+
prepare(entry, entries, held)
|
|
774
|
+
} catch (defect) {
|
|
775
|
+
failedAt(entry, "a commit", defect)
|
|
776
|
+
}
|
|
635
777
|
}
|
|
636
778
|
if (timelines.size > 0 || endings.size > 0) syncTimelines()
|
|
637
779
|
commitAll(entries, held)
|
|
@@ -659,13 +801,13 @@ export const makeFlushGate = (runtime: FlushGateRuntime, options: FlushGateOptio
|
|
|
659
801
|
}
|
|
660
802
|
byKey.set(key, value)
|
|
661
803
|
}
|
|
662
|
-
//
|
|
804
|
+
// A Subject left with none leaves the map, so the flush skips it.
|
|
663
805
|
if (Predicate.isNotUndefined(byKey) && byKey.size === 0) timelines.delete(entry)
|
|
664
806
|
entry.dirty = true
|
|
665
807
|
scheduleFlush()
|
|
666
808
|
}
|
|
667
809
|
|
|
668
|
-
/** `entry`'s Timeline values for `keys`, cancelled at once: those keys go back to the
|
|
810
|
+
/** `entry`'s Timeline values for `keys`, cancelled at once: those keys go back to the Subject's own style. */
|
|
669
811
|
const releaseTimelines = (entry: Entry, keys: ReadonlyArray<string>): void => {
|
|
670
812
|
const byKey = timelines.get(entry)
|
|
671
813
|
if (Predicate.isUndefined(byKey)) return
|