@wardic/core 1.3.1 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/BaseValue.d.ts +1 -1
- package/dist/BaseValue.js +2 -2
- package/dist/BaseValue.js.map +1 -1
- package/dist/Batch.d.ts +5 -9
- package/dist/Batch.d.ts.map +1 -1
- package/dist/Batch.js +166 -20
- package/dist/Batch.js.map +1 -1
- package/dist/Clock.d.ts +16 -0
- package/dist/Clock.d.ts.map +1 -1
- package/dist/Clock.js +13 -0
- package/dist/Clock.js.map +1 -1
- package/dist/DragRecognizer.d.ts +10 -5
- package/dist/DragRecognizer.d.ts.map +1 -1
- package/dist/DragRecognizer.js +60 -24
- package/dist/DragRecognizer.js.map +1 -1
- package/dist/Frame.js +1 -1
- package/dist/Frame.js.map +1 -1
- package/dist/InputFeed.d.ts +10 -7
- package/dist/InputFeed.d.ts.map +1 -1
- package/dist/InputFeed.js +16 -35
- package/dist/InputFeed.js.map +1 -1
- package/dist/LiveValue.d.ts +9 -3
- package/dist/LiveValue.d.ts.map +1 -1
- package/dist/LiveValue.js +160 -14
- package/dist/LiveValue.js.map +1 -1
- package/dist/Machine.d.ts +16 -6
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +50 -27
- package/dist/Machine.js.map +1 -1
- package/dist/Playback.d.ts.map +1 -1
- package/dist/Playback.js +10 -8
- package/dist/Playback.js.map +1 -1
- package/dist/Recognizer.d.ts +1 -1
- package/dist/Recognizer.d.ts.map +1 -1
- package/dist/Recognizer.js +9 -4
- package/dist/Recognizer.js.map +1 -1
- package/dist/internal/frameLoop.d.ts +10 -2
- package/dist/internal/frameLoop.d.ts.map +1 -1
- package/dist/internal/frameLoop.js +148 -18
- package/dist/internal/frameLoop.js.map +1 -1
- package/dist/internal/guarded.d.ts +16 -0
- package/dist/internal/guarded.d.ts.map +1 -0
- package/dist/internal/guarded.js +68 -0
- package/dist/internal/guarded.js.map +1 -0
- package/dist/internal/stepper.d.ts +9 -3
- package/dist/internal/stepper.d.ts.map +1 -1
- package/dist/internal/stepper.js +5 -4
- package/dist/internal/stepper.js.map +1 -1
- package/dist/unstable/AnimationControls.d.ts +15 -8
- package/dist/unstable/AnimationControls.d.ts.map +1 -1
- package/dist/unstable/AnimationControls.js +36 -15
- package/dist/unstable/AnimationControls.js.map +1 -1
- package/dist/unstable/AppearHandoff.d.ts +6 -0
- package/dist/unstable/AppearHandoff.d.ts.map +1 -1
- package/dist/unstable/AppearHandoff.js.map +1 -1
- package/dist/unstable/Config.d.ts +5 -1
- package/dist/unstable/Config.d.ts.map +1 -1
- package/dist/unstable/Config.js.map +1 -1
- package/dist/unstable/FlushGate.d.ts +4 -2
- package/dist/unstable/FlushGate.d.ts.map +1 -1
- package/dist/unstable/FlushGate.js +155 -38
- package/dist/unstable/FlushGate.js.map +1 -1
- package/dist/unstable/FrameEffects.d.ts +4 -1
- package/dist/unstable/FrameEffects.d.ts.map +1 -1
- package/dist/unstable/FrameEffects.js +12 -1
- package/dist/unstable/FrameEffects.js.map +1 -1
- package/dist/unstable/Imperative.d.ts +13 -4
- package/dist/unstable/Imperative.d.ts.map +1 -1
- package/dist/unstable/Imperative.js +202 -43
- package/dist/unstable/Imperative.js.map +1 -1
- package/dist/unstable/MeasuredPairs.d.ts +6 -2
- package/dist/unstable/MeasuredPairs.d.ts.map +1 -1
- package/dist/unstable/MeasuredPairs.js.map +1 -1
- package/dist/unstable/PresenceRecord.d.ts +4 -0
- package/dist/unstable/PresenceRecord.d.ts.map +1 -1
- package/dist/unstable/PresenceRecord.js.map +1 -1
- package/dist/unstable/Report.d.ts +7 -0
- package/dist/unstable/Report.d.ts.map +1 -1
- package/dist/unstable/Report.js +17 -1
- package/dist/unstable/Report.js.map +1 -1
- package/dist/unstable/RetargetLegs.d.ts +6 -0
- package/dist/unstable/RetargetLegs.d.ts.map +1 -1
- package/dist/unstable/RetargetLegs.js +15 -0
- package/dist/unstable/RetargetLegs.js.map +1 -1
- package/dist/unstable/Spine.d.ts +53 -7
- package/dist/unstable/Spine.d.ts.map +1 -1
- package/dist/unstable/Spine.js +190 -40
- package/dist/unstable/Spine.js.map +1 -1
- package/dist/unstable/VariantTarget.d.ts +25 -3
- package/dist/unstable/VariantTarget.d.ts.map +1 -1
- package/dist/unstable/VariantTarget.js +66 -13
- package/dist/unstable/VariantTarget.js.map +1 -1
- package/dist/unstable/VariantTree.d.ts +37 -3
- package/dist/unstable/VariantTree.d.ts.map +1 -1
- package/dist/unstable/VariantTree.js +54 -7
- package/dist/unstable/VariantTree.js.map +1 -1
- package/package.json +1 -1
- package/src/BaseValue.ts +2 -2
- package/src/Batch.ts +167 -17
- package/src/Clock.ts +20 -0
- package/src/DragRecognizer.ts +82 -30
- package/src/Frame.ts +1 -1
- package/src/InputFeed.ts +37 -40
- package/src/LiveValue.ts +140 -14
- package/src/Machine.ts +67 -34
- package/src/Playback.ts +10 -8
- package/src/Recognizer.ts +9 -3
- package/src/internal/frameLoop.ts +165 -19
- package/src/internal/guarded.ts +69 -0
- package/src/internal/stepper.ts +14 -5
- package/src/unstable/AnimationControls.ts +49 -21
- package/src/unstable/AppearHandoff.ts +7 -0
- package/src/unstable/Config.ts +7 -1
- package/src/unstable/FlushGate.ts +169 -37
- package/src/unstable/FrameEffects.ts +15 -2
- package/src/unstable/Imperative.ts +219 -48
- package/src/unstable/MeasuredPairs.ts +7 -1
- package/src/unstable/PresenceRecord.ts +4 -0
- package/src/unstable/Report.ts +19 -1
- package/src/unstable/RetargetLegs.ts +14 -0
- package/src/unstable/Spine.ts +235 -40
- package/src/unstable/VariantTarget.ts +93 -14
- package/src/unstable/VariantTree.ts +87 -6
package/src/Batch.ts
CHANGED
|
@@ -18,10 +18,11 @@
|
|
|
18
18
|
// a member's keys at `slot * stride + k` (#663's shape); stepped by `Spring.matrixFor`'s exact step
|
|
19
19
|
// (#370), the probe's loop (`.tmp/564-canvas/perf/group.ts` on `probe/564-canvas`).
|
|
20
20
|
import * as Arr from "effect/Array"
|
|
21
|
+
import * as Cause from "effect/Cause"
|
|
22
|
+
import * as Context from "effect/Context"
|
|
21
23
|
import * as Effect from "effect/Effect"
|
|
22
24
|
import { identity } from "effect/Function"
|
|
23
25
|
import * as Inspectable from "effect/Inspectable"
|
|
24
|
-
import * as Iter from "effect/Iterable"
|
|
25
26
|
import * as Match from "effect/Match"
|
|
26
27
|
import { type Pipeable, pipeArguments } from "effect/Pipeable"
|
|
27
28
|
import * as Predicate from "effect/Predicate"
|
|
@@ -35,6 +36,7 @@ import type * as Playback from "./Playback.ts"
|
|
|
35
36
|
import * as Scalar from "./Scalar.ts"
|
|
36
37
|
import * as Spring from "./Spring.ts"
|
|
37
38
|
import * as UnitScale from "./UnitScale.ts"
|
|
39
|
+
import * as Report from "./unstable/Report.ts"
|
|
38
40
|
import { dual } from "./internal/dual.ts"
|
|
39
41
|
import { tickOf, writableOf } from "./internal/playhead.ts"
|
|
40
42
|
import { resolveKeyframes } from "./internal/keyframes.ts"
|
|
@@ -271,6 +273,20 @@ interface State<S> {
|
|
|
271
273
|
running: number
|
|
272
274
|
/** How many runs it has had: the next one's number. */
|
|
273
275
|
runs: number
|
|
276
|
+
/** What its failures are reported on: its last run's services, an empty Context before its first. */
|
|
277
|
+
services: Context.Context<never>
|
|
278
|
+
/** Whether a member's write threw in this step. */
|
|
279
|
+
writeThrewInStep: boolean
|
|
280
|
+
/** Whether a member's write throw is reported, with no step since that wrote every member clean. */
|
|
281
|
+
writeReported: boolean
|
|
282
|
+
/** Whether a member's start partway threw in this step. */
|
|
283
|
+
startThrewInStep: boolean
|
|
284
|
+
/** Whether a member's start throw is reported, with no step since that started every member clean. */
|
|
285
|
+
startReported: boolean
|
|
286
|
+
/** Whether its writer's `flush` throw is reported, with no `flush` since that returned. */
|
|
287
|
+
flushReported: boolean
|
|
288
|
+
/** Whether its `onFrame` throw is reported, with no `onFrame` since that returned. */
|
|
289
|
+
onFrameReported: boolean
|
|
274
290
|
}
|
|
275
291
|
|
|
276
292
|
const Proto = {
|
|
@@ -474,6 +490,13 @@ export const make = <S>(options: Options<S>): Batch<S> => {
|
|
|
474
490
|
frame: 0,
|
|
475
491
|
running: 0,
|
|
476
492
|
runs: 0,
|
|
493
|
+
services: Context.empty(),
|
|
494
|
+
writeThrewInStep: false,
|
|
495
|
+
writeReported: false,
|
|
496
|
+
startThrewInStep: false,
|
|
497
|
+
startReported: false,
|
|
498
|
+
flushReported: false,
|
|
499
|
+
onFrameReported: false,
|
|
477
500
|
}
|
|
478
501
|
// The Batch's own transitions, pinned: the first entries, rule 0 the first key's.
|
|
479
502
|
state.ownRules = rulesOf(state, options.transition, unnamedKey(state))
|
|
@@ -798,6 +821,48 @@ export const retarget: {
|
|
|
798
821
|
return setOff
|
|
799
822
|
})
|
|
800
823
|
|
|
824
|
+
/**
|
|
825
|
+
* `defect`, a failure on the Batch's path named by `message`, logged and handed to the ErrorReporters of
|
|
826
|
+
* what it runs on, annotated with its member's slot where it's one member's.
|
|
827
|
+
*/
|
|
828
|
+
// #977 (ADR-0074): one member's failure is its own. Its failure path, off the per-frame one.
|
|
829
|
+
const report = <S>(state: State<S>, message: string, defect: unknown, slot?: number): void => {
|
|
830
|
+
const failure = Report.failure(message, Cause.die(defect))
|
|
831
|
+
if (Predicate.isUndefined(slot)) {
|
|
832
|
+
Effect.runForkWith(state.services)(failure)
|
|
833
|
+
return
|
|
834
|
+
}
|
|
835
|
+
Effect.runForkWith(state.services)(Effect.annotateLogs(failure, { member: slot }))
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
/** A member's write that threw: reported once, until a step writes every member clean. */
|
|
839
|
+
const writeFailed = <S>(state: State<S>, slot: number, defect: unknown): void => {
|
|
840
|
+
state.writeThrewInStep = true
|
|
841
|
+
if (state.writeReported) return
|
|
842
|
+
state.writeReported = true
|
|
843
|
+
report(state, "wardic.batch: a member's write failed", defect, slot)
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
/** A member's start partway that threw: reported once, until a step starts every member clean. */
|
|
847
|
+
const startFailed = <S>(state: State<S>, slot: number, defect: unknown): void => {
|
|
848
|
+
state.startThrewInStep = true
|
|
849
|
+
if (state.startReported) return
|
|
850
|
+
state.startReported = true
|
|
851
|
+
report(state, "wardic.batch: a member's start failed", defect, slot)
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
/** The writer's `flush`, a step's or a draw's: a throw reported once, until one returns. */
|
|
855
|
+
const flushed = <S>(state: State<S>): void => {
|
|
856
|
+
try {
|
|
857
|
+
state.flush()
|
|
858
|
+
if (state.flushReported) state.flushReported = false
|
|
859
|
+
} catch (defect) {
|
|
860
|
+
if (state.flushReported) return
|
|
861
|
+
state.flushReported = true
|
|
862
|
+
report(state, "wardic.batch: its writer's flush failed", defect)
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
|
|
801
866
|
/** Whether any member moves: one `step` would move. */
|
|
802
867
|
export const isMoving = <S>(self: Batch<S>): boolean => {
|
|
803
868
|
const state = stateOf(self)
|
|
@@ -809,6 +874,11 @@ export const isMoving = <S>(self: Batch<S>): boolean => {
|
|
|
809
874
|
* outside a step set (an `enter`, a `replace`, a start from a given value, a play, seek, stop or cancel):
|
|
810
875
|
* whether nothing moves now. One a delay or a paused Playhead holds still isn't written. The run on the
|
|
811
876
|
* Frame loop calls it each tick.
|
|
877
|
+
*
|
|
878
|
+
* One member's failure is its own: a write or a start partway that throws is reported once, until a step
|
|
879
|
+
* runs every member's clean, and its member steps on with the others. A landing's callback that throws is
|
|
880
|
+
* reported each time, the other members told and the other changes landed; the writer's `flush` and
|
|
881
|
+
* `onFrame` once until they return. Each is reported on what the Batch last ran on.
|
|
812
882
|
*/
|
|
813
883
|
// Per frame (ADR-0025, ADR-0030 decisions 10 and 11): `dt` clamped once (#78), then the two moving
|
|
814
884
|
// lists. Each steps a key by `springValues`' exact step, or `Machine.tween`'s, its spring's matrix
|
|
@@ -817,12 +887,35 @@ export const step = <S>(self: Batch<S>, dt: number): boolean => {
|
|
|
817
887
|
const state = stateOf(self)
|
|
818
888
|
const clamped = Math.min(dt, Machine.MAX_DT)
|
|
819
889
|
state.frame = state.frame + 1
|
|
890
|
+
// Whether a member's write or start throws in this step: a `draw`'s between steps isn't one (#977).
|
|
891
|
+
state.writeThrewInStep = false
|
|
892
|
+
state.startThrewInStep = false
|
|
820
893
|
if (state.startList.length > 0) startPass(state, clamped)
|
|
821
894
|
if (state.plainCount > 0) stepPlain(state, clamped)
|
|
822
895
|
if (state.ruledCount > 0) stepRuled(state, clamped)
|
|
823
|
-
|
|
824
|
-
state.
|
|
825
|
-
|
|
896
|
+
// Each change's landing its own: a callback that throws leaves the others to land (#977).
|
|
897
|
+
if (state.animations.size > 0) {
|
|
898
|
+
for (const animation of state.animations) {
|
|
899
|
+
try {
|
|
900
|
+
checkLanding(animation)
|
|
901
|
+
} catch (defect) {
|
|
902
|
+
report(state, "wardic.batch: a change's landing failed", defect)
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
flushed(state)
|
|
907
|
+
try {
|
|
908
|
+
state.onFrame()
|
|
909
|
+
if (state.onFrameReported) state.onFrameReported = false
|
|
910
|
+
} catch (defect) {
|
|
911
|
+
if (!state.onFrameReported) {
|
|
912
|
+
state.onFrameReported = true
|
|
913
|
+
report(state, "wardic.batch: an onFrame failed", defect)
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
// A path that stepped clean is reported again at its next throw (#977).
|
|
917
|
+
if (!state.writeThrewInStep) state.writeReported = false
|
|
918
|
+
if (!state.startThrewInStep) state.startReported = false
|
|
826
919
|
// Counted after `onFrame`: a change it makes keeps the run going.
|
|
827
920
|
if (state.plainCount + state.ruledCount > 0) return false
|
|
828
921
|
// A driven change playing, paused at rest, still holds its entries.
|
|
@@ -843,9 +936,13 @@ export const draw = <S>(self: Batch<S>): void => {
|
|
|
843
936
|
for (let slot = 0; slot < state.used; slot++) {
|
|
844
937
|
if ((flags[slot] & LIVE) === 0) continue
|
|
845
938
|
flags[slot] = flags[slot] & ~DUE
|
|
846
|
-
|
|
939
|
+
try {
|
|
940
|
+
write(subjects[slot] as S, positions, slot * stride)
|
|
941
|
+
} catch (defect) {
|
|
942
|
+
writeFailed(state, slot, defect)
|
|
943
|
+
}
|
|
847
944
|
}
|
|
848
|
-
state
|
|
945
|
+
flushed(state)
|
|
849
946
|
}
|
|
850
947
|
|
|
851
948
|
/**
|
|
@@ -936,7 +1033,13 @@ const stepPlain = <S>(state: State<S>, clamped: number): void => {
|
|
|
936
1033
|
elapsed[at] = time
|
|
937
1034
|
}
|
|
938
1035
|
// One a delay holds still isn't written: an unchanged write is a style write all the same.
|
|
939
|
-
if (moved)
|
|
1036
|
+
if (moved) {
|
|
1037
|
+
try {
|
|
1038
|
+
write(subjects[slot] as S, positions, base)
|
|
1039
|
+
} catch (defect) {
|
|
1040
|
+
writeFailed(state, slot, defect)
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
940
1043
|
// At rest: still its member's, in neither list.
|
|
941
1044
|
if (still) {
|
|
942
1045
|
flags[slot] = LIVE
|
|
@@ -1066,7 +1169,13 @@ const stepRuled = <S>(state: State<S>, clamped: number): void => {
|
|
|
1066
1169
|
positions[at] = position
|
|
1067
1170
|
velocities[at] = speed
|
|
1068
1171
|
}
|
|
1069
|
-
if (moved)
|
|
1172
|
+
if (moved) {
|
|
1173
|
+
try {
|
|
1174
|
+
write(subjects[slot] as S, positions, base)
|
|
1175
|
+
} catch (defect) {
|
|
1176
|
+
writeFailed(state, slot, defect)
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1070
1179
|
// At rest: still its member's, in neither list (a member is in one at most).
|
|
1071
1180
|
if (still) {
|
|
1072
1181
|
flags[slot] = LIVE
|
|
@@ -1167,7 +1276,13 @@ const stepRuledDriven = <S>(state: State<S>): void => {
|
|
|
1167
1276
|
positions[at] = position
|
|
1168
1277
|
velocities[at] = speed
|
|
1169
1278
|
}
|
|
1170
|
-
if (moved)
|
|
1279
|
+
if (moved) {
|
|
1280
|
+
try {
|
|
1281
|
+
write(subjects[slot] as S, positions, base)
|
|
1282
|
+
} catch (defect) {
|
|
1283
|
+
writeFailed(state, slot, defect)
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1171
1286
|
// At rest: still its member's, in neither list (a member is in one at most).
|
|
1172
1287
|
if (still) {
|
|
1173
1288
|
flags[slot] = LIVE
|
|
@@ -1418,7 +1533,13 @@ const startedPartway = <S>(state: State<S>, slot: number, dt: number): boolean =
|
|
|
1418
1533
|
const { stride, elapsed, rules, positions, velocities, targets, originVelocities, startAts } = state
|
|
1419
1534
|
const startAt = UndefinedOr.getOrThrow(startAts[slot])
|
|
1420
1535
|
startAts[slot] = undefined
|
|
1421
|
-
|
|
1536
|
+
// A start that throws is its member's: it starts from its start, as `NaN` gives (#977).
|
|
1537
|
+
let time = Number.NaN
|
|
1538
|
+
try {
|
|
1539
|
+
time = startAt(slot)
|
|
1540
|
+
} catch (defect) {
|
|
1541
|
+
startFailed(state, slot, defect)
|
|
1542
|
+
}
|
|
1422
1543
|
const base = slot * stride
|
|
1423
1544
|
const started = !Number.isNaN(time)
|
|
1424
1545
|
for (let k = 0; k < stride; k++) {
|
|
@@ -1439,7 +1560,11 @@ const startedPartway = <S>(state: State<S>, slot: number, dt: number): boolean =
|
|
|
1439
1560
|
}
|
|
1440
1561
|
if (started) {
|
|
1441
1562
|
state.flags[slot] = state.flags[slot] & ~DUE
|
|
1442
|
-
|
|
1563
|
+
try {
|
|
1564
|
+
state.write(state.subjects[slot] as S, positions, base)
|
|
1565
|
+
} catch (defect) {
|
|
1566
|
+
writeFailed(state, slot, defect)
|
|
1567
|
+
}
|
|
1443
1568
|
}
|
|
1444
1569
|
return started
|
|
1445
1570
|
}
|
|
@@ -1527,7 +1652,14 @@ const tellIdle = <S>(animation: AnimationState<S>): void => {
|
|
|
1527
1652
|
animation.idleTold = true
|
|
1528
1653
|
const tell = animation.options.onMemberLanded
|
|
1529
1654
|
if (Predicate.isUndefined(tell)) return
|
|
1530
|
-
|
|
1655
|
+
// Each member's own: a landing that throws leaves the others told (#977).
|
|
1656
|
+
Arr.forEach(animation.idle, (slot) => {
|
|
1657
|
+
try {
|
|
1658
|
+
tell(slot)
|
|
1659
|
+
} catch (defect) {
|
|
1660
|
+
report(animation.state, "wardic.batch: a member's landing failed", defect, slot)
|
|
1661
|
+
}
|
|
1662
|
+
})
|
|
1531
1663
|
}
|
|
1532
1664
|
|
|
1533
1665
|
/**
|
|
@@ -1552,7 +1684,12 @@ const tellMembers = <S>(animation: AnimationState<S>, tell: (slot: number) => vo
|
|
|
1552
1684
|
}
|
|
1553
1685
|
if (!kept || !atRest) continue
|
|
1554
1686
|
told[r] = 1
|
|
1555
|
-
|
|
1687
|
+
const slot = slotAt(state, ats[firsts[r]])
|
|
1688
|
+
try {
|
|
1689
|
+
tell(slot)
|
|
1690
|
+
} catch (defect) {
|
|
1691
|
+
report(state, "wardic.batch: a member's landing failed", defect, slot)
|
|
1692
|
+
}
|
|
1556
1693
|
}
|
|
1557
1694
|
}
|
|
1558
1695
|
|
|
@@ -2182,23 +2319,36 @@ const machineOf = <S>(self: Batch<S>, id: number): Machine.Machine<Frame.Frame<n
|
|
|
2182
2319
|
/**
|
|
2183
2320
|
* Runs `self` on the Frame loop while any member moves, from the next tick: each tick steps every
|
|
2184
2321
|
* moving member and writes it. It succeeds once nothing moves. While one runs, another does nothing,
|
|
2185
|
-
* so a binding calls it after each change.
|
|
2322
|
+
* so a binding calls it after each change. A member's failure is reported on the services it runs with,
|
|
2323
|
+
* the Environment's Logger and ErrorReporters, and the run goes on.
|
|
2186
2324
|
*
|
|
2187
2325
|
* @example
|
|
2188
2326
|
* Batch.retarget(grid, slots, targetOf)
|
|
2189
2327
|
* runtime.runFork(Batch.run(grid))
|
|
2190
2328
|
*/
|
|
2329
|
+
/** A Batch run's options (#1026): on the frame timeline while members take their Appear animations over, or not. */
|
|
2330
|
+
const TAKING_OVER: Machine.RunOptions = { onFrameTimeline: true }
|
|
2331
|
+
const ON_ITS_OWN: Machine.RunOptions = {}
|
|
2332
|
+
|
|
2191
2333
|
// One run, not a fiber per member (ADR-0069, decision 10). Its span is `wardic.batch`.
|
|
2192
|
-
export const run
|
|
2193
|
-
Effect.
|
|
2334
|
+
export const run =<S>(self: Batch<S>): Effect.Effect<void, never, FrameLoop.FrameLoop> =>
|
|
2335
|
+
Effect.contextWith((services: Context.Context<never>) => {
|
|
2194
2336
|
const state = stateOf(self)
|
|
2195
2337
|
if (state.running !== 0) return Effect.void
|
|
2338
|
+
// Its failures are reported on what it runs on, the Environment's Logger and ErrorReporters, kept
|
|
2339
|
+
// for a draw or a play between runs; a second run while one runs swaps nothing (#977).
|
|
2340
|
+
state.services = services
|
|
2196
2341
|
if (state.plainCount + state.ruledCount === 0) return Effect.void
|
|
2197
2342
|
const id = state.runs + 1
|
|
2198
2343
|
state.runs = id
|
|
2199
2344
|
state.running = id
|
|
2345
|
+
// A run that starts with members taking their Appear animations over keeps the frame timeline's time,
|
|
2346
|
+
// where those animations' `currentTime` is (#1026); one that doesn't takes no long task's time from
|
|
2347
|
+
// before it was on the page.
|
|
2348
|
+
let options = ON_ITS_OWN
|
|
2349
|
+
if (state.startList.length > 0) options = TAKING_OVER
|
|
2200
2350
|
return Effect.ensuring(
|
|
2201
|
-
Effect.asVoid(Machine.run(machineOf(self, id), ignore)),
|
|
2351
|
+
Effect.asVoid(Machine.run(machineOf(self, id), ignore, options)),
|
|
2202
2352
|
Effect.sync(() => {
|
|
2203
2353
|
if (state.running === id) state.running = 0
|
|
2204
2354
|
}),
|
package/src/Clock.ts
CHANGED
|
@@ -95,6 +95,26 @@ export class Clock extends Context.Service<Clock, {
|
|
|
95
95
|
// @16c6122).
|
|
96
96
|
export const NOMINAL_DT = 1 / 60
|
|
97
97
|
|
|
98
|
+
/**
|
|
99
|
+
* How an Environment's Refresh frames run late ({@link LateFrames}): by their timestamps alone, or, once a
|
|
100
|
+
* frame's callback ran more than `ranAfter` ms after its timestamp, late, a long task holding it.
|
|
101
|
+
*/
|
|
102
|
+
export type LateFrameTiming = "timestamp" | { readonly ranAfter: number }
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Whether the Frame loop tells a late Refresh frame (#1026): not by default; for an Environment whose
|
|
106
|
+
* frame timestamps are on its Clock's `now()`'s timebase, as the DOM's are, a frame that ran more than
|
|
107
|
+
* `ranAfter` ms after its timestamp. A long task delays a frame, whose timestamp is the time it was due,
|
|
108
|
+
* from before the task, so the next frame's dt holds the task's time. A run made in that task wasn't on
|
|
109
|
+
* the page before its first frame ran, and the loop leaves that time out of its first steps. The Clock's
|
|
110
|
+
* time stays the frames' timestamps, what every other run and reading counts.
|
|
111
|
+
*/
|
|
112
|
+
// The DOM provides `{ ranAfter: 40 }` to its Frame loop (`DomLive`); `@wardic/object`'s pumped frames,
|
|
113
|
+
// whose times are its host's, keep the default.
|
|
114
|
+
export const LateFrames: Context.Reference<LateFrameTiming> = /*#__PURE__*/ Context.Reference<LateFrameTiming>("@wardic/core/Clock/LateFrames", {
|
|
115
|
+
defaultValue: () => "timestamp",
|
|
116
|
+
})
|
|
117
|
+
|
|
98
118
|
// @wardic/core compiles against ES2022 alone (no DOM lib, no Node types), which does
|
|
99
119
|
// not declare `performance` or `queueMicrotask`. They are host globals in every environment
|
|
100
120
|
// Wardic targets (browsers, Node, React Native), so they are declared here, in module scope only.
|
package/src/DragRecognizer.ts
CHANGED
|
@@ -409,12 +409,17 @@ export interface DragOptions {
|
|
|
409
409
|
readonly threshold?: ((down: InputSource.PointerLikeEvent) => Option.Option<number>) | undefined
|
|
410
410
|
/**
|
|
411
411
|
* Where each pointer point is for the gesture, as Motion's `transformPagePoint`: read at each down, and
|
|
412
|
-
* applied to
|
|
413
|
-
*
|
|
414
|
-
*
|
|
415
|
-
*
|
|
412
|
+
* applied to the points the gesture is made of, its down's, each pressed move's and its release's. A
|
|
413
|
+
* cancel, a move with no button pressed, an enter and a leave aren't mapped. None, or no function given,
|
|
414
|
+
* leaves the points as they are. It's handed the point on the screen and gives one; the scroll a hold
|
|
415
|
+
* counts in is added back after. A caller gives back the same `Some` while its mapping is the same, so
|
|
416
|
+
* a down allocates nothing.
|
|
417
|
+
*
|
|
418
|
+
* A mapping that throws is reported through `onDefect`, once a run of throws, and the gesture goes on
|
|
419
|
+
* without that point: a move is left out; a release ends the gesture at its last point, with its moves'
|
|
420
|
+
* velocity, as a cancel does; a down starts nothing, and ends a gesture its pointer had left open.
|
|
416
421
|
*/
|
|
417
|
-
// #443; an `Option` (#618, A1).
|
|
422
|
+
// #443; an `Option` (#618, A1). #1000 (ADR-0074): the points mapped, and a throw's.
|
|
418
423
|
readonly mapPoint?: LazyArg<Option.Option<PointMap>> | undefined
|
|
419
424
|
}
|
|
420
425
|
|
|
@@ -425,20 +430,30 @@ export type PointMap = (point: Point.Point) => Point.Point
|
|
|
425
430
|
/** `watchPan`'s options. */
|
|
426
431
|
// #443.
|
|
427
432
|
export interface PanOptions {
|
|
428
|
-
/** Where each pointer point is for the gesture, as `DragOptions`' `mapPoint
|
|
433
|
+
/** Where each pointer point is for the gesture, as `DragOptions`' `mapPoint`: the same points, and a throw the same way. */
|
|
429
434
|
readonly mapPoint?: LazyArg<Option.Option<PointMap>> | undefined
|
|
430
435
|
}
|
|
431
436
|
|
|
432
437
|
/**
|
|
433
|
-
*
|
|
434
|
-
*
|
|
435
|
-
*
|
|
438
|
+
* Whether a drag's fold reads `event`'s point: a down's, a pressed move's and a release's. A cancel ends at
|
|
439
|
+
* the last move's point and an unpressed move (a lost release) at the last pressed one, and an enter or
|
|
440
|
+
* a leave moves nothing.
|
|
441
|
+
*/
|
|
442
|
+
// #1000 (ADR-0074): mapped, a cancel at (0, 0), where Chromium's lands, or any hover move could throw.
|
|
443
|
+
const readsPoint = (event: InputSource.PointerLikeEvent): boolean =>
|
|
444
|
+
Bool.or(Bool.or(event.type === "down", event.type === "up"), Bool.and(event.type === "move", event.pressed))
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* A gesture's point mapping (#443): read at each down, `event` mapped while it's set, when its fold reads
|
|
448
|
+
* its point ({@link readsPoint}). The point mapped is the one on the screen (`x - scroll.x`), the scroll
|
|
449
|
+
* the hold counts in added back after. Allocates only for a mapped gesture.
|
|
436
450
|
*/
|
|
437
451
|
const mappedEvents = (mapPoint: DragOptions["mapPoint"]): ((event: InputSource.PointerLikeEvent) => InputSource.PointerLikeEvent) => {
|
|
438
452
|
if (Predicate.isUndefined(mapPoint)) return identity
|
|
439
453
|
const current = MutableRef.make<Option.Option<PointMap>>(Option.none())
|
|
440
454
|
return (event) => {
|
|
441
455
|
if (event.type === "down") MutableRef.set(current, mapPoint())
|
|
456
|
+
if (Bool.not(readsPoint(event))) return event
|
|
442
457
|
const mapping = MutableRef.get(current)
|
|
443
458
|
if (Option.isNone(mapping)) return event
|
|
444
459
|
const { scroll } = event
|
|
@@ -447,6 +462,54 @@ const mappedEvents = (mapPoint: DragOptions["mapPoint"]): ((event: InputSource.P
|
|
|
447
462
|
}
|
|
448
463
|
}
|
|
449
464
|
|
|
465
|
+
/**
|
|
466
|
+
* The event folded in place of one whose point its mapping can't give, an event whose point isn't read:
|
|
467
|
+
* a release's a cancel, which ends the gesture at its last point with its moves' velocity; a down's an
|
|
468
|
+
* unpressed move, a lost release, which ends a gesture of its pointer's still open, at its last point
|
|
469
|
+
* with no velocity, and starts none. None for a move, left out.
|
|
470
|
+
*/
|
|
471
|
+
// #1000 (ADR-0074): a release left out kept its gesture going, active and claimed, until the next press;
|
|
472
|
+
// a down left out kept one a lost release had left open, for good while the mapping threw at each down.
|
|
473
|
+
const standInFor: (event: InputSource.PointerLikeEvent) => Option.Option<InputSource.PointerLikeEvent> = /*#__PURE__*/ Match.type<InputSource.PointerLikeEvent>().pipe(
|
|
474
|
+
Match.when({ type: "up" }, (up) => Option.some<InputSource.PointerLikeEvent>({ ...up, type: "cancel" })),
|
|
475
|
+
Match.when({ type: "down" }, (down) => Option.some<InputSource.PointerLikeEvent>({ ...down, type: "move", pressed: false })),
|
|
476
|
+
Match.orElse(() => Option.none()),
|
|
477
|
+
)
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* A watch's handler over `step`: each event's point mapped first, its state kept in `state` and its
|
|
481
|
+
* samples told to `tell`. An event whose mapping throws is folded as its stand-in ({@link standInFor}),
|
|
482
|
+
* and the throw goes on to the watch's guard, which reports it, once its samples are told.
|
|
483
|
+
*/
|
|
484
|
+
// #443; #1000: the throw is rethrown so the guard stays the one place a run of throws is reported, once.
|
|
485
|
+
// A throw from `tell` as the stand-in's samples are told reaches the guard in the mapping's place: still
|
|
486
|
+
// one report for the run.
|
|
487
|
+
const mappedHandler = <S>(
|
|
488
|
+
mapPoint: DragOptions["mapPoint"],
|
|
489
|
+
step: (state: DragState, event: InputSource.PointerLikeEvent) => readonly [DragState, ReadonlyArray<S>],
|
|
490
|
+
state: MutableRef.MutableRef<DragState>,
|
|
491
|
+
tell: (sample: S) => void,
|
|
492
|
+
): ((event: InputSource.PointerLikeEvent) => boolean) => {
|
|
493
|
+
const mapped = mappedEvents(mapPoint)
|
|
494
|
+
const fold = (event: InputSource.PointerLikeEvent): void => {
|
|
495
|
+
const [next, samples] = step(MutableRef.get(state), event)
|
|
496
|
+
MutableRef.set(state, next)
|
|
497
|
+
Arr.forEach(samples, tell)
|
|
498
|
+
}
|
|
499
|
+
return (event) => {
|
|
500
|
+
let mappedEvent: InputSource.PointerLikeEvent
|
|
501
|
+
try {
|
|
502
|
+
mappedEvent = mapped(event)
|
|
503
|
+
} catch (error) {
|
|
504
|
+
const standIn = standInFor(event)
|
|
505
|
+
if (Option.isSome(standIn)) fold(standIn.value)
|
|
506
|
+
throw error
|
|
507
|
+
}
|
|
508
|
+
fold(mappedEvent)
|
|
509
|
+
return true
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
450
513
|
/** A drag's watch, as one with no drag controls gives it back: its Scope ends it, and nothing else does. */
|
|
451
514
|
// #618 (F3): a plain watch's type has no `stop` or `cancel`, which did nothing on it.
|
|
452
515
|
export interface WatchedDrag {}
|
|
@@ -591,10 +654,13 @@ export const watchDragAmong: (
|
|
|
591
654
|
}
|
|
592
655
|
const own: PressedMember = { scope: Scope.forkUnsafe(scope, "sequential"), pointerId: told.pointerId, started: false }
|
|
593
656
|
pressed.set(member, own)
|
|
657
|
+
// #979 group I, row 28 (ADR-0074, group A's *Order first*): the watch ended before the app hears the
|
|
658
|
+
// end, so a handler that throws at it can't leave the member pressed, its next press starting nothing.
|
|
659
|
+
// The end closes the watch after this dispatch, so the handler still hears this sample.
|
|
594
660
|
const on = (sample: Drag.Sample): void => {
|
|
595
661
|
if (sample.phase === "start") own.started = true
|
|
596
|
-
handlers.on(member, sample)
|
|
597
662
|
if (sample.phase === "end") end(member, own)
|
|
663
|
+
handlers.on(member, sample)
|
|
598
664
|
}
|
|
599
665
|
run(watchDrag(member, { ...options, listen: false, adoptable: true }, { on, onDefect: handlers.onDefect }).pipe(Scope.provide(own.scope)))
|
|
600
666
|
hand(member, own, told)
|
|
@@ -670,7 +736,6 @@ export const watchDrag: {
|
|
|
670
736
|
handlers: InputFeed.Handlers<Drag.Sample>,
|
|
671
737
|
): Effect.Effect<AdoptableDrag, never, Scope.Scope | InputSource.InputSource> => {
|
|
672
738
|
const attributes = { threshold: THRESHOLD, velocityWindowMs: VELOCITY_WINDOW_MS }
|
|
673
|
-
const mapped = mappedEvents(mapPoint)
|
|
674
739
|
const axisAt = axisAtOf(axis)
|
|
675
740
|
const fold = dragFoldOf(lock, listen, threshold)
|
|
676
741
|
const on = handlers.on
|
|
@@ -738,12 +803,7 @@ export const watchDrag: {
|
|
|
738
803
|
"wardic.drag",
|
|
739
804
|
attributes,
|
|
740
805
|
feed,
|
|
741
|
-
() => (
|
|
742
|
-
const [next, samples] = fold(MutableRef.get(state), mapped(event))
|
|
743
|
-
MutableRef.set(state, next)
|
|
744
|
-
Arr.forEach(samples, admit)
|
|
745
|
-
return true
|
|
746
|
-
},
|
|
806
|
+
() => mappedHandler(mapPoint, fold, state, admit),
|
|
747
807
|
handlers,
|
|
748
808
|
)
|
|
749
809
|
// Its ends from outside its pointer (#431) only for a target given Drag controls (#539): no other
|
|
@@ -847,19 +907,11 @@ export const watchPan: (target: unknown, handlers: InputFeed.Handlers<PanSample>
|
|
|
847
907
|
"wardic.pan",
|
|
848
908
|
PAN_ATTRIBUTES,
|
|
849
909
|
input.pointer(target),
|
|
850
|
-
() =>
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
MutableRef.set(state, next)
|
|
856
|
-
Arr.forEach(samples, (sample) => {
|
|
857
|
-
counted(sample)
|
|
858
|
-
handlers.on(sample)
|
|
859
|
-
})
|
|
860
|
-
return true
|
|
861
|
-
}
|
|
862
|
-
},
|
|
910
|
+
() =>
|
|
911
|
+
mappedHandler(options.mapPoint, panStep, MutableRef.make(initState), (sample) => {
|
|
912
|
+
counted(sample)
|
|
913
|
+
handlers.on(sample)
|
|
914
|
+
}),
|
|
863
915
|
handlers,
|
|
864
916
|
)
|
|
865
917
|
})
|
package/src/Frame.ts
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
*/
|
|
15
15
|
// CONTEXT.md's Frame; docs/adr/0001-core-stream-contract.md. A plain shape, so it has no prototype
|
|
16
16
|
// (ADR-0028, decision 1): a step allocates one every tick, or rewrites one per run in place, as
|
|
17
|
-
// `springValues`'
|
|
17
|
+
// `springValues`', a tween's and the blends' do (ADR-0030, decision 11 and *Amendment (#895)*). Only the physics Primitives (`spring`, `decay`, `chase`)
|
|
18
18
|
// emit `velocity`, the field `isPhysics` narrows on.
|
|
19
19
|
import * as Predicate from "effect/Predicate"
|
|
20
20
|
|
package/src/InputFeed.ts
CHANGED
|
@@ -31,7 +31,8 @@
|
|
|
31
31
|
// authors; nothing here names a DOM type.
|
|
32
32
|
import * as Arr from "effect/Array"
|
|
33
33
|
import * as Bool from "effect/Boolean"
|
|
34
|
-
import * as Cause from "effect/Cause"
|
|
34
|
+
import type * as Cause from "effect/Cause"
|
|
35
|
+
import type * as Context from "effect/Context"
|
|
35
36
|
import * as Effect from "effect/Effect"
|
|
36
37
|
import { constVoid } from "effect/Function"
|
|
37
38
|
import * as MutableRef from "effect/MutableRef"
|
|
@@ -41,6 +42,7 @@ import * as Queue from "effect/Queue"
|
|
|
41
42
|
import type * as Scope from "effect/Scope"
|
|
42
43
|
import * as Stream from "effect/Stream"
|
|
43
44
|
import * as UndefinedOr from "effect/UndefinedOr"
|
|
45
|
+
import { guarded, switchedOn } from "./internal/guarded.ts"
|
|
44
46
|
|
|
45
47
|
/**
|
|
46
48
|
* A source of events: called with `emit` and `end`, it calls `emit` with each event from then on, and
|
|
@@ -140,10 +142,13 @@ export const byTarget = <A>(lookup: (target: unknown) => InputFeed<A>): ((target
|
|
|
140
142
|
}
|
|
141
143
|
|
|
142
144
|
/**
|
|
143
|
-
* Where a watch hands
|
|
144
|
-
*
|
|
145
|
+
* Where a watch hands its handler's run of throws, at its first, so a binding can report it its own way:
|
|
146
|
+
* a run lasts from a throw to the next call that returns, and the watch goes on with the next event.
|
|
147
|
+
* With none, the run is reported then, on the context the watch started in, and the watch goes on.
|
|
145
148
|
*/
|
|
146
|
-
// #318, ADR-0055.
|
|
149
|
+
// #318, ADR-0055. With none, core reports the throw itself (#979, row 27; ADR-0030, *Amendment (#979,
|
|
150
|
+
// groups D and G)*): where no binding's fiber is there to see it. Once a run either way (#979 group I,
|
|
151
|
+
// row 26; ADR-0074 decision 3).
|
|
147
152
|
export type OnDefect = (cause: Cause.Cause<never>) => void
|
|
148
153
|
|
|
149
154
|
/** A watch's handlers. */
|
|
@@ -151,7 +156,7 @@ export type OnDefect = (cause: Cause.Cause<never>) => void
|
|
|
151
156
|
export interface Handlers<A> {
|
|
152
157
|
/** Each event or value, inside the event's dispatch. */
|
|
153
158
|
readonly on: (value: A) => void
|
|
154
|
-
/** A
|
|
159
|
+
/** A handler's run of throws, at its first. Without it, the run is reported then, and the watch goes on. */
|
|
155
160
|
readonly onDefect?: OnDefect | undefined
|
|
156
161
|
/** The feed ran out, as a test's script does. */
|
|
157
162
|
readonly onEnd?: (() => void) | undefined
|
|
@@ -162,19 +167,6 @@ export interface Handlers<A> {
|
|
|
162
167
|
readonly onStop?: (() => void) | undefined
|
|
163
168
|
}
|
|
164
169
|
|
|
165
|
-
/** `handle`, a throw from it handed to `onDefect` when there is one. */
|
|
166
|
-
const guarded = <A>(handle: (event: A) => void, onDefect: OnDefect | undefined): ((event: A) => void) =>
|
|
167
|
-
UndefinedOr.match(onDefect, {
|
|
168
|
-
onUndefined: () => handle,
|
|
169
|
-
onDefined: (defect) => (event: A): void => {
|
|
170
|
-
try {
|
|
171
|
-
handle(event)
|
|
172
|
-
} catch (error) {
|
|
173
|
-
defect(Cause.die(error))
|
|
174
|
-
}
|
|
175
|
-
},
|
|
176
|
-
})
|
|
177
|
-
|
|
178
170
|
/** A subscription its owner opens and closes: `switched`'s. */
|
|
179
171
|
// #460.
|
|
180
172
|
export interface Switch {
|
|
@@ -186,38 +178,39 @@ export interface Switch {
|
|
|
186
178
|
|
|
187
179
|
/**
|
|
188
180
|
* A subscription to `feed` its owner opens and closes, each event handed to `handle` inside its emit, a
|
|
189
|
-
*
|
|
181
|
+
* run of throws to `onDefect` at its first. With none, the run is reported then on Effect's default runtime, as
|
|
182
|
+
* a subscription has no context of its own, and it goes on. For a feed a watch needs only some of the time: a keyboard
|
|
190
183
|
* press holds its target's keys only while focus is within it, so an element at rest holds none. The feed
|
|
191
184
|
* running out ends nothing; its owner closes it when it's done.
|
|
192
185
|
*/
|
|
193
186
|
// #460: a **Keyboard press**.
|
|
194
|
-
export const switched = <A>(feed: InputFeed<A>, handle: (event: A) => void, onDefect?: OnDefect): Switch =>
|
|
195
|
-
const on = guarded(handle, onDefect)
|
|
196
|
-
let stop: (() => void) | undefined
|
|
197
|
-
return {
|
|
198
|
-
open: () => {
|
|
199
|
-
if (Predicate.isUndefined(stop)) stop = feed(on, constVoid)
|
|
200
|
-
},
|
|
201
|
-
close: () => {
|
|
202
|
-
if (Predicate.isUndefined(stop)) return
|
|
203
|
-
const running = stop
|
|
204
|
-
stop = undefined
|
|
205
|
-
running()
|
|
206
|
-
},
|
|
207
|
-
}
|
|
208
|
-
}
|
|
187
|
+
export const switched = <A>(feed: InputFeed<A>, handle: (event: A) => void, onDefect?: OnDefect): Switch => switchedOn(feed, handle, onDefect, undefined)
|
|
209
188
|
|
|
210
189
|
/**
|
|
211
190
|
* Watches `feed` while the Scope is open, with a handler that can stop: `make` makes this subscription's
|
|
212
191
|
* handler, which hears each event inside its emit and returns whether to go on. `false` stops it, even
|
|
213
|
-
* from inside the feed's start. A
|
|
214
|
-
* the
|
|
192
|
+
* from inside the feed's start. A run of throws from it goes to `handlers.onDefect` at its first, else it's
|
|
193
|
+
* reported then on the context the watch started in, and the watch goes on. `handlers.onEnd` is told if the
|
|
194
|
+
* feed runs out, and closing the Scope stops the feed.
|
|
215
195
|
*/
|
|
216
196
|
// #318, #379: no fiber and no Stream. A recognizer's `once` returns `false`.
|
|
217
197
|
export const watchWith = <A>(
|
|
218
198
|
feed: InputFeed<A>,
|
|
219
199
|
make: () => (event: A) => boolean,
|
|
220
200
|
handlers: Pick<Handlers<never>, "onDefect" | "onEnd" | "onStop">,
|
|
201
|
+
): Effect.Effect<void, never, Scope.Scope> =>
|
|
202
|
+
// The context a throw with no `onDefect` is reported on (#979, row 27), read only for such a watch.
|
|
203
|
+
UndefinedOr.match(handlers.onDefect, {
|
|
204
|
+
onDefined: () => watching(feed, make, handlers, undefined),
|
|
205
|
+
onUndefined: () => Effect.flatMap(Effect.context<never>(), (context) => watching(feed, make, handlers, context)),
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
/** `watchWith`'s watch, a throw with no `onDefect` reported on `context`. */
|
|
209
|
+
const watching = <A>(
|
|
210
|
+
feed: InputFeed<A>,
|
|
211
|
+
make: () => (event: A) => boolean,
|
|
212
|
+
handlers: Pick<Handlers<never>, "onDefect" | "onEnd" | "onStop">,
|
|
213
|
+
context: Context.Context<never> | undefined,
|
|
221
214
|
): Effect.Effect<void, never, Scope.Scope> =>
|
|
222
215
|
Effect.acquireRelease(
|
|
223
216
|
Effect.sync(() => {
|
|
@@ -231,10 +224,14 @@ export const watchWith = <A>(
|
|
|
231
224
|
if (Predicate.isNotUndefined(handlers.onStop)) handlers.onStop()
|
|
232
225
|
}
|
|
233
226
|
const stop = feed(
|
|
234
|
-
guarded(
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
227
|
+
guarded(
|
|
228
|
+
(event: A) => {
|
|
229
|
+
if (MutableRef.get(done)) return
|
|
230
|
+
if (Bool.not(handle(event))) finish()
|
|
231
|
+
},
|
|
232
|
+
handlers.onDefect,
|
|
233
|
+
context,
|
|
234
|
+
),
|
|
238
235
|
() => {
|
|
239
236
|
if (MutableRef.get(done)) return
|
|
240
237
|
UndefinedOr.map(handlers.onEnd, (onEnd) => onEnd())
|