@wardic/core 1.3.0 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/BaseValue.d.ts +1 -1
- package/dist/BaseValue.js +2 -2
- package/dist/BaseValue.js.map +1 -1
- package/dist/Batch.d.ts +5 -9
- package/dist/Batch.d.ts.map +1 -1
- package/dist/Batch.js +195 -24
- package/dist/Batch.js.map +1 -1
- package/dist/Clock.d.ts +16 -0
- package/dist/Clock.d.ts.map +1 -1
- package/dist/Clock.js +13 -0
- package/dist/Clock.js.map +1 -1
- package/dist/DragRecognizer.d.ts +10 -5
- package/dist/DragRecognizer.d.ts.map +1 -1
- package/dist/DragRecognizer.js +60 -24
- package/dist/DragRecognizer.js.map +1 -1
- package/dist/Frame.js +1 -1
- package/dist/Frame.js.map +1 -1
- package/dist/InputFeed.d.ts +10 -7
- package/dist/InputFeed.d.ts.map +1 -1
- package/dist/InputFeed.js +16 -35
- package/dist/InputFeed.js.map +1 -1
- package/dist/LiveValue.d.ts +9 -3
- package/dist/LiveValue.d.ts.map +1 -1
- package/dist/LiveValue.js +160 -14
- package/dist/LiveValue.js.map +1 -1
- package/dist/Machine.d.ts +16 -6
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +50 -27
- package/dist/Machine.js.map +1 -1
- package/dist/Playback.d.ts.map +1 -1
- package/dist/Playback.js +10 -8
- package/dist/Playback.js.map +1 -1
- package/dist/Recognizer.d.ts +1 -1
- package/dist/Recognizer.d.ts.map +1 -1
- package/dist/Recognizer.js +9 -4
- package/dist/Recognizer.js.map +1 -1
- package/dist/internal/frameLoop.d.ts +10 -2
- package/dist/internal/frameLoop.d.ts.map +1 -1
- package/dist/internal/frameLoop.js +148 -18
- package/dist/internal/frameLoop.js.map +1 -1
- package/dist/internal/guarded.d.ts +16 -0
- package/dist/internal/guarded.d.ts.map +1 -0
- package/dist/internal/guarded.js +68 -0
- package/dist/internal/guarded.js.map +1 -0
- package/dist/internal/stepper.d.ts +9 -3
- package/dist/internal/stepper.d.ts.map +1 -1
- package/dist/internal/stepper.js +5 -4
- package/dist/internal/stepper.js.map +1 -1
- package/dist/unstable/AnimationControls.d.ts +15 -8
- package/dist/unstable/AnimationControls.d.ts.map +1 -1
- package/dist/unstable/AnimationControls.js +36 -15
- package/dist/unstable/AnimationControls.js.map +1 -1
- package/dist/unstable/AppearHandoff.d.ts +6 -0
- package/dist/unstable/AppearHandoff.d.ts.map +1 -1
- package/dist/unstable/AppearHandoff.js.map +1 -1
- package/dist/unstable/BatchCalls.d.ts +16 -1
- package/dist/unstable/BatchCalls.d.ts.map +1 -1
- package/dist/unstable/BatchCalls.js +8 -0
- package/dist/unstable/BatchCalls.js.map +1 -1
- package/dist/unstable/Config.d.ts +16 -1
- package/dist/unstable/Config.d.ts.map +1 -1
- package/dist/unstable/Config.js.map +1 -1
- package/dist/unstable/FlushGate.d.ts +4 -2
- package/dist/unstable/FlushGate.d.ts.map +1 -1
- package/dist/unstable/FlushGate.js +155 -38
- package/dist/unstable/FlushGate.js.map +1 -1
- package/dist/unstable/FrameEffects.d.ts +4 -1
- package/dist/unstable/FrameEffects.d.ts.map +1 -1
- package/dist/unstable/FrameEffects.js +12 -1
- package/dist/unstable/FrameEffects.js.map +1 -1
- package/dist/unstable/Imperative.d.ts +42 -11
- package/dist/unstable/Imperative.d.ts.map +1 -1
- package/dist/unstable/Imperative.js +413 -77
- package/dist/unstable/Imperative.js.map +1 -1
- package/dist/unstable/MeasuredPairs.d.ts +6 -2
- package/dist/unstable/MeasuredPairs.d.ts.map +1 -1
- package/dist/unstable/MeasuredPairs.js.map +1 -1
- package/dist/unstable/PresenceRecord.d.ts +4 -0
- package/dist/unstable/PresenceRecord.d.ts.map +1 -1
- package/dist/unstable/PresenceRecord.js.map +1 -1
- package/dist/unstable/Report.d.ts +7 -0
- package/dist/unstable/Report.d.ts.map +1 -1
- package/dist/unstable/Report.js +17 -1
- package/dist/unstable/Report.js.map +1 -1
- package/dist/unstable/RetargetLegs.d.ts +6 -0
- package/dist/unstable/RetargetLegs.d.ts.map +1 -1
- package/dist/unstable/RetargetLegs.js +15 -0
- package/dist/unstable/RetargetLegs.js.map +1 -1
- package/dist/unstable/Spine.d.ts +62 -10
- package/dist/unstable/Spine.d.ts.map +1 -1
- package/dist/unstable/Spine.js +190 -40
- package/dist/unstable/Spine.js.map +1 -1
- package/dist/unstable/VariantTarget.d.ts +25 -3
- package/dist/unstable/VariantTarget.d.ts.map +1 -1
- package/dist/unstable/VariantTarget.js +66 -13
- package/dist/unstable/VariantTarget.js.map +1 -1
- package/dist/unstable/VariantTree.d.ts +37 -3
- package/dist/unstable/VariantTree.d.ts.map +1 -1
- package/dist/unstable/VariantTree.js +54 -7
- package/dist/unstable/VariantTree.js.map +1 -1
- package/package.json +1 -1
- package/src/BaseValue.ts +2 -2
- package/src/Batch.ts +210 -20
- package/src/Clock.ts +20 -0
- package/src/DragRecognizer.ts +82 -30
- package/src/Frame.ts +1 -1
- package/src/InputFeed.ts +37 -40
- package/src/LiveValue.ts +140 -14
- package/src/Machine.ts +67 -34
- package/src/Playback.ts +10 -8
- package/src/Recognizer.ts +9 -3
- package/src/internal/frameLoop.ts +165 -19
- package/src/internal/guarded.ts +69 -0
- package/src/internal/stepper.ts +14 -5
- package/src/unstable/AnimationControls.ts +49 -21
- package/src/unstable/AppearHandoff.ts +7 -0
- package/src/unstable/BatchCalls.ts +20 -2
- package/src/unstable/Config.ts +24 -1
- package/src/unstable/FlushGate.ts +169 -37
- package/src/unstable/FrameEffects.ts +15 -2
- package/src/unstable/Imperative.ts +447 -89
- package/src/unstable/MeasuredPairs.ts +7 -1
- package/src/unstable/PresenceRecord.ts +4 -0
- package/src/unstable/Report.ts +19 -1
- package/src/unstable/RetargetLegs.ts +14 -0
- package/src/unstable/Spine.ts +244 -43
- package/src/unstable/VariantTarget.ts +93 -14
- package/src/unstable/VariantTree.ts +87 -6
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
* - **`stop()`** ends each element's running legs where they are.
|
|
16
16
|
*
|
|
17
17
|
* A function definition is called once per element, with its `custom`, values and velocities, as
|
|
18
|
-
* Motion's `controls.start((i) => …)
|
|
18
|
+
* Motion's `controls.start((i) => …)`, every element's before any is set: one that throws for an element
|
|
19
|
+
* refuses the call, taking nothing. An element hears the controls from its mount to its unmount.
|
|
19
20
|
*
|
|
20
21
|
* Unstable, for Wardic's own packages: public, with no semver promise.
|
|
21
22
|
*
|
|
@@ -58,9 +59,11 @@ export interface ControlsChange {
|
|
|
58
59
|
readonly landed: () => void
|
|
59
60
|
}
|
|
60
61
|
|
|
61
|
-
/** What a controlled element does at a change, as its binding wires it: its entry set, and the change's landing promised. */
|
|
62
|
+
/** What a controlled element does at a change, as its binding wires it: its entry worked out, then set, and the change's landing promised. */
|
|
62
63
|
export interface Controlled {
|
|
63
|
-
|
|
64
|
+
/** Its entry for `definition`: a function definition called with its `custom`, values and velocities; anything else as it is. */
|
|
65
|
+
readonly entryOf: (definition: Config.WardicControlsDefinition) => Config.WardicVariant | Config.WardicVariantLabels
|
|
66
|
+
readonly change: (entry: Config.WardicVariant | Config.WardicVariantLabels, override: Config.WardicTransition | undefined) => Promise<void>
|
|
64
67
|
readonly stop: () => void
|
|
65
68
|
}
|
|
66
69
|
|
|
@@ -71,6 +74,15 @@ const subscribers = new WeakMap<Config.WardicAnimationControls, Set<Controlled>>
|
|
|
71
74
|
/** `set`'s transition (#433, Motion's `setValues`): none to speak of, and no orchestration. */
|
|
72
75
|
export const INSTANT: Config.WardicTransition = { type: "tween", duration: 0 }
|
|
73
76
|
|
|
77
|
+
/**
|
|
78
|
+
* Each element's entry for `definition`, worked out before any is set: a function definition that throws
|
|
79
|
+
* for one refuses the call, taking nothing, as an `animate()` call refuses one.
|
|
80
|
+
*/
|
|
81
|
+
// #979 (ADR-0074, row 35): `start` and `set` set each element's entry as they called its function, so one
|
|
82
|
+
// that threw for a later element left the earlier ones changed and the rest unreached, as #986's row 20.
|
|
83
|
+
const entriesOf = (elements: ReadonlyArray<Controlled>, definition: Config.WardicControlsDefinition): ReadonlyArray<Config.WardicVariant | Config.WardicVariantLabels> =>
|
|
84
|
+
Arr.map(elements, (element) => element.entryOf(definition))
|
|
85
|
+
|
|
74
86
|
/**
|
|
75
87
|
* Makes animation controls, which animate elements from code by their variants or targets: give them
|
|
76
88
|
* to each element as `animate={controls}`, on a `w.*` element, in a ward's config or on a
|
|
@@ -87,12 +99,18 @@ export const createAnimationControls = (): Config.WardicAnimationControls => {
|
|
|
87
99
|
const reached = new Set<Controlled>()
|
|
88
100
|
const controls: Config.WardicAnimationControls = {
|
|
89
101
|
[Config.CONTROLS]: true,
|
|
90
|
-
start: (definition, transitionOverride) =>
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
102
|
+
start: (definition, transitionOverride) => {
|
|
103
|
+
const elements = Arr.fromIterable(reached)
|
|
104
|
+
const entries = entriesOf(elements, definition)
|
|
105
|
+
return Promise.all(Arr.zipWith(elements, entries, (element, entry) => element.change(entry, transitionOverride))).then(() => undefined)
|
|
106
|
+
},
|
|
107
|
+
set: (definition) => {
|
|
108
|
+
const elements = Arr.fromIterable(reached)
|
|
109
|
+
const entries = entriesOf(elements, definition)
|
|
110
|
+
Arr.forEach(Arr.zip(elements, entries), ([element, entry]) => {
|
|
111
|
+
void element.change(entry, INSTANT)
|
|
112
|
+
})
|
|
113
|
+
},
|
|
96
114
|
stop: () => reached.forEach((element) => element.stop()),
|
|
97
115
|
}
|
|
98
116
|
subscribers.set(controls, reached)
|
|
@@ -121,26 +139,35 @@ export const subscribe = (controls: Config.WardicAnimationControls, element: Con
|
|
|
121
139
|
let serials = 0
|
|
122
140
|
|
|
123
141
|
/**
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
* lands once every element it reaches has joined, at the end of the binding's flush (`armed`), and
|
|
127
|
-
* left. One that reaches no element lands then.
|
|
142
|
+
* An element's entry for `definition`: a resolver called with its `custom`, values and velocities (once,
|
|
143
|
+
* as Motion's), anything else as it is.
|
|
128
144
|
*/
|
|
129
|
-
|
|
145
|
+
// #433; #979 (row 35): worked out for every element before any is set.
|
|
146
|
+
export const entryOf = (
|
|
130
147
|
definition: Config.WardicControlsDefinition,
|
|
131
|
-
override: Config.WardicTransition | undefined,
|
|
132
148
|
custom: unknown,
|
|
133
149
|
values: Readonly<Record<string, number | string>>,
|
|
134
150
|
velocities: Readonly<Record<string, number>>,
|
|
151
|
+
): Config.WardicVariant | Config.WardicVariantLabels =>
|
|
152
|
+
Bool.match(Predicate.isFunction(definition), {
|
|
153
|
+
onTrue: () => (definition as Config.WardicVariantResolver)(custom, { ...values }, { ...velocities }),
|
|
154
|
+
onFalse: () => definition as Config.WardicVariant | Config.WardicVariantLabels,
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* A change of one element: its entry, on `override`, and its landing, promised. It lands once every
|
|
159
|
+
* element it reaches has joined, at the end of the binding's flush (`armed`), and left. One that reaches
|
|
160
|
+
* no element lands then.
|
|
161
|
+
*/
|
|
162
|
+
// #433.
|
|
163
|
+
export const changeOf = (
|
|
164
|
+
entry: Config.WardicVariant | Config.WardicVariantLabels,
|
|
165
|
+
override: Config.WardicTransition | undefined,
|
|
135
166
|
): { readonly change: ControlsChange; readonly landing: Promise<void> } => {
|
|
136
167
|
let resolve!: () => void
|
|
137
168
|
const landing = new Promise<void>((done) => {
|
|
138
169
|
resolve = done
|
|
139
170
|
})
|
|
140
|
-
const entry = Bool.match(Predicate.isFunction(definition), {
|
|
141
|
-
onTrue: () => (definition as Config.WardicVariantResolver)(custom, { ...values }, { ...velocities }),
|
|
142
|
-
onFalse: () => definition as Config.WardicVariant | Config.WardicVariantLabels,
|
|
143
|
-
})
|
|
144
171
|
const change: ControlsChange = { serial: ++serials, definition: entry, override, pending: 0, armed: false, landed: resolve }
|
|
145
172
|
return { change, landing }
|
|
146
173
|
}
|
|
@@ -194,8 +221,9 @@ export interface ControlledSnapshot {
|
|
|
194
221
|
* every element it reaches joined by then; `stop` ends its legs.
|
|
195
222
|
*/
|
|
196
223
|
export const controlledElement = (setChange: (change: ControlsChange) => void, state: ControlledState, stop: () => void): Controlled => ({
|
|
197
|
-
|
|
198
|
-
|
|
224
|
+
entryOf: (definition) => entryOf(definition, state.custom(), state.snapshot.values, state.snapshot.velocitiesNow(state.snapshot)),
|
|
225
|
+
change: (entry, override) => {
|
|
226
|
+
const made = changeOf(entry, override)
|
|
199
227
|
setChange(made.change)
|
|
200
228
|
queueMicrotask(() => arm(made.change))
|
|
201
229
|
return made.landing
|
|
@@ -42,6 +42,13 @@ export interface MountAnimation {
|
|
|
42
42
|
readonly skipped?: boolean | undefined
|
|
43
43
|
/** Its **Transform template** (#443): its stops drawn through it, as the client draws them. Left out with none. */
|
|
44
44
|
readonly template?: Config.SpineConfig["transformTemplate"]
|
|
45
|
+
/**
|
|
46
|
+
* Each key already at its target, which it leaves where it is, at its value, as the client writes it
|
|
47
|
+
* beside the moving keys: its Environment may draw some of them together with those in each stop.
|
|
48
|
+
* Part of its key when it draws any; none, or an empty one, holds nothing.
|
|
49
|
+
*/
|
|
50
|
+
// #1004 (ADR-0044, *Amendment (#1004)*).
|
|
51
|
+
readonly held?: Values.Values | undefined
|
|
45
52
|
}
|
|
46
53
|
|
|
47
54
|
/** Whether a transition repeats for ever: a tween's `repeat: Infinity`, a tween as it runs (ADR-0051). */
|
|
@@ -206,9 +206,26 @@ export interface ChangeCall {
|
|
|
206
206
|
readonly skipAnimations: boolean
|
|
207
207
|
readonly head: Playback.Playhead
|
|
208
208
|
readonly settled: () => void
|
|
209
|
+
/** It ended with a key a later change took, never landing (#951). */
|
|
210
|
+
readonly taken?: (() => void) | undefined
|
|
209
211
|
readonly onMemberLanded?: ((slot: number) => void) | undefined
|
|
210
212
|
}
|
|
211
213
|
|
|
214
|
+
/**
|
|
215
|
+
* A Batch change's options `O`, `Batch.animate`'s or `Batch.keyframes`', with `onTaken`: called once
|
|
216
|
+
* the change ends with a key a later change took while it moved it, which it then never lands.
|
|
217
|
+
*/
|
|
218
|
+
// #951: Motion's never resolves then; the scope it was started in hears it end. Here, in an unstable
|
|
219
|
+
// module, not on Batch's own options: Batch reads it at a change's end (`checkLanding`'s TakenHook).
|
|
220
|
+
export type Taken<O> = O & { readonly onTaken?: (() => void) | undefined }
|
|
221
|
+
|
|
222
|
+
/** A sequence's call's options for `Batch.keyframes`: its Playhead, its landing, and its `onTaken`. */
|
|
223
|
+
export const keyframesOptions = (call: { readonly head: Playback.Playhead; readonly settled: () => void; readonly taken: () => void }): Taken<Batch.KeyframesOptions> => ({
|
|
224
|
+
head: call.head,
|
|
225
|
+
onLanded: call.settled,
|
|
226
|
+
onTaken: call.taken,
|
|
227
|
+
})
|
|
228
|
+
|
|
212
229
|
/**
|
|
213
230
|
* A driven change's options for core's `Batch.animate`, toward `targetOf`, from `fromOf`'s first stops
|
|
214
231
|
* when it gives them, on its call's transitions: each key's own, else its Default transition toward the
|
|
@@ -220,7 +237,7 @@ export const animateOptions = (
|
|
|
220
237
|
call: ChangeCall,
|
|
221
238
|
targetOf: (slot: number, k: number) => number,
|
|
222
239
|
fromOf: ((slot: number, k: number) => number) | undefined,
|
|
223
|
-
): Batch.AnimateOptions => {
|
|
240
|
+
): Taken<Batch.AnimateOptions> => {
|
|
224
241
|
const transition = Bool.match(call.skipAnimations, {
|
|
225
242
|
onTrue: () => (): Batch.Transition => INSTANT,
|
|
226
243
|
onFalse: () => {
|
|
@@ -232,8 +249,9 @@ export const animateOptions = (
|
|
|
232
249
|
}
|
|
233
250
|
},
|
|
234
251
|
})
|
|
235
|
-
const options: { -readonly [K in keyof Batch.AnimateOptions]: Batch.AnimateOptions[K] } = { head: call.head, transition, onLanded: call.settled }
|
|
252
|
+
const options: { -readonly [K in keyof Taken<Batch.AnimateOptions>]: Taken<Batch.AnimateOptions>[K] } = { head: call.head, transition, onLanded: call.settled }
|
|
236
253
|
if (Predicate.isNotUndefined(fromOf)) options.from = fromOf
|
|
254
|
+
if (Predicate.isNotUndefined(call.taken)) options.onTaken = call.taken
|
|
237
255
|
if (Predicate.isNotUndefined(call.onMemberLanded)) options.onMemberLanded = call.onMemberLanded
|
|
238
256
|
const delay = Bool.match(call.skipAnimations, { onTrue: () => undefined, onFalse: () => staggerOf(call.transition) })
|
|
239
257
|
if (Predicate.isNotUndefined(delay)) options.delay = delay
|
package/src/unstable/Config.ts
CHANGED
|
@@ -208,6 +208,23 @@ export type WardicTransitionEntries = WardicValueEntries<WardicValueKey> & { rea
|
|
|
208
208
|
/** Entries for the values `K`, and `default` for the rest (#301). */
|
|
209
209
|
export type WardicValueEntries<K extends string> = { readonly default?: WardicValueTransition } & { readonly [P in K]?: WardicValueTransition }
|
|
210
210
|
|
|
211
|
+
/** Each member's keys, as one union: a union's own `keyof` is only the keys its members share. */
|
|
212
|
+
type KeysOfEach<T> = T extends unknown ? keyof T : never
|
|
213
|
+
|
|
214
|
+
/** A transition's own fields' names, on any arm, and its `layout` entry's. */
|
|
215
|
+
type TransitionFieldName = KeysOfEach<WardicTransitionWith<unknown>> | "layout"
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* A transition for a Subject whose keys are `K`: an entry under each of `K`, and `default`; no
|
|
219
|
+
* `layout`. A key named like one of the transition's own fields (`duration`, `type`, `delay`…) has
|
|
220
|
+
* no entry, since that name is the field's: it runs on `default` or the transition's own fields.
|
|
221
|
+
*/
|
|
222
|
+
// #952: an Environment whose keys depend on its Subject (`@wardic/object`'s, `@wardic/three`'s) types
|
|
223
|
+
// its transitions so; one whose keys are global, `ValueKeys`' (`@wardic/dom`'s), `WardicTransition`.
|
|
224
|
+
// A name holds the field or the entry, never both, and the runtime reads any object under it as an
|
|
225
|
+
// entry (RetargetLegs.entriesOf): a field's name is left out of the entries, so it stays the field's.
|
|
226
|
+
export type WardicTransitionFor<K extends string> = WardicTransitionWith<WardicValueEntries<Exclude<K, TransitionFieldName>>>
|
|
227
|
+
|
|
211
228
|
/**
|
|
212
229
|
* A variant's own transition, or a target's: it runs the animation that variant starts, in place of
|
|
213
230
|
* the element's `transition`, unless `inherit: true` lays it over the element's, its own fields winning.
|
|
@@ -246,7 +263,12 @@ export type WardicVariantLabels = string | ReadonlyArray<string>
|
|
|
246
263
|
* A dynamic variant (Motion's `TargetResolver`): called each time the variant is
|
|
247
264
|
* resolved with the element's `custom` (or, for an exit, its `<AnimatePresence custom>`), its values
|
|
248
265
|
* now and their velocities, and returns its target, or another variant's name.
|
|
266
|
+
*
|
|
267
|
+
* One that throws is reported, and only its element is affected: it keeps its last target until the
|
|
268
|
+
* variant resolves, leaves without that exit, or starts without that variant's values.
|
|
249
269
|
*/
|
|
270
|
+
// #979 (group F; ADR-0074, ADR-0007's Amendment): core's one call site catches it, and the failure
|
|
271
|
+
// travels as the target's value, so no binding's update sees the throw.
|
|
250
272
|
export type WardicVariantResolver = (
|
|
251
273
|
// Motion's `custom` is `any`: a resolver declares its own (`(direction: number) => …`).
|
|
252
274
|
custom: any,
|
|
@@ -274,9 +296,10 @@ export interface WardicAnimationControls {
|
|
|
274
296
|
* Animates every element given these controls to `definition`, as a change of its `animate` would,
|
|
275
297
|
* its variant children following. `transitionOverride`, when given, is the transition of this change,
|
|
276
298
|
* over the definition's own, and its stagger. Resolves once each element and its children have landed.
|
|
299
|
+
* A function definition that throws for one element refuses the call, throwing, with no element changed.
|
|
277
300
|
*/
|
|
278
301
|
readonly start: (definition: WardicControlsDefinition, transitionOverride?: WardicTransition) => Promise<void>
|
|
279
|
-
/** Sets every element given these controls, and its variant children, at `definition` at once. */
|
|
302
|
+
/** Sets every element given these controls, and its variant children, at `definition` at once; refused, with none set, as `start` is. */
|
|
280
303
|
readonly set: (definition: WardicControlsDefinition) => void
|
|
281
304
|
/** Ends every element's running animation where it is. */
|
|
282
305
|
readonly stop: () => void
|
|
@@ -48,8 +48,10 @@
|
|
|
48
48
|
*
|
|
49
49
|
* Observability (CONTEXT.md convention): the hot path (`write`/`flush`) is the
|
|
50
50
|
* per-frame work, so — exactly like core's per-frame writes and the Clock's
|
|
51
|
-
* `tick` — it stays quiet (no span, no per-call log, no metric). A
|
|
52
|
-
* binding's hook,
|
|
51
|
+
* `tick` — it stays quiet (no span, no per-call log, no metric). A throw in one element's step (its
|
|
52
|
+
* binding's hook, the read of its own value, its Timeline values, its commit) is that element's: it
|
|
53
|
+
* commits nothing that frame, a run of them is reported once (`Report.failure`) until it commits again,
|
|
54
|
+
* and every other element still commits. Anything else a flush throws is reported and the gate
|
|
53
55
|
* goes on, so it can't fail the Frame loop's tick it runs in (ADR-0033).
|
|
54
56
|
*
|
|
55
57
|
* Unstable, for Wardic's own packages: public, with no semver promise.
|
|
@@ -58,6 +60,7 @@
|
|
|
58
60
|
*/
|
|
59
61
|
// Unstable: ADR-0071, decision 5. #672: dom's `internal/gate.ts`, moved for the spine to write through
|
|
60
62
|
// it in core; dom's `FlushGate` builds it with the DOM's edges (`DOM_GATE`) and gives it as a Layer.
|
|
63
|
+
// #969 (ADR-0033, *Amendment (#969)*): one element's failure in a flush is its own.
|
|
61
64
|
import * as FrameLoop from "../FrameLoop.ts"
|
|
62
65
|
import * as RefreshFrameSource from "../RefreshFrameSource.ts"
|
|
63
66
|
import * as Renderer from "../Renderer.ts"
|
|
@@ -109,8 +112,34 @@ export interface FlushSink {
|
|
|
109
112
|
readonly onCommit?: ((values: Readonly<Record<string, unknown>>) => void) | undefined
|
|
110
113
|
}
|
|
111
114
|
|
|
115
|
+
/**
|
|
116
|
+
* A flush's entries, in order, kept from one flush to the next (#895): `count` of them in use, the rest
|
|
117
|
+
* cleared. Emptied by its count, not `length = 0`, which V8 answers by dropping the array's storage, so it
|
|
118
|
+
* grew again every flush.
|
|
119
|
+
*/
|
|
120
|
+
interface EntryList {
|
|
121
|
+
readonly entries: Array<Entry | undefined>
|
|
122
|
+
count: number
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const entryListOf = (): EntryList => ({ entries: [], count: 0 })
|
|
126
|
+
|
|
127
|
+
/** `entry`, last in `list`. */
|
|
128
|
+
const addTo = (list: EntryList, entry: Entry): void => {
|
|
129
|
+
list.entries[list.count] = entry
|
|
130
|
+
list.count++
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** `list` cleared in place: its storage kept, its slots emptied, so it keeps no entry alive. */
|
|
134
|
+
const clear = (list: EntryList): void => {
|
|
135
|
+
for (let i = 0; i < list.count; i++) list.entries[i] = undefined
|
|
136
|
+
list.count = 0
|
|
137
|
+
}
|
|
138
|
+
|
|
112
139
|
/** Accumulated pre-`project` state for one registered element. */
|
|
113
140
|
interface Entry {
|
|
141
|
+
/** Its gate id: what a failure of its own is reported with (#969). */
|
|
142
|
+
readonly id: string
|
|
114
143
|
/** Merged value-map (partials `Object.assign`ed in by key). */
|
|
115
144
|
readonly values: Record<string, unknown>
|
|
116
145
|
/** Where this element's projected Patch goes. */
|
|
@@ -131,7 +160,14 @@ interface Entry {
|
|
|
131
160
|
* Whether its `onCommit` threw at its last call (#257 item 4): a run of throws is logged and
|
|
132
161
|
* reported at its first, so one that throws every frame logs once; a call that returns ends it.
|
|
133
162
|
*/
|
|
134
|
-
|
|
163
|
+
onCommitFailing: boolean
|
|
164
|
+
/**
|
|
165
|
+
* Whether one of its own steps threw at a flush since its last commit (#969): a run of them is reported
|
|
166
|
+
* at its first, so one that throws every frame logs once; a commit that lands ends it.
|
|
167
|
+
*/
|
|
168
|
+
stepFailing: boolean
|
|
169
|
+
/** Whether its sink's `onHeld` threw before it heard the keys held (#969): its next flush tells it again. */
|
|
170
|
+
heldUntold: boolean
|
|
135
171
|
/** Its patch, projected this flush and committed once the binding has heard the keys held. */
|
|
136
172
|
patch: Renderer.Patch | undefined
|
|
137
173
|
}
|
|
@@ -141,6 +177,8 @@ interface Output {
|
|
|
141
177
|
readonly atom: Atom.Writable<unknown>
|
|
142
178
|
last: unknown
|
|
143
179
|
readonly unmount: () => void
|
|
180
|
+
/** Whether its sets are throwing back a dependent's failure: reported at the first, again after a clean set. */
|
|
181
|
+
failing: boolean
|
|
144
182
|
}
|
|
145
183
|
|
|
146
184
|
/** What the gate calls of a key's Timeline value (#240): its sync with the values drawn, and its cancel. */
|
|
@@ -163,6 +201,9 @@ export interface GateEnvironment {
|
|
|
163
201
|
readonly templateKey: string
|
|
164
202
|
}
|
|
165
203
|
|
|
204
|
+
/** A step of one element's flush, as its failure is reported (#969): `prepare`'s report as its commit. */
|
|
205
|
+
type Step = "a commit" | "a beforeFirstCommit" | "an onHeld" | "a Timeline sync"
|
|
206
|
+
|
|
166
207
|
/** Each of `values` cancelled (#240). Per flush: a plain loop. */
|
|
167
208
|
const cancelEach = (values: Iterable<GateTimeline>): void => {
|
|
168
209
|
for (const value of values) value.cancel()
|
|
@@ -321,8 +362,8 @@ export const makeFlushGate = (runtime: FlushGateRuntime, options: FlushGateOptio
|
|
|
321
362
|
const endings = new Map<Entry, Array<GateTimeline>>()
|
|
322
363
|
// A frame flush's entries, in order, prepared and waiting for their commit; and those whose
|
|
323
364
|
// keys held changed, which the binding hears first. Reused each flush: the per-frame path.
|
|
324
|
-
const prepared
|
|
325
|
-
const heldChanged
|
|
365
|
+
const prepared = entryListOf()
|
|
366
|
+
const heldChanged = entryListOf()
|
|
326
367
|
|
|
327
368
|
/**
|
|
328
369
|
* Project one dirty entry's patch and restore the keys it dropped (once per element per flush),
|
|
@@ -330,11 +371,11 @@ export const makeFlushGate = (runtime: FlushGateRuntime, options: FlushGateOptio
|
|
|
330
371
|
* hears them. Its commit waits for the binding's `batch` of those (ADR-0034, *Amendment
|
|
331
372
|
* (#209)*). Plain calls only: this is the per-frame path.
|
|
332
373
|
*/
|
|
333
|
-
const prepare = (entry: Entry, into:
|
|
374
|
+
const prepare = (entry: Entry, into: EntryList, held: EntryList): void => {
|
|
334
375
|
const patch = project(entry.values)
|
|
335
376
|
entry.dirty = false
|
|
336
377
|
entry.patch = patch
|
|
337
|
-
into
|
|
378
|
+
addTo(into, entry)
|
|
338
379
|
const sink = entry.sink
|
|
339
380
|
const target = sink.target
|
|
340
381
|
const committed = entry.committed
|
|
@@ -357,12 +398,16 @@ export const makeFlushGate = (runtime: FlushGateRuntime, options: FlushGateOptio
|
|
|
357
398
|
if (key in patch) continue
|
|
358
399
|
if (Predicate.isUndefined(restore)) restore = {}
|
|
359
400
|
restore[key] = own
|
|
360
|
-
committed.delete(key)
|
|
361
401
|
}
|
|
362
402
|
}
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
403
|
+
// Committed before its keys are let go of, so a restore that throws is tried again at the next flush (#969).
|
|
404
|
+
if (Predicate.isNotUndefined(restore)) {
|
|
405
|
+
commit(target, restore)
|
|
406
|
+
for (const key in restore) committed.delete(key)
|
|
407
|
+
}
|
|
408
|
+
// The keys held changed (the usual frame changes none), or its sink threw before it heard them: the
|
|
409
|
+
// binding hears before the commit.
|
|
410
|
+
if ((added || Predicate.isNotUndefined(restore) || entry.heldUntold) && Predicate.isNotUndefined(sink.onHeld)) addTo(held, entry)
|
|
366
411
|
}
|
|
367
412
|
|
|
368
413
|
/**
|
|
@@ -375,11 +420,22 @@ export const makeFlushGate = (runtime: FlushGateRuntime, options: FlushGateOptio
|
|
|
375
420
|
for (const [entry, ended] of endings) {
|
|
376
421
|
if (Predicate.isUndefined(entry.patch)) continue
|
|
377
422
|
endings.delete(entry)
|
|
378
|
-
|
|
423
|
+
// Each on its own: one whose cancel throws stops none of the others (#969).
|
|
424
|
+
for (let i = 0; i < ended.length; i++) {
|
|
425
|
+
try {
|
|
426
|
+
ended[i].cancel()
|
|
427
|
+
} catch (defect) {
|
|
428
|
+
failedAt(entry, "a Timeline sync", defect)
|
|
429
|
+
}
|
|
430
|
+
}
|
|
379
431
|
}
|
|
380
432
|
for (const [entry, byKey] of timelines) {
|
|
381
433
|
if (Predicate.isUndefined(entry.patch)) continue
|
|
382
|
-
|
|
434
|
+
try {
|
|
435
|
+
for (const value of byKey.values()) value.sync(entry.values)
|
|
436
|
+
} catch (defect) {
|
|
437
|
+
failedAt(entry, "a Timeline sync", defect)
|
|
438
|
+
}
|
|
383
439
|
}
|
|
384
440
|
}
|
|
385
441
|
|
|
@@ -399,26 +455,60 @@ export const makeFlushGate = (runtime: FlushGateRuntime, options: FlushGateOptio
|
|
|
399
455
|
if (Predicate.isUndefined(patch)) return
|
|
400
456
|
entry.patch = undefined
|
|
401
457
|
commit(entry.sink.target, patch)
|
|
458
|
+
if (entry.stepFailing) entry.stepFailing = false
|
|
402
459
|
if (Predicate.isNotUndefined(entry.sink.onCommit)) committedSince.add(entry)
|
|
403
460
|
}
|
|
404
461
|
|
|
462
|
+
/**
|
|
463
|
+
* One of `entry`'s steps threw this flush (#969): its later steps skipped this frame, its patch with
|
|
464
|
+
* them, and the other elements' going on. A run of them is reported at its first, `step` naming it.
|
|
465
|
+
*/
|
|
466
|
+
// A failure's path, never the frame's: one place each loop's catch calls.
|
|
467
|
+
const failedAt = (entry: Entry, step: Step, defect: unknown): void => {
|
|
468
|
+
entry.patch = undefined
|
|
469
|
+
// Tried again at the gate's next flush, which it doesn't ask for itself: a Subject frozen for good would
|
|
470
|
+
// keep the host's frames running. A later write, its own or another element's, brings that flush.
|
|
471
|
+
entry.dirty = true
|
|
472
|
+
// Its sink's `onCommit` hears nothing of a frame it didn't commit in.
|
|
473
|
+
committedSince.delete(entry)
|
|
474
|
+
if (entry.stepFailing) return
|
|
475
|
+
entry.stepFailing = true
|
|
476
|
+
runtime.runFork(Effect.annotateLogs(Report.failure(`wardic.gate: ${step} failed`, Cause.die(defect)), { id: entry.id }))
|
|
477
|
+
}
|
|
478
|
+
|
|
405
479
|
/**
|
|
406
480
|
* The prepared entries, committed, after the binding has heard the keys held change, together, in
|
|
407
481
|
* its `batch` (#209); both lists emptied for the next flush.
|
|
408
482
|
*/
|
|
409
|
-
const commitAll = (entries:
|
|
410
|
-
if (held.
|
|
411
|
-
for (
|
|
412
|
-
entries.
|
|
413
|
-
|
|
483
|
+
const commitAll = (entries: EntryList, held: EntryList): void => {
|
|
484
|
+
if (held.count > 0) batch(() => tellHeld(held))
|
|
485
|
+
// A try for each element, its call direct (#969): a shared helper taking the step measured +20% a frame.
|
|
486
|
+
for (let i = 0; i < entries.count; i++) {
|
|
487
|
+
const entry = entries.entries[i] as Entry
|
|
488
|
+
try {
|
|
489
|
+
commitPrepared(entry)
|
|
490
|
+
} catch (defect) {
|
|
491
|
+
failedAt(entry, "a commit", defect)
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
clear(entries)
|
|
495
|
+
clear(held)
|
|
414
496
|
}
|
|
415
497
|
|
|
416
498
|
/** Each entry's `onHeld`, with every key the gate holds on its element now. */
|
|
417
|
-
const tellHeld = (held:
|
|
418
|
-
for (let i = 0; i < held.
|
|
419
|
-
const entry = held[i]
|
|
499
|
+
const tellHeld = (held: EntryList): void => {
|
|
500
|
+
for (let i = 0; i < held.count; i++) {
|
|
501
|
+
const entry = held.entries[i] as Entry
|
|
420
502
|
const onHeld = entry.sink.onHeld
|
|
421
|
-
if (Predicate.
|
|
503
|
+
if (Predicate.isUndefined(onHeld)) continue
|
|
504
|
+
try {
|
|
505
|
+
onHeld(Array.from(entry.committed.keys()))
|
|
506
|
+
if (entry.heldUntold) entry.heldUntold = false
|
|
507
|
+
} catch (defect) {
|
|
508
|
+
// Told again at its next flush, before its commit (#969).
|
|
509
|
+
entry.heldUntold = true
|
|
510
|
+
failedAt(entry, "an onHeld", defect)
|
|
511
|
+
}
|
|
422
512
|
}
|
|
423
513
|
}
|
|
424
514
|
|
|
@@ -441,10 +531,10 @@ export const makeFlushGate = (runtime: FlushGateRuntime, options: FlushGateOptio
|
|
|
441
531
|
delete latest[templateKey]
|
|
442
532
|
try {
|
|
443
533
|
onCommit(latest)
|
|
444
|
-
entry.
|
|
534
|
+
entry.onCommitFailing = false
|
|
445
535
|
} catch (defect) {
|
|
446
|
-
if (entry.
|
|
447
|
-
entry.
|
|
536
|
+
if (entry.onCommitFailing) continue
|
|
537
|
+
entry.onCommitFailing = true
|
|
448
538
|
runtime.runFork(Report.failure("wardic.gate: an onCommit failed", Cause.die(defect)))
|
|
449
539
|
}
|
|
450
540
|
}
|
|
@@ -457,6 +547,9 @@ export const makeFlushGate = (runtime: FlushGateRuntime, options: FlushGateOptio
|
|
|
457
547
|
* written in the same frame, and commits with it. An unchanged one skips the registry. Plain
|
|
458
548
|
* calls: a write is the per-frame path.
|
|
459
549
|
*/
|
|
550
|
+
// #979, group D (ADR-0074): an output's dependent that throws (an app's Atom over a ward's `read(key)`)
|
|
551
|
+
// is its own. The registry has set the output and told its other listeners before the throw comes back,
|
|
552
|
+
// so the write goes on, the element's other outputs with it: before, it came out of the ward's own leg.
|
|
460
553
|
const setOutputs = (entry: Entry): void => {
|
|
461
554
|
const outputs = entry.outputs
|
|
462
555
|
if (Predicate.isUndefined(outputs)) return
|
|
@@ -464,7 +557,20 @@ export const makeFlushGate = (runtime: FlushGateRuntime, options: FlushGateOptio
|
|
|
464
557
|
const value = entry.values[key]
|
|
465
558
|
if (value === output.last) continue
|
|
466
559
|
output.last = value
|
|
560
|
+
setOutput(entry.id, key, output, value)
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/** `output` set to `value`, its dependent's throw its own: reported once a run of throws, until a clean set. */
|
|
565
|
+
// The try is here, out of the loops that call it (`setOutputs`', `endOutputs`'): in the body of
|
|
566
|
+
// `setOutputs`' loop over the element's outputs Map, it measured +5–8% on Node's write.
|
|
567
|
+
const setOutput = (id: string, key: string, output: Output, value: unknown): void => {
|
|
568
|
+
try {
|
|
467
569
|
registry.set(output.atom, value)
|
|
570
|
+
if (output.failing) output.failing = false
|
|
571
|
+
} catch (defect) {
|
|
572
|
+
if (!output.failing) runtime.runFork(Effect.annotateLogs(Report.failure("wardic.gate: an output failed", Cause.die(defect)), { id, key }))
|
|
573
|
+
output.failing = true
|
|
468
574
|
}
|
|
469
575
|
}
|
|
470
576
|
|
|
@@ -477,9 +583,15 @@ export const makeFlushGate = (runtime: FlushGateRuntime, options: FlushGateOptio
|
|
|
477
583
|
for (const id of firstCommits) {
|
|
478
584
|
const entry = accumulator.get(id)
|
|
479
585
|
if (Predicate.isUndefined(entry) || !entry.dirty) continue
|
|
480
|
-
firstCommits.delete(id)
|
|
481
586
|
const hook = entry.sink.beforeFirstCommit
|
|
482
|
-
|
|
587
|
+
try {
|
|
588
|
+
if (Predicate.isNotUndefined(hook)) hook()
|
|
589
|
+
// Its own: a hook that registered the id again leaves the new entry's switch to come (#969).
|
|
590
|
+
if (accumulator.get(id) === entry) firstCommits.delete(id)
|
|
591
|
+
} catch (defect) {
|
|
592
|
+
// Kept, so the gate's next flush switches it; nothing of it commits before (#969).
|
|
593
|
+
failedAt(entry, "a beforeFirstCommit", defect)
|
|
594
|
+
}
|
|
483
595
|
}
|
|
484
596
|
}
|
|
485
597
|
|
|
@@ -490,13 +602,22 @@ export const makeFlushGate = (runtime: FlushGateRuntime, options: FlushGateOptio
|
|
|
490
602
|
if (firstCommits.size > 0) batch(runFirstCommits)
|
|
491
603
|
// Every dirty element, once. No auto-reschedule — the next write() does. A write()
|
|
492
604
|
// from an effect a sink's hook runs requests the next frame (it isn't stranded).
|
|
493
|
-
for (const entry of accumulator.values())
|
|
605
|
+
for (const entry of accumulator.values()) {
|
|
606
|
+
if (!entry.dirty) continue
|
|
607
|
+
// Its Starting-style switch threw this frame: it waits for the next flush's (#969).
|
|
608
|
+
if (firstCommits.size > 0 && firstCommits.has(entry.id)) continue
|
|
609
|
+
try {
|
|
610
|
+
prepare(entry, prepared, heldChanged)
|
|
611
|
+
} catch (defect) {
|
|
612
|
+
failedAt(entry, "a commit", defect)
|
|
613
|
+
}
|
|
614
|
+
}
|
|
494
615
|
if (timelines.size > 0 || endings.size > 0) syncTimelines()
|
|
495
616
|
commitAll(prepared, heldChanged)
|
|
496
617
|
if (committedSince.size > 0) tellCommitted()
|
|
497
618
|
} catch (defect) {
|
|
498
|
-
prepared
|
|
499
|
-
heldChanged
|
|
619
|
+
clear(prepared)
|
|
620
|
+
clear(heldChanged)
|
|
500
621
|
runtime.runFork(Report.failure("wardic.gate: a flush failed", Cause.die(defect)))
|
|
501
622
|
}
|
|
502
623
|
if (afterFlushes.length > 0) runAfterFlushes()
|
|
@@ -544,8 +665,11 @@ export const makeFlushGate = (runtime: FlushGateRuntime, options: FlushGateOptio
|
|
|
544
665
|
dirty: false,
|
|
545
666
|
committed: new Map(),
|
|
546
667
|
outputs: outputsById.get(id),
|
|
668
|
+
id,
|
|
547
669
|
latest: undefined,
|
|
548
|
-
|
|
670
|
+
onCommitFailing: false,
|
|
671
|
+
stepFailing: false,
|
|
672
|
+
heldUntold: false,
|
|
549
673
|
patch: undefined,
|
|
550
674
|
}
|
|
551
675
|
// An entry the id had: its Timeline values end with it (#240).
|
|
@@ -563,12 +687,15 @@ export const makeFlushGate = (runtime: FlushGateRuntime, options: FlushGateOptio
|
|
|
563
687
|
}
|
|
564
688
|
|
|
565
689
|
/** `id`'s live outputs, each set to `undefined` and forgotten: its element is gone. */
|
|
690
|
+
// #979, row 42 (ADR-0074): set through `setOutput`, so a dependent that throws as its element leaves is
|
|
691
|
+
// reported, and every output still ends: before, its throw came out of the unregister, a binding's
|
|
692
|
+
// cleanup, and left that output and the later ones mounted.
|
|
566
693
|
const endOutputs = (id: string): void => {
|
|
567
694
|
const outputs = outputsById.get(id)
|
|
568
695
|
if (Predicate.isUndefined(outputs)) return
|
|
569
696
|
outputsById.delete(id)
|
|
570
|
-
for (const output of outputs
|
|
571
|
-
|
|
697
|
+
for (const [key, output] of outputs) {
|
|
698
|
+
setOutput(id, key, output, undefined)
|
|
572
699
|
output.unmount()
|
|
573
700
|
}
|
|
574
701
|
}
|
|
@@ -593,7 +720,7 @@ export const makeFlushGate = (runtime: FlushGateRuntime, options: FlushGateOptio
|
|
|
593
720
|
// Made `undefined` and mounted until its element unregisters, not kept alive: a kept-alive
|
|
594
721
|
// Atom's node never leaves the registry, and one left behind reads `undefined` afresh.
|
|
595
722
|
const atom = Atom.make<unknown>(undefined)
|
|
596
|
-
const output: Output = { atom, last: undefined, unmount: registry.mount(atom) }
|
|
723
|
+
const output: Output = { atom, last: undefined, unmount: registry.mount(atom), failing: false }
|
|
597
724
|
outputs.set(key, output)
|
|
598
725
|
const value = committedValueOf(id, key)
|
|
599
726
|
if (Predicate.isNotUndefined(value)) {
|
|
@@ -627,11 +754,16 @@ export const makeFlushGate = (runtime: FlushGateRuntime, options: FlushGateOptio
|
|
|
627
754
|
// flush (a frame later for an element mounted inside a frame). The frame flush switches.
|
|
628
755
|
// A commit here is told at the frame flush (#233): the write that made it scheduled that flush.
|
|
629
756
|
// Its own lists: a pass may run from a hook the frame flush's `batch` runs.
|
|
630
|
-
const entries
|
|
631
|
-
const held
|
|
757
|
+
const entries = entryListOf()
|
|
758
|
+
const held = entryListOf()
|
|
632
759
|
for (const id of written) {
|
|
633
760
|
const entry = accumulator.get(id)
|
|
634
|
-
if (Predicate.
|
|
761
|
+
if (Predicate.isUndefined(entry) || !entry.dirty) continue
|
|
762
|
+
try {
|
|
763
|
+
prepare(entry, entries, held)
|
|
764
|
+
} catch (defect) {
|
|
765
|
+
failedAt(entry, "a commit", defect)
|
|
766
|
+
}
|
|
635
767
|
}
|
|
636
768
|
if (timelines.size > 0 || endings.size > 0) syncTimelines()
|
|
637
769
|
commitAll(entries, held)
|
|
@@ -30,7 +30,10 @@ import * as RefreshFrameSource from "../RefreshFrameSource.ts"
|
|
|
30
30
|
export interface FrameEffectsOptions {
|
|
31
31
|
/** Asks the Environment for a frame, whose end runs the effects. Called once a request, until the run. */
|
|
32
32
|
readonly requestFrame: () => void
|
|
33
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* What an effect that throws reports, at the first frame of a run of throws: its next frame that
|
|
35
|
+
* returns ends the run. The rest of the frame's effects still run.
|
|
36
|
+
*/
|
|
34
37
|
readonly report: (defect: unknown) => void
|
|
35
38
|
}
|
|
36
39
|
|
|
@@ -64,6 +67,13 @@ export const make = (options: FrameEffectsOptions): FrameEffects => {
|
|
|
64
67
|
let running = false
|
|
65
68
|
let removedInRun = 0
|
|
66
69
|
let asked = false
|
|
70
|
+
// #979 group I, row 22 (ADR-0074 decision 3): a run of throws is reported once, at its first. A throw is
|
|
71
|
+
// its run's first unless the entry threw at the run before, so a frame it returns from ends the run. The
|
|
72
|
+
// runs are numbered, and the run an entry last threw in is kept here, written only in the catch: the
|
|
73
|
+
// clean path does nothing. A flag on the entry cleared there cost Node 12% on a bare effect, and a number
|
|
74
|
+
// on the entry written in the catch 3% (group I's microbench); this one nothing.
|
|
75
|
+
let runs = 0
|
|
76
|
+
const threwAt = new Map<Entry, number>()
|
|
67
77
|
|
|
68
78
|
/** The entries no longer live taken out, in place, keeping the rest's order. */
|
|
69
79
|
const compact = (): void => {
|
|
@@ -81,6 +91,7 @@ export const make = (options: FrameEffectsOptions): FrameEffects => {
|
|
|
81
91
|
return () => {
|
|
82
92
|
if (!entry.live) return
|
|
83
93
|
entry.live = false
|
|
94
|
+
threwAt.delete(entry)
|
|
84
95
|
if (running) {
|
|
85
96
|
removedInRun++
|
|
86
97
|
return
|
|
@@ -98,6 +109,7 @@ export const make = (options: FrameEffectsOptions): FrameEffects => {
|
|
|
98
109
|
const run: FrameEffects["run"] = (time) => {
|
|
99
110
|
asked = false
|
|
100
111
|
running = true
|
|
112
|
+
runs++
|
|
101
113
|
// Those added before the run: one added in it waits for the next frame.
|
|
102
114
|
const count = entries.length
|
|
103
115
|
try {
|
|
@@ -107,7 +119,8 @@ export const make = (options: FrameEffectsOptions): FrameEffects => {
|
|
|
107
119
|
try {
|
|
108
120
|
entry.effect(time)
|
|
109
121
|
} catch (defect) {
|
|
110
|
-
report(defect)
|
|
122
|
+
if (threwAt.get(entry) !== runs - 1) report(defect)
|
|
123
|
+
threwAt.set(entry, runs)
|
|
111
124
|
}
|
|
112
125
|
}
|
|
113
126
|
} finally {
|