@wardic/core 1.3.2 → 1.5.0-next.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 +15 -5
- package/dist/Batch.d.ts.map +1 -1
- package/dist/Batch.js +218 -20
- package/dist/Batch.js.map +1 -1
- package/dist/Clock.d.ts +7 -7
- package/dist/Clock.d.ts.map +1 -1
- package/dist/Clock.js +17 -16
- 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 +8 -6
- package/dist/DragRecognizer.d.ts.map +1 -1
- package/dist/DragRecognizer.js +51 -16
- 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 +1 -1
- package/dist/InputFeed.js +2 -2
- package/dist/InputSource.d.ts +9 -3
- package/dist/InputSource.d.ts.map +1 -1
- package/dist/InputSource.js +2 -2
- package/dist/InputSource.js.map +1 -1
- 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 +7 -6
- package/dist/LiveValue.d.ts.map +1 -1
- package/dist/LiveValue.js +45 -14
- package/dist/LiveValue.js.map +1 -1
- package/dist/Machine.d.ts +7 -4
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +146 -45
- package/dist/Machine.js.map +1 -1
- package/dist/Playback.d.ts.map +1 -1
- package/dist/Playback.js +6 -1
- package/dist/Playback.js.map +1 -1
- package/dist/Projection.d.ts +8 -19
- package/dist/Projection.d.ts.map +1 -1
- package/dist/Projection.js +3 -19
- package/dist/Projection.js.map +1 -1
- package/dist/Recognizer.d.ts +1 -1
- package/dist/Recognizer.d.ts.map +1 -1
- package/dist/Recognizer.js +22 -7
- 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 +12 -2
- package/dist/Reorder.d.ts.map +1 -1
- package/dist/Reorder.js +65 -37
- 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 +1 -1
- package/dist/internal/frameLoop.d.ts.map +1 -1
- package/dist/internal/frameLoop.js +102 -81
- package/dist/internal/frameLoop.js.map +1 -1
- 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/projectionRest.d.ts +22 -0
- package/dist/internal/projectionRest.d.ts.map +1 -0
- package/dist/internal/projectionRest.js +20 -0
- package/dist/internal/projectionRest.js.map +1 -0
- package/dist/internal/stepper.d.ts +13 -2
- package/dist/internal/stepper.d.ts.map +1 -1
- package/dist/internal/stepper.js +16 -1
- 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 +37 -38
- package/dist/unstable/AnimationControls.d.ts.map +1 -1
- package/dist/unstable/AnimationControls.js +39 -36
- package/dist/unstable/AnimationControls.js.map +1 -1
- package/dist/unstable/AppearHandoff.d.ts +5 -5
- package/dist/unstable/AppearHandoff.d.ts.map +1 -1
- package/dist/unstable/BatchCalls.d.ts +2 -2
- package/dist/unstable/BatchCalls.js +5 -5
- package/dist/unstable/Config.d.ts +19 -19
- package/dist/unstable/Config.d.ts.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 +53 -51
- package/dist/unstable/FlushGate.d.ts.map +1 -1
- package/dist/unstable/FlushGate.js +56 -49
- package/dist/unstable/FlushGate.js.map +1 -1
- package/dist/unstable/FrameEffects.d.ts +2 -2
- package/dist/unstable/FrameEffects.js +2 -2
- package/dist/unstable/FrameTime.d.ts +1 -1
- package/dist/unstable/FrameTime.js +1 -1
- package/dist/unstable/Imperative.d.ts +29 -9
- package/dist/unstable/Imperative.d.ts.map +1 -1
- package/dist/unstable/Imperative.js +79 -47
- package/dist/unstable/Imperative.js.map +1 -1
- package/dist/unstable/OwnValues.js +1 -1
- package/dist/unstable/PresenceRecord.d.ts +31 -27
- 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 +1 -1
- package/dist/unstable/Report.js +1 -1
- package/dist/unstable/RetargetLegs.d.ts +1 -1
- package/dist/unstable/RetargetLegs.d.ts.map +1 -1
- package/dist/unstable/RetargetLegs.js +9 -8
- package/dist/unstable/RetargetLegs.js.map +1 -1
- package/dist/unstable/Spine.d.ts +81 -72
- package/dist/unstable/Spine.d.ts.map +1 -1
- package/dist/unstable/Spine.js +171 -164
- 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 +7 -7
- package/dist/unstable/VariantTarget.d.ts.map +1 -1
- package/dist/unstable/VariantTarget.js +11 -11
- package/dist/unstable/VariantTarget.js.map +1 -1
- package/dist/unstable/VariantTree.d.ts +43 -36
- package/dist/unstable/VariantTree.d.ts.map +1 -1
- package/dist/unstable/VariantTree.js +34 -34
- 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 +236 -22
- package/src/Clock.ts +18 -17
- package/src/DefaultTransition.ts +5 -3
- package/src/Drag.ts +32 -14
- package/src/DragActivity.ts +3 -3
- package/src/DragRecognizer.ts +65 -23
- package/src/Easing.ts +1 -1
- package/src/Frame.ts +5 -3
- package/src/InputFeed.ts +2 -2
- package/src/InputSource.ts +12 -5
- package/src/Interpolator.ts +3 -3
- package/src/InterpolatorRegistry.ts +22 -13
- package/src/LiveValue.ts +47 -17
- package/src/Machine.ts +199 -61
- package/src/Playback.ts +5 -1
- package/src/Projection.ts +10 -28
- package/src/Recognizer.ts +24 -8
- package/src/ReducedMotion.ts +6 -6
- package/src/Renderer.ts +6 -6
- package/src/Reorder.ts +84 -38
- 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 +103 -87
- package/src/internal/lerpsNumbers.ts +53 -0
- package/src/internal/options.ts +10 -10
- package/src/internal/projectionRest.ts +31 -0
- package/src/internal/stepper.ts +20 -2
- package/src/internal/tracing.ts +1 -1
- package/src/unstable/AnimationControls.ts +59 -56
- package/src/unstable/AppearHandoff.ts +6 -6
- package/src/unstable/BatchCalls.ts +5 -5
- package/src/unstable/Config.ts +19 -19
- package/src/unstable/FirstSteps.ts +26 -0
- package/src/unstable/FlushGate.ts +92 -82
- package/src/unstable/FrameEffects.ts +2 -2
- package/src/unstable/FrameTime.ts +1 -1
- package/src/unstable/Imperative.ts +126 -56
- package/src/unstable/OwnValues.ts +1 -1
- package/src/unstable/PresenceRecord.ts +34 -30
- package/src/unstable/Projector.ts +45 -0
- package/src/unstable/Report.ts +1 -1
- package/src/unstable/RetargetLegs.ts +10 -9
- package/src/unstable/Spine.ts +210 -201
- 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 +13 -13
- package/src/unstable/VariantTree.ts +50 -43
- package/src/unstable/WardicConfigValue.ts +13 -13
|
@@ -4,54 +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 throw in one
|
|
52
|
-
* binding's hook, the read of its own value, its Timeline values, its commit) is that
|
|
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
|
|
53
54
|
* commits nothing that frame, a run of them is reported once (`Report.failure`) until it commits again,
|
|
54
|
-
* and every other
|
|
55
|
+
* and every other Subject still commits. Anything else a flush throws is reported and the gate
|
|
55
56
|
* goes on, so it can't fail the Frame loop's tick it runs in (ADR-0033).
|
|
56
57
|
*
|
|
57
58
|
* Unstable, for Wardic's own packages: public, with no semver promise.
|
|
@@ -71,32 +72,32 @@ import * as Scope from "effect/Scope";
|
|
|
71
72
|
* at flush time.
|
|
72
73
|
*/
|
|
73
74
|
export interface FlushSink {
|
|
74
|
-
/** The
|
|
75
|
+
/** The Subject the patch is committed onto. */
|
|
75
76
|
readonly target: unknown;
|
|
76
77
|
/**
|
|
77
|
-
* Called once, just before the
|
|
78
|
-
* pass's `flushPass`), inside the binding's `batch` with every other
|
|
78
|
+
* Called once, just before the Subject's first commit in a frame flush (not a Measure
|
|
79
|
+
* pass's `flushPass`), inside the binding's `batch` with every other Subject's switch that
|
|
79
80
|
* flush: a binding drops its Starting style from its `style` here,
|
|
80
81
|
* so its framework removes those keys and the commit writes the first frame in the same
|
|
81
|
-
* Refresh frame, with
|
|
82
|
+
* Refresh frame, with nothing drawn in between.
|
|
82
83
|
*/
|
|
83
84
|
readonly beforeFirstCommit?: (() => void) | undefined;
|
|
84
85
|
/**
|
|
85
|
-
* Called with every key the gate now holds on the
|
|
86
|
+
* Called with every key the gate now holds on the Subject, each time that set changes: after the
|
|
86
87
|
* gate restores a key it dropped, and before the commit that first
|
|
87
|
-
* writes a key. A binding whose `style` reaches the
|
|
88
|
+
* writes a key. A binding whose `style` reaches the Subject leaves these keys out of it,
|
|
88
89
|
* so its framework never writes over Wardic's value (`style` is a key's fallback). Called in
|
|
89
|
-
* the binding's `batch`, with every other
|
|
90
|
-
* binding changes reaches the
|
|
90
|
+
* the binding's `batch`, with every other Subject's whose keys changed that flush, so what the
|
|
91
|
+
* binding changes reaches the Subject before the commit, a framework that applies an update later
|
|
91
92
|
* (Solid 2) included.
|
|
92
93
|
*/
|
|
93
94
|
readonly onHeld?: ((keys: ReadonlyArray<string>) => void) | undefined;
|
|
94
95
|
/**
|
|
95
|
-
* Called once per frame in which the
|
|
96
|
+
* Called once per frame in which the Subject's values were committed, after every commit of that
|
|
96
97
|
* frame (Motion's `onUpdate`), with its values before
|
|
97
|
-
* projection (`x` as a number). The object is the
|
|
98
|
+
* projection (`x` as a number). The object is the Subject's own, reused each call: valid during
|
|
98
99
|
* the call, copied to keep. A Measure pass's commits are told at the frame flush after them, so
|
|
99
|
-
* a frame tells each
|
|
100
|
+
* a frame tells each Subject once. A write it makes is the next frame's. A throw is reported,
|
|
100
101
|
* and the others are still told.
|
|
101
102
|
*/
|
|
102
103
|
readonly onCommit?: ((values: Readonly<Record<string, unknown>>) => void) | undefined;
|
|
@@ -109,24 +110,24 @@ export interface GateTimeline {
|
|
|
109
110
|
/**
|
|
110
111
|
* What the gate reads of its Environment's targets, and what it keeps from a sink: a target's value
|
|
111
112
|
* for a key before the gate first writes it there (`""` for none), which it gives back at the key's
|
|
112
|
-
* release, and the key its Renderer reserves for
|
|
113
|
+
* release, and the key its Renderer reserves for a Subject's Transform template, which `onCommit`
|
|
113
114
|
* never sees.
|
|
114
115
|
*/
|
|
115
116
|
export interface GateEnvironment {
|
|
116
117
|
readonly valueBeforeOf: (target: unknown, key: string) => string;
|
|
117
118
|
readonly templateKey: string;
|
|
118
119
|
}
|
|
119
|
-
/** A Flush gate: what a binding registers its
|
|
120
|
+
/** A Flush gate: what a binding registers its Subjects with and writes their values into, one per provider. */
|
|
120
121
|
export interface FlushGate {
|
|
121
122
|
/**
|
|
122
|
-
* Register
|
|
123
|
-
* that removes the
|
|
123
|
+
* Register a Subject under `id` with its `sink`. Returns an unregister fn
|
|
124
|
+
* that removes the Subject from the accumulator (a subsequent `write` is a
|
|
124
125
|
* no-op). `values` start its value-map, unflushed: drawn with its first `write`, so they never
|
|
125
126
|
* commit alone.
|
|
126
127
|
*/
|
|
127
128
|
readonly register: (id: string, sink: FlushSink, values?: Readonly<Record<string, unknown>>) => () => void;
|
|
128
129
|
/**
|
|
129
|
-
* Merge `partial` into the
|
|
130
|
+
* Merge `partial` into the Subject's value-map by key, mark it dirty, and
|
|
130
131
|
* schedule a flush: the end of the Frame loop's tick, for a write made in one, or else the
|
|
131
132
|
* next Refresh frame. A `write` for an unregistered (or unregistered-since) id
|
|
132
133
|
* is a no-op.
|
|
@@ -138,41 +139,41 @@ export interface FlushGate {
|
|
|
138
139
|
* `pass()` runs are recorded; each recorded entry is `project`ed and committed once, and
|
|
139
140
|
* marked clean. Everything else stays dirty for its flush. A write made by an effect a sink's
|
|
140
141
|
* hook runs (a Solid effect) takes the ordinary path. The Projection system calls it at the
|
|
141
|
-
* end of a task, so a new layout never
|
|
142
|
+
* end of a task, so a new layout is never drawn without its projection.
|
|
142
143
|
*/
|
|
143
144
|
readonly flushPass: (pass: () => void) => void;
|
|
144
145
|
/**
|
|
145
|
-
* Hand `keys` back to the
|
|
146
|
+
* Hand `keys` back to the Subject's own style: drop each from the Subject's
|
|
146
147
|
* value-map and schedule a flush, which writes `restore[key]` (its Environment's text form) for a key it had
|
|
147
|
-
* written, or else the
|
|
148
|
+
* written, or else the Subject's own value it overwrote, and tells the sink (`onHeld`). A key the
|
|
148
149
|
* entry doesn't hold, or an unknown id, is a no-op. A binding releases a key back at its `style`
|
|
149
150
|
* value, so a later `style` change shows at rest. A later `write` brings the key back. A property in
|
|
150
151
|
* `keep` (`transform` for its keys) is left as it's drawn when it drops out: another writer draws it next.
|
|
151
152
|
*/
|
|
152
153
|
readonly release: (id: string, keys: ReadonlyArray<string>, restore?: Readonly<Record<string, string>>, keep?: ReadonlyArray<string>) => void;
|
|
153
154
|
/**
|
|
154
|
-
* The
|
|
155
|
+
* The Subject's value for `id`'s `key`, live: an `Atom` set as each write that
|
|
155
156
|
* changes it lands, so it's the value the next commit draws, before the Renderer projects it
|
|
156
157
|
* (`x` as a number, not a `transform`). Set at the write, not the commit, so a value derived
|
|
157
158
|
* from it (another key following it through a binding) is written in the same frame and
|
|
158
159
|
* commits with it. `undefined` before the key's first write, and once it's released or the
|
|
159
|
-
*
|
|
160
|
+
* Subject unregisters. One Atom for an id and a key, made on first ask, so per frame only the
|
|
160
161
|
* keys asked for cost anything.
|
|
161
162
|
*/
|
|
162
163
|
readonly valueOf: (id: string, key: string) => Atom.Atom<unknown>;
|
|
163
164
|
/**
|
|
164
|
-
* Run `key`'s Timeline value on `id`'s
|
|
165
|
+
* Run `key`'s Timeline value on `id`'s Subject (#240), or stop it (`undefined`): a binding sets one
|
|
165
166
|
* while the key shows its Live value, and clears it when an entry of the Override stack takes the
|
|
166
|
-
* key. The gate goes on writing the key: at each flush that commits the
|
|
167
|
+
* key. The gate goes on writing the key: at each flush that commits the Subject, before the commit,
|
|
167
168
|
* it starts the value's animation over it, or cancels it while something else adds to its property
|
|
168
169
|
* (a projection, a Transform template, another transform key off its identity), so a frame shows one
|
|
169
170
|
* or the other. A cleared or replaced one is cancelled at the next flush; a released key's, an
|
|
170
|
-
* unregistered
|
|
171
|
+
* unregistered Subject's and a disposed gate's, at once. Setting one schedules a flush.
|
|
171
172
|
*/
|
|
172
173
|
readonly timeline: (id: string, key: string, timeline: GateTimeline | undefined) => void;
|
|
173
174
|
/**
|
|
174
175
|
* Call `fn` once, after the gate's next flush: the end of the Frame loop's tick, for a call
|
|
175
|
-
* made in one, else the next Refresh frame's, so what was written before it is on the
|
|
176
|
+
* made in one, else the next Refresh frame's, so what was written before it is on the Subjects.
|
|
176
177
|
* It schedules that flush if none is pending. A binding tells an animation's end here, as Motion's
|
|
177
178
|
* `onAnimationComplete` comes with the final value set. One that throws is reported, and the rest
|
|
178
179
|
* still run.
|
|
@@ -183,7 +184,7 @@ export interface FlushGate {
|
|
|
183
184
|
}
|
|
184
185
|
/** The gate as its spine and its binding use it: all but its `dispose`, which its Scope runs. */
|
|
185
186
|
export type Shape = Omit<FlushGate, "dispose">;
|
|
186
|
-
/**
|
|
187
|
+
/** A Subject's commit target and hooks, given to `register`. */
|
|
187
188
|
export type Sink = FlushSink;
|
|
188
189
|
/** 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`. */
|
|
189
190
|
export type FlushGateServices = Renderer.Renderer | RefreshFrameSource.RefreshFrameSource | FrameLoop.FrameLoop | AtomRegistry.AtomRegistry;
|
|
@@ -201,11 +202,11 @@ export interface FlushGateRuntime {
|
|
|
201
202
|
export interface FlushGateOptions {
|
|
202
203
|
/**
|
|
203
204
|
* Runs a flush's hooks together: calls `apply`, and returns once every update inside it has reached
|
|
204
|
-
* the
|
|
205
|
+
* the Subjects, before the gate commits. Solid 1 passes its `batch`, Solid 2 runs `apply` then
|
|
205
206
|
* `flush()`, and React would pass `flushSync`, untried; a binding with nothing to batch passes
|
|
206
207
|
* `(apply) => apply()`. Called at most twice a flush: once for the starting-style switches
|
|
207
|
-
* (`beforeFirstCommit`) of the
|
|
208
|
-
*
|
|
208
|
+
* (`beforeFirstCommit`) of the Subjects committing for the first time, before anything is read off the
|
|
209
|
+
* Subjects; and once for the held keys (`onHeld`) of the Subjects whose held keys changed.
|
|
209
210
|
*/
|
|
210
211
|
readonly batch: (apply: () => void) => void;
|
|
211
212
|
}
|
|
@@ -214,7 +215,8 @@ export interface FlushGateOptions {
|
|
|
214
215
|
* switches through the binding's `batch`.
|
|
215
216
|
*
|
|
216
217
|
* Resolves both ONCE here: `project` is pure and `commit` a plain call (both called directly at
|
|
217
|
-
* flush, ADR-0034),
|
|
218
|
+
* flush, ADR-0034), and a Renderer's projector maker makes each Subject's projector as it registers;
|
|
219
|
+
* `requestFrame` /
|
|
218
220
|
* `cancelFrame` schedule and cancel the flush of a write made outside a tick, and the Frame
|
|
219
221
|
* loop's `afterTick` takes the gate's hook for its lifetime. All come from whichever env the
|
|
220
222
|
* provider was given (`DomLive` / `TestLive`), so the gate inherits that environment's
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FlushGate.d.ts","sourceRoot":"","sources":["../../src/unstable/FlushGate.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"FlushGate.d.ts","sourceRoot":"","sources":["../../src/unstable/FlushGate.ts"],"names":[],"mappings":"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"}
|
|
@@ -4,54 +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 throw in one
|
|
52
|
-
* binding's hook, the read of its own value, its Timeline values, its commit) is that
|
|
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
|
|
53
54
|
* commits nothing that frame, a run of them is reported once (`Report.failure`) until it commits again,
|
|
54
|
-
* and every other
|
|
55
|
+
* and every other Subject still commits. Anything else a flush throws is reported and the gate
|
|
55
56
|
* goes on, so it can't fail the Frame loop's tick it runs in (ADR-0033).
|
|
56
57
|
*
|
|
57
58
|
* Unstable, for Wardic's own packages: public, with no semver promise.
|
|
@@ -60,15 +61,17 @@
|
|
|
60
61
|
*/
|
|
61
62
|
// Unstable: ADR-0071, decision 5. #672: dom's `internal/gate.ts`, moved for the spine to write through
|
|
62
63
|
// 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
|
|
64
|
+
// #969 (ADR-0033, *Amendment (#969)*): one Subject's failure in a flush is its own.
|
|
64
65
|
import * as FrameLoop from "../FrameLoop.js";
|
|
65
66
|
import * as RefreshFrameSource from "../RefreshFrameSource.js";
|
|
66
67
|
import * as Renderer from "../Renderer.js";
|
|
68
|
+
import * as Projector from "./Projector.js";
|
|
67
69
|
import * as Cause from "effect/Cause";
|
|
68
70
|
import * as Atom from "effect/reactivity/Atom";
|
|
69
71
|
import * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
70
72
|
import * as Effect from "effect/Effect";
|
|
71
73
|
import * as Exit from "effect/Exit";
|
|
74
|
+
import * as Option from "effect/Option";
|
|
72
75
|
import * as Predicate from "effect/Predicate";
|
|
73
76
|
import * as UndefinedOr from "effect/UndefinedOr";
|
|
74
77
|
import * as Scope from "effect/Scope";
|
|
@@ -95,7 +98,8 @@ const cancelEach = (values) => {
|
|
|
95
98
|
* switches through the binding's `batch`.
|
|
96
99
|
*
|
|
97
100
|
* Resolves both ONCE here: `project` is pure and `commit` a plain call (both called directly at
|
|
98
|
-
* flush, ADR-0034),
|
|
101
|
+
* flush, ADR-0034), and a Renderer's projector maker makes each Subject's projector as it registers;
|
|
102
|
+
* `requestFrame` /
|
|
99
103
|
* `cancelFrame` schedule and cancel the flush of a write made outside a tick, and the Frame
|
|
100
104
|
* loop's `afterTick` takes the gate's hook for its lifetime. All come from whichever env the
|
|
101
105
|
* provider was given (`DomLive` / `TestLive`), so the gate inherits that environment's
|
|
@@ -108,12 +112,14 @@ export const makeFlushGate = (runtime, options, environment) => {
|
|
|
108
112
|
// `requestFrame` and `cancelFrame` are called detached, never as `frames.requestFrame(cb)`: a
|
|
109
113
|
// browser throws "Illegal invocation" when `requestAnimationFrame` runs with `this` bound to
|
|
110
114
|
// anything but the window (ADR-0031, decision 7).
|
|
111
|
-
const { commit, project, requestFrame, cancelFrame, afterTick } = runtime.runSync(Effect.gen(function* () {
|
|
112
|
-
const
|
|
115
|
+
const { commit, project, maker, requestFrame, cancelFrame, afterTick } = runtime.runSync(Effect.gen(function* () {
|
|
116
|
+
const renderer = yield* Renderer.Renderer;
|
|
113
117
|
const { requestFrame, cancelFrame } = yield* RefreshFrameSource.RefreshFrameSource;
|
|
114
118
|
const { afterTick } = yield* FrameLoop.FrameLoop;
|
|
115
|
-
return { commit, project, requestFrame, cancelFrame, afterTick };
|
|
119
|
+
return { commit: renderer.commit, project: renderer.project, maker: Projector.makerOf(renderer), requestFrame, cancelFrame, afterTick };
|
|
116
120
|
}));
|
|
121
|
+
// What makes a new Subject's projector, at its register: its Renderer's maker, or the Renderer's `project` for all.
|
|
122
|
+
const projectorOf = Option.getOrElse(maker, () => () => project);
|
|
117
123
|
const accumulator = new Map();
|
|
118
124
|
// Every live output asked for (`valueOf`), by id: an entry registered later picks its map up.
|
|
119
125
|
const outputsById = new Map();
|
|
@@ -129,8 +135,8 @@ export const makeFlushGate = (runtime, options, environment) => {
|
|
|
129
135
|
let recording;
|
|
130
136
|
// The entries committed since the last frame flush whose sink has an `onCommit` (#233).
|
|
131
137
|
const committedSince = new Set();
|
|
132
|
-
// Each
|
|
133
|
-
// its next: only the
|
|
138
|
+
// Each Subject's Timeline values by key (#240), and those let go of since its last flush, cancelled at
|
|
139
|
+
// its next: only the Subjects that have one, so the per-frame path checks their sizes alone.
|
|
134
140
|
const timelines = new Map();
|
|
135
141
|
const endings = new Map();
|
|
136
142
|
// A frame flush's entries, in order, prepared and waiting for their commit; and those whose
|
|
@@ -138,13 +144,13 @@ export const makeFlushGate = (runtime, options, environment) => {
|
|
|
138
144
|
const prepared = entryListOf();
|
|
139
145
|
const heldChanged = entryListOf();
|
|
140
146
|
/**
|
|
141
|
-
* Project one dirty entry's patch and restore the keys it dropped (once per
|
|
147
|
+
* Project one dirty entry's patch and restore the keys it dropped (once per Subject per flush),
|
|
142
148
|
* marking it clean: into `into`, and into `held` when the keys it holds change and its sink
|
|
143
149
|
* hears them. Its commit waits for the binding's `batch` of those (ADR-0034, *Amendment
|
|
144
150
|
* (#209)*). Plain calls only: this is the per-frame path.
|
|
145
151
|
*/
|
|
146
152
|
const prepare = (entry, into, held) => {
|
|
147
|
-
const patch =
|
|
153
|
+
const patch = entry.projector(entry.values);
|
|
148
154
|
entry.dirty = false;
|
|
149
155
|
entry.patch = patch;
|
|
150
156
|
addTo(into, entry);
|
|
@@ -162,7 +168,7 @@ export const makeFlushGate = (runtime, options, environment) => {
|
|
|
162
168
|
committed.set(key, valueBeforeOf(target, key));
|
|
163
169
|
added = true;
|
|
164
170
|
}
|
|
165
|
-
// A key the last patch wrote and this one doesn't: the
|
|
171
|
+
// A key the last patch wrote and this one doesn't: the Subject gets its own value
|
|
166
172
|
// back. Only looked for when one dropped out (the usual frame keeps every key).
|
|
167
173
|
let restore;
|
|
168
174
|
if (kept < before) {
|
|
@@ -186,10 +192,10 @@ export const makeFlushGate = (runtime, options, environment) => {
|
|
|
186
192
|
addTo(held, entry);
|
|
187
193
|
};
|
|
188
194
|
/**
|
|
189
|
-
* Before a flush's commits (#240): cancel the Timeline values each
|
|
195
|
+
* Before a flush's commits (#240): cancel the Timeline values each Subject committing now let go of,
|
|
190
196
|
* and sync the rest with its values, so each starts or stops as nothing else adds to its property.
|
|
191
197
|
* An entry is committing while it holds a prepared patch. Kept beside the entries, not on them, so an
|
|
192
|
-
*
|
|
198
|
+
* Subject with none pays nothing per frame: the flush checks two sizes. Per flush: plain loops.
|
|
193
199
|
*/
|
|
194
200
|
const syncTimelines = () => {
|
|
195
201
|
for (const [entry, ended] of endings) {
|
|
@@ -218,7 +224,7 @@ export const makeFlushGate = (runtime, options, environment) => {
|
|
|
218
224
|
}
|
|
219
225
|
}
|
|
220
226
|
};
|
|
221
|
-
/** Every Timeline value of `entry`, cancelled at once: its
|
|
227
|
+
/** Every Timeline value of `entry`, cancelled at once: its Subject is gone, or the gate is. */
|
|
222
228
|
const cancelTimelines = (entry) => {
|
|
223
229
|
const ended = endings.get(entry);
|
|
224
230
|
endings.delete(entry);
|
|
@@ -229,7 +235,7 @@ export const makeFlushGate = (runtime, options, environment) => {
|
|
|
229
235
|
if (Predicate.isNotUndefined(byKey))
|
|
230
236
|
cancelEach(byKey.values());
|
|
231
237
|
};
|
|
232
|
-
/** Commit a prepared entry's patch onto its
|
|
238
|
+
/** Commit a prepared entry's patch onto its Subject. */
|
|
233
239
|
const commitPrepared = (entry) => {
|
|
234
240
|
const patch = entry.patch;
|
|
235
241
|
if (Predicate.isUndefined(patch))
|
|
@@ -243,13 +249,13 @@ export const makeFlushGate = (runtime, options, environment) => {
|
|
|
243
249
|
};
|
|
244
250
|
/**
|
|
245
251
|
* One of `entry`'s steps threw this flush (#969): its later steps skipped this frame, its patch with
|
|
246
|
-
* them, and the other
|
|
252
|
+
* them, and the other Subjects' going on. A run of them is reported at its first, `step` naming it.
|
|
247
253
|
*/
|
|
248
254
|
// A failure's path, never the frame's: one place each loop's catch calls.
|
|
249
255
|
const failedAt = (entry, step, defect) => {
|
|
250
256
|
entry.patch = undefined;
|
|
251
257
|
// Tried again at the gate's next flush, which it doesn't ask for itself: a Subject frozen for good would
|
|
252
|
-
// keep the host's frames running. A later write, its own or another
|
|
258
|
+
// keep the host's frames running. A later write, its own or another Subject's, brings that flush.
|
|
253
259
|
entry.dirty = true;
|
|
254
260
|
// Its sink's `onCommit` hears nothing of a frame it didn't commit in.
|
|
255
261
|
committedSince.delete(entry);
|
|
@@ -265,7 +271,7 @@ export const makeFlushGate = (runtime, options, environment) => {
|
|
|
265
271
|
const commitAll = (entries, held) => {
|
|
266
272
|
if (held.count > 0)
|
|
267
273
|
batch(() => tellHeld(held));
|
|
268
|
-
// A try for each
|
|
274
|
+
// A try for each Subject, its call direct (#969): a shared helper taking the step measured +20% a frame.
|
|
269
275
|
for (let i = 0; i < entries.count; i++) {
|
|
270
276
|
const entry = entries.entries[i];
|
|
271
277
|
try {
|
|
@@ -278,7 +284,7 @@ export const makeFlushGate = (runtime, options, environment) => {
|
|
|
278
284
|
clear(entries);
|
|
279
285
|
clear(held);
|
|
280
286
|
};
|
|
281
|
-
/** Each entry's `onHeld`, with every key the gate holds on its
|
|
287
|
+
/** Each entry's `onHeld`, with every key the gate holds on its Subject now. */
|
|
282
288
|
const tellHeld = (held) => {
|
|
283
289
|
for (let i = 0; i < held.count; i++) {
|
|
284
290
|
const entry = held.entries[i];
|
|
@@ -338,7 +344,7 @@ export const makeFlushGate = (runtime, options, environment) => {
|
|
|
338
344
|
*/
|
|
339
345
|
// #979, group D (ADR-0074): an output's dependent that throws (an app's Atom over a ward's `read(key)`)
|
|
340
346
|
// is its own. The registry has set the output and told its other listeners before the throw comes back,
|
|
341
|
-
// so the write goes on, the
|
|
347
|
+
// so the write goes on, the Subject's other outputs with it: before, it came out of the ward's own leg.
|
|
342
348
|
const setOutputs = (entry) => {
|
|
343
349
|
const outputs = entry.outputs;
|
|
344
350
|
if (Predicate.isUndefined(outputs))
|
|
@@ -353,7 +359,7 @@ export const makeFlushGate = (runtime, options, environment) => {
|
|
|
353
359
|
};
|
|
354
360
|
/** `output` set to `value`, its dependent's throw its own: reported once a run of throws, until a clean set. */
|
|
355
361
|
// The try is here, out of the loops that call it (`setOutputs`', `endOutputs`'): in the body of
|
|
356
|
-
// `setOutputs`' loop over the
|
|
362
|
+
// `setOutputs`' loop over the Subject's outputs Map, it measured +5–8% on Node's write.
|
|
357
363
|
const setOutput = (id, key, output, value) => {
|
|
358
364
|
try {
|
|
359
365
|
registry.set(output.atom, value);
|
|
@@ -393,10 +399,10 @@ export const makeFlushGate = (runtime, options, environment) => {
|
|
|
393
399
|
const flush = () => {
|
|
394
400
|
scheduled = false;
|
|
395
401
|
try {
|
|
396
|
-
// The switches first:
|
|
402
|
+
// The switches first: a Subject's own values are read once its Starting style is gone.
|
|
397
403
|
if (firstCommits.size > 0)
|
|
398
404
|
batch(runFirstCommits);
|
|
399
|
-
// Every dirty
|
|
405
|
+
// Every dirty Subject, once. No auto-reschedule — the next write() does. A write()
|
|
400
406
|
// from an effect a sink's hook runs requests the next frame (it isn't stranded).
|
|
401
407
|
for (const entry of accumulator.values()) {
|
|
402
408
|
if (!entry.dirty)
|
|
@@ -467,6 +473,7 @@ export const makeFlushGate = (runtime, options, environment) => {
|
|
|
467
473
|
committed: new Map(),
|
|
468
474
|
outputs: outputsById.get(id),
|
|
469
475
|
id,
|
|
476
|
+
projector: projectorOf(),
|
|
470
477
|
latest: undefined,
|
|
471
478
|
onCommitFailing: false,
|
|
472
479
|
stepFailing: false,
|
|
@@ -488,8 +495,8 @@ export const makeFlushGate = (runtime, options, environment) => {
|
|
|
488
495
|
endOutputs(id);
|
|
489
496
|
};
|
|
490
497
|
};
|
|
491
|
-
/** `id`'s live outputs, each set to `undefined` and forgotten: its
|
|
492
|
-
// #979, row 42 (ADR-0074): set through `setOutput`, so a dependent that throws as its
|
|
498
|
+
/** `id`'s live outputs, each set to `undefined` and forgotten: its Subject is gone. */
|
|
499
|
+
// #979, row 42 (ADR-0074): set through `setOutput`, so a dependent that throws as its Subject leaves is
|
|
493
500
|
// reported, and every output still ends: before, its throw came out of the unregister, a binding's
|
|
494
501
|
// cleanup, and left that output and the later ones mounted.
|
|
495
502
|
const endOutputs = (id) => {
|
|
@@ -521,7 +528,7 @@ export const makeFlushGate = (runtime, options, environment) => {
|
|
|
521
528
|
const known = outputs.get(key);
|
|
522
529
|
if (Predicate.isNotUndefined(known))
|
|
523
530
|
return known.atom;
|
|
524
|
-
// Made `undefined` and mounted until its
|
|
531
|
+
// Made `undefined` and mounted until its Subject unregisters, not kept alive: a kept-alive
|
|
525
532
|
// Atom's node never leaves the registry, and one left behind reads `undefined` afresh.
|
|
526
533
|
const atom = Atom.make(undefined);
|
|
527
534
|
const output = { atom, last: undefined, unmount: registry.mount(atom), failing: false };
|
|
@@ -557,7 +564,7 @@ export const makeFlushGate = (runtime, options, environment) => {
|
|
|
557
564
|
return;
|
|
558
565
|
// No `beforeFirstCommit` here: a Measure pass may write only a node's projection, and
|
|
559
566
|
// dropping the Starting style then would leave its animated keys unset until the frame
|
|
560
|
-
// flush (a frame later for
|
|
567
|
+
// flush (a frame later for a Subject mounted inside a frame). The frame flush switches.
|
|
561
568
|
// A commit here is told at the frame flush (#233): the write that made it scheduled that flush.
|
|
562
569
|
// Its own lists: a pass may run from a hook the frame flush's `batch` runs.
|
|
563
570
|
const entries = entryListOf();
|
|
@@ -605,13 +612,13 @@ export const makeFlushGate = (runtime, options, environment) => {
|
|
|
605
612
|
}
|
|
606
613
|
byKey.set(key, value);
|
|
607
614
|
}
|
|
608
|
-
//
|
|
615
|
+
// A Subject left with none leaves the map, so the flush skips it.
|
|
609
616
|
if (Predicate.isNotUndefined(byKey) && byKey.size === 0)
|
|
610
617
|
timelines.delete(entry);
|
|
611
618
|
entry.dirty = true;
|
|
612
619
|
scheduleFlush();
|
|
613
620
|
};
|
|
614
|
-
/** `entry`'s Timeline values for `keys`, cancelled at once: those keys go back to the
|
|
621
|
+
/** `entry`'s Timeline values for `keys`, cancelled at once: those keys go back to the Subject's own style. */
|
|
615
622
|
const releaseTimelines = (entry, keys) => {
|
|
616
623
|
const byKey = timelines.get(entry);
|
|
617
624
|
if (Predicate.isUndefined(byKey))
|