@wardic/core 1.0.0 → 1.1.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/Batch.d.ts +4 -2
- package/dist/Batch.d.ts.map +1 -1
- package/dist/Batch.js +80 -13
- package/dist/Batch.js.map +1 -1
- package/dist/DefaultTransition.d.ts.map +1 -1
- package/dist/DefaultTransition.js +1 -1
- package/dist/DefaultTransition.js.map +1 -1
- package/dist/LiveValue.d.ts +61 -0
- package/dist/LiveValue.d.ts.map +1 -1
- package/dist/LiveValue.js +79 -5
- package/dist/LiveValue.js.map +1 -1
- package/dist/Machine.d.ts +10 -1
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +18 -1
- package/dist/Machine.js.map +1 -1
- package/dist/Renderer.js +2 -2
- package/dist/Renderer.js.map +1 -1
- package/dist/Reorder.d.ts +4 -2
- package/dist/Reorder.d.ts.map +1 -1
- package/dist/Reorder.js +32 -9
- package/dist/Reorder.js.map +1 -1
- package/dist/Spans.d.ts +41 -0
- package/dist/Spans.d.ts.map +1 -0
- package/dist/Spans.js +39 -0
- package/dist/Spans.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/frameLoop.d.ts +1 -1
- package/dist/internal/frameLoop.d.ts.map +1 -1
- package/dist/internal/frameLoop.js +42 -19
- package/dist/internal/frameLoop.js.map +1 -1
- package/dist/internal/options.d.ts.map +1 -1
- package/dist/internal/options.js +2 -2
- package/dist/internal/options.js.map +1 -1
- package/dist/internal/tracing.d.ts +34 -14
- package/dist/internal/tracing.d.ts.map +1 -1
- package/dist/internal/tracing.js +56 -24
- package/dist/internal/tracing.js.map +1 -1
- package/package.json +1 -1
- package/src/Batch.ts +68 -12
- package/src/DefaultTransition.ts +1 -1
- package/src/LiveValue.ts +129 -5
- package/src/Machine.ts +22 -1
- package/src/Renderer.ts +2 -2
- package/src/Reorder.ts +44 -9
- package/src/Spans.ts +50 -0
- package/src/index.ts +1 -0
- package/src/internal/frameLoop.ts +44 -20
- package/src/internal/options.ts +2 -2
- package/src/internal/tracing.ts +82 -28
|
@@ -1,22 +1,42 @@
|
|
|
1
|
+
import * as Context from "effect/Context";
|
|
1
2
|
import * as Effect from "effect/Effect";
|
|
2
3
|
import type * as Fiber from "effect/Fiber";
|
|
3
4
|
import type * as Scope from "effect/Scope";
|
|
4
5
|
import * as Stream from "effect/Stream";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
import * as Tracer from "effect/Tracer";
|
|
7
|
+
import type * as Spans from "../Spans.ts";
|
|
8
|
+
/** What opens Wardic's spans, read from the fiber where each would open. */
|
|
9
|
+
export interface Shape {
|
|
10
|
+
/** `self` under the span `name`, when `fiber` is traced. */
|
|
11
|
+
readonly traced: <A, E, R>(fiber: Fiber.Fiber<unknown, unknown>, self: Effect.Effect<A, E, R>, name: string, options: Spans.Options) => Effect.Effect<A, E, R>;
|
|
12
|
+
/** `self` under the span `name` for its Scope's life, when `fiber` is traced. */
|
|
13
|
+
readonly tracedScoped: <A, E, R>(fiber: Fiber.Fiber<unknown, unknown>, self: Effect.Effect<A, E, R>, name: string, options: Spans.Options) => Effect.Effect<A, E, R | Scope.Scope>;
|
|
14
|
+
/** `self` under the span `name`, when `fiber`, the one running it, is traced; `self` itself, the same Stream, otherwise. */
|
|
15
|
+
readonly tracedStream: <A, E, R>(fiber: Fiber.Fiber<unknown, unknown>, self: Stream.Stream<A, E, R>, name: string, options: Spans.Options) => Stream.Stream<A, E, R>;
|
|
16
|
+
/**
|
|
17
|
+
* `body` under the span `name`, the `ParentSpan` of what runs inside it, with no stack frame
|
|
18
|
+
* (ADR-0040, decision 3), when `fiber` is traced: what a Frame loop run opens. `body` is given the
|
|
19
|
+
* span, or `undefined` with none.
|
|
20
|
+
*/
|
|
21
|
+
readonly run: <A, E, R>(fiber: Fiber.Fiber<unknown, unknown>, name: string, attributes: Readonly<Record<string, unknown>>, body: (span: Tracer.Span | undefined) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
|
|
9
22
|
}
|
|
10
|
-
/**
|
|
11
|
-
export declare const
|
|
12
|
-
/**
|
|
13
|
-
export declare const
|
|
14
|
-
/**
|
|
15
|
-
export declare const
|
|
23
|
+
/** Opens no span: what's read without `Spans.layer`. */
|
|
24
|
+
export declare const none: Shape;
|
|
25
|
+
/** Opens each span where its fiber is traced: what `Spans.layer` gives. */
|
|
26
|
+
export declare const opening: Shape;
|
|
27
|
+
/** What opens Wardic's spans: {@link none} unless the app gives `Spans.layer`, as `FrameLoop`'s metrics are given (#518). */
|
|
28
|
+
export declare const SpansGiven: Context.Reference<Shape>;
|
|
29
|
+
/** Whether a tracer reads the running fiber's spans while the app gives none: what development warns of. */
|
|
30
|
+
export declare const missing: Effect.Effect<boolean>;
|
|
31
|
+
/** `self` under the span `name` when its fiber is traced and the app gives spans; as it is otherwise. */
|
|
32
|
+
export declare const traced: <A, E, R>(self: Effect.Effect<A, E, R>, name: string, options?: Spans.Options) => Effect.Effect<A, E, R>;
|
|
33
|
+
/** `self` under the span `name` for its Scope's life when its fiber is traced and the app gives spans; as it is otherwise. */
|
|
34
|
+
export declare const tracedScoped: <A, E, R>(self: Effect.Effect<A, E, R>, name: string, options?: Spans.Options) => Effect.Effect<A, E, R | Scope.Scope>;
|
|
16
35
|
/**
|
|
17
|
-
* `self` under the span `name` when the fiber running it is traced; as it is
|
|
18
|
-
* when the stream is run, and the pull handed on is `self`'s own: a
|
|
19
|
-
* every pull, per element per frame for a Stream consumer (+4–6% on
|
|
36
|
+
* `self` under the span `name` when the fiber running it is traced and the app gives spans; as it is
|
|
37
|
+
* otherwise. Decided once, when the stream is run, and the pull handed on is `self`'s own: a
|
|
38
|
+
* `Stream.unwrap` here suspended every pull, per element per frame for a Stream consumer (+4–6% on
|
|
39
|
+
* Bun's `ticksOnly`). `Shape.tracedStream` hands `self` back untraced, which is how it's told.
|
|
20
40
|
*/
|
|
21
|
-
export declare const tracedStream: <A, E, R>(self: Stream.Stream<A, E, R>, name: string, options?:
|
|
41
|
+
export declare const tracedStream: <A, E, R>(self: Stream.Stream<A, E, R>, name: string, options?: Spans.Options) => Stream.Stream<A, E, R>;
|
|
22
42
|
//# sourceMappingURL=tracing.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tracing.d.ts","sourceRoot":"","sources":["../../src/internal/tracing.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAA;AAE1C,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAA;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"tracing.d.ts","sourceRoot":"","sources":["../../src/internal/tracing.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAA;AAE1C,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAA;AAC1C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,KAAK,MAAM,aAAa,CAAA;AAEzC,4EAA4E;AAC5E,MAAM,WAAW,KAAK;IACpB,4DAA4D;IAC5D,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC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
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
2
|
+
* Core's spans (#746, ADR-0067 *Amendment (#746)*, decision 8): opened through what the app gives,
|
|
3
|
+
* `Spans.layer`, read from the fiber where each would open. With nothing given, `none` opens none, and
|
|
4
|
+
* no module an app imports names Effect's `Tracer`. Given, each opens only where something reads it
|
|
5
|
+
* (#460, ADR-0040 *Amendment (#460)*): a tracer installed other than Effect's default, tracing on. No
|
|
6
|
+
* span captures a call-site stack (ADR-0040, decision 2).
|
|
7
7
|
*/
|
|
8
8
|
import * as Channel from "effect/Channel";
|
|
9
|
+
import * as Context from "effect/Context";
|
|
9
10
|
import * as Effect from "effect/Effect";
|
|
10
11
|
import * as References from "effect/References";
|
|
11
12
|
import * as Stream from "effect/Stream";
|
|
12
13
|
import * as Tracer from "effect/Tracer";
|
|
13
|
-
/**
|
|
14
|
-
export const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
});
|
|
21
|
-
/** `self` under the span `name` for its Scope's life when its fiber is traced; as it is otherwise. */
|
|
22
|
-
export const tracedScoped = (self, name, options = {}) => Effect.withFiber((fiber) => {
|
|
23
|
-
if (!isTraced(fiber))
|
|
24
|
-
return self;
|
|
25
|
-
return Effect.withSpanScoped(self, name, { ...options, captureStackTrace: false });
|
|
26
|
-
});
|
|
14
|
+
/** Opens no span: what's read without `Spans.layer`. */
|
|
15
|
+
export const none = {
|
|
16
|
+
traced: (_, self) => self,
|
|
17
|
+
tracedScoped: (_, self) => self,
|
|
18
|
+
tracedStream: (_, self) => self,
|
|
19
|
+
run: (_, __, ___, body) => body(undefined),
|
|
20
|
+
};
|
|
27
21
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
22
|
+
* Whether a fiber's spans reach anything: a tracer installed, not Effect's default `nativeTracer` (the
|
|
23
|
+
* comparison Effect's `Tracer` documents for this), and tracing on. With Effect's default, a span is
|
|
24
|
+
* recorded that nothing reads, and its `ParentSpan` gives the fiber a new context root.
|
|
25
|
+
*/
|
|
26
|
+
const isTraced = (fiber) => fiber.getRef(Tracer.Tracer) !== Tracer.nativeTracer && fiber.getRef(References.TracerEnabled);
|
|
27
|
+
/** Opens each span where its fiber is traced: what `Spans.layer` gives. */
|
|
28
|
+
export const opening = {
|
|
29
|
+
traced: (fiber, self, name, options) => {
|
|
30
|
+
if (!isTraced(fiber))
|
|
31
|
+
return self;
|
|
32
|
+
return Effect.withSpan(self, name, { ...options, captureStackTrace: false });
|
|
33
|
+
},
|
|
34
|
+
tracedScoped: (fiber, self, name, options) => {
|
|
35
|
+
if (!isTraced(fiber))
|
|
36
|
+
return self;
|
|
37
|
+
return Effect.withSpanScoped(self, name, { ...options, captureStackTrace: false });
|
|
38
|
+
},
|
|
39
|
+
tracedStream: (fiber, self, name, options) => {
|
|
40
|
+
if (!isTraced(fiber))
|
|
41
|
+
return self;
|
|
42
|
+
return Stream.withSpan(self, name, { ...options, captureStackTrace: false });
|
|
43
|
+
},
|
|
44
|
+
run: (fiber, name, attributes, body) => {
|
|
45
|
+
if (!isTraced(fiber))
|
|
46
|
+
return body(undefined);
|
|
47
|
+
return Effect.useSpan(name, { attributes }, (span) => Effect.provideService(body(span), Tracer.ParentSpan, span));
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
/** What opens Wardic's spans: {@link none} unless the app gives `Spans.layer`, as `FrameLoop`'s metrics are given (#518). */
|
|
51
|
+
export const SpansGiven = /*#__PURE__*/ Context.Reference("@wardic/core/Spans", { defaultValue: () => none });
|
|
52
|
+
/** Whether a tracer reads the running fiber's spans while the app gives none: what development warns of. */
|
|
53
|
+
export const missing = /*#__PURE__*/ Effect.withFiber((fiber) => Effect.succeed(isTraced(fiber) && fiber.getRef(SpansGiven) === none));
|
|
54
|
+
/** `self` under the span `name` when its fiber is traced and the app gives spans; as it is otherwise. */
|
|
55
|
+
export const traced = (self, name, options = {}) => Effect.withFiber((fiber) => fiber.getRef(SpansGiven).traced(fiber, self, name, options));
|
|
56
|
+
/** `self` under the span `name` for its Scope's life when its fiber is traced and the app gives spans; as it is otherwise. */
|
|
57
|
+
export const tracedScoped = (self, name, options = {}) => Effect.withFiber((fiber) => fiber.getRef(SpansGiven).tracedScoped(fiber, self, name, options));
|
|
58
|
+
/**
|
|
59
|
+
* `self` under the span `name` when the fiber running it is traced and the app gives spans; as it is
|
|
60
|
+
* otherwise. Decided once, when the stream is run, and the pull handed on is `self`'s own: a
|
|
61
|
+
* `Stream.unwrap` here suspended every pull, per element per frame for a Stream consumer (+4–6% on
|
|
62
|
+
* Bun's `ticksOnly`). `Shape.tracedStream` hands `self` back untraced, which is how it's told.
|
|
31
63
|
*/
|
|
32
64
|
export const tracedStream = (self, name, options = {}) => {
|
|
33
65
|
const channel = Stream.toChannel(self);
|
|
34
66
|
return Stream.fromChannel(Channel.fromTransform((upstream, scope) => Effect.withFiber((fiber) => {
|
|
35
|
-
|
|
67
|
+
const spanned = fiber.getRef(SpansGiven).tracedStream(fiber, self, name, options);
|
|
68
|
+
if (spanned === self)
|
|
36
69
|
return Channel.toTransform(channel)(upstream, scope);
|
|
37
|
-
const spanned = Stream.withSpan(self, name, { ...options, captureStackTrace: false });
|
|
38
70
|
return Channel.toTransform(Stream.toChannel(spanned))(upstream, scope);
|
|
39
71
|
})));
|
|
40
72
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tracing.js","sourceRoot":"","sources":["../../src/internal/tracing.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAA;AAE/C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"tracing.js","sourceRoot":"","sources":["../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,OAAO,CAAC,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAA;QAC1E,OAAO,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAA;IACxE,CAAC,CAAC,CACH,CACF,CAAA;AACH,CAAC,CAAA"}
|
package/package.json
CHANGED
package/src/Batch.ts
CHANGED
|
@@ -173,6 +173,14 @@ const COUNTED = 8
|
|
|
173
173
|
const STARTS = 16
|
|
174
174
|
/** The start pass drew it this step: its loop keeps it, unstepped, and clears the flag. */
|
|
175
175
|
const STARTED = 32
|
|
176
|
+
/**
|
|
177
|
+
* Its values changed outside a step (it entered, took a new Subject, a change started it from a given value,
|
|
178
|
+
* or a play, seek, stop or cancel put it somewhere): its next step writes it, though that step may not move
|
|
179
|
+
* it. A step writes a member it moves, or one due; not one a delay or a paused Playhead holds still. A bit
|
|
180
|
+
* of the flags each step reads anyway: the plain list's check stays one compare, and only a member due takes
|
|
181
|
+
* the slow path.
|
|
182
|
+
*/
|
|
183
|
+
const DUE = 64
|
|
176
184
|
|
|
177
185
|
/** A Batch's state, which only this module's operations write. */
|
|
178
186
|
interface State<S> {
|
|
@@ -517,7 +525,8 @@ export const enter: {
|
|
|
517
525
|
const slot = slotFor(state)
|
|
518
526
|
state.subjects[slot] = subject
|
|
519
527
|
// A start a member that left never took isn't this one's.
|
|
520
|
-
|
|
528
|
+
// Drawn at its first step, at its start, though a delay holds it there.
|
|
529
|
+
state.flags[slot] = (state.flags[slot] & ~(STARTS | STARTED)) | LIVE | DUE
|
|
521
530
|
const base = slot * state.stride
|
|
522
531
|
Arr.forEach(state.keys, (key, k) => {
|
|
523
532
|
const given = start[key]
|
|
@@ -571,6 +580,8 @@ export const replace: {
|
|
|
571
580
|
const state = stateOf(self)
|
|
572
581
|
if ((state.flags[slot] & LIVE) === 0) return
|
|
573
582
|
state.subjects[slot] = subject
|
|
583
|
+
// The new Subject has nothing drawn on it yet.
|
|
584
|
+
state.flags[slot] = state.flags[slot] | DUE
|
|
574
585
|
})
|
|
575
586
|
|
|
576
587
|
/** A slot for a new member: one a `leave` freed, else the next, the arrays doubled when they're full. */
|
|
@@ -669,6 +680,8 @@ export const retarget: {
|
|
|
669
680
|
if ((flag & COUNTED) !== 0) continue
|
|
670
681
|
const base = slot * stride
|
|
671
682
|
let moves = false
|
|
683
|
+
// Started from a value given: drawn there at its next step, though a delay holds it there.
|
|
684
|
+
let jumped = false
|
|
672
685
|
for (let k = 0; k < stride; k++) {
|
|
673
686
|
const at = base + k
|
|
674
687
|
let target = targetOf(slot, k)
|
|
@@ -680,6 +693,7 @@ export const retarget: {
|
|
|
680
693
|
if (!Number.isNaN(jump)) {
|
|
681
694
|
if (Number.isNaN(target)) target = targets[at]
|
|
682
695
|
state.positions[at] = jump
|
|
696
|
+
jumped = true
|
|
683
697
|
state.velocities[at] = 0
|
|
684
698
|
if (Predicate.isNotUndefined(speedOf)) state.velocities[at] = speedOf(slot, k)
|
|
685
699
|
targets[at] = Number.NaN
|
|
@@ -690,6 +704,7 @@ export const retarget: {
|
|
|
690
704
|
}
|
|
691
705
|
if (!moves) continue
|
|
692
706
|
flags[slot] = flag | COUNTED
|
|
707
|
+
if (jumped) flags[slot] = flags[slot] | DUE
|
|
693
708
|
movers[n] = slot
|
|
694
709
|
n++
|
|
695
710
|
}
|
|
@@ -778,8 +793,10 @@ export const isMoving = <S>(self: Batch<S>): boolean => {
|
|
|
778
793
|
}
|
|
779
794
|
|
|
780
795
|
/**
|
|
781
|
-
* Steps every moving member by `dt` seconds and writes each one
|
|
782
|
-
*
|
|
796
|
+
* Steps every moving member by `dt` seconds and writes each one the step moves, or whose values a change
|
|
797
|
+
* outside a step set (an `enter`, a `replace`, a start from a given value, a play, seek, stop or cancel):
|
|
798
|
+
* whether nothing moves now. One a delay or a paused Playhead holds still isn't written. The run on the
|
|
799
|
+
* Frame loop calls it each tick.
|
|
783
800
|
*/
|
|
784
801
|
// Per frame (ADR-0025, ADR-0030 decisions 10 and 11): `dt` clamped once (#78), then the two moving
|
|
785
802
|
// lists. Each steps a key by `springValues`' exact step, or `Machine.tween`'s, its spring's matrix
|
|
@@ -813,6 +830,7 @@ export const draw = <S>(self: Batch<S>): void => {
|
|
|
813
830
|
const { flags, subjects, positions, stride, write } = state
|
|
814
831
|
for (let slot = 0; slot < state.used; slot++) {
|
|
815
832
|
if ((flags[slot] & LIVE) === 0) continue
|
|
833
|
+
flags[slot] = flags[slot] & ~DUE
|
|
816
834
|
write(subjects[slot] as S, positions, slot * stride)
|
|
817
835
|
}
|
|
818
836
|
state.flush()
|
|
@@ -851,8 +869,10 @@ const stepPlain = <S>(state: State<S>, clamped: number): void => {
|
|
|
851
869
|
for (let a = 0; a < count; a++) {
|
|
852
870
|
const slot = plainList[a]
|
|
853
871
|
const flag = flags[slot]
|
|
872
|
+
// Whether to write it: this step moved a key, or a change outside a step left it due.
|
|
873
|
+
let moved = false
|
|
854
874
|
// A member a change gave another transition is the ruled list's now; one that left is dropped here,
|
|
855
|
-
// unwritten. One the start pass drew this step is kept, unstepped (#706).
|
|
875
|
+
// unwritten. One the start pass drew this step is kept, unstepped (#706). One due is stepped and written.
|
|
856
876
|
if (flag !== (LIVE | IN_PLAIN)) {
|
|
857
877
|
if (flag === (LIVE | IN_PLAIN | STARTED)) {
|
|
858
878
|
flags[slot] = LIVE | IN_PLAIN
|
|
@@ -860,8 +880,14 @@ const stepPlain = <S>(state: State<S>, clamped: number): void => {
|
|
|
860
880
|
kept++
|
|
861
881
|
continue
|
|
862
882
|
}
|
|
863
|
-
if (
|
|
864
|
-
|
|
883
|
+
if (flag === (LIVE | IN_PLAIN | DUE)) {
|
|
884
|
+
flags[slot] = LIVE | IN_PLAIN
|
|
885
|
+
moved = true
|
|
886
|
+
}
|
|
887
|
+
if (!moved) {
|
|
888
|
+
if ((flag & IN_PLAIN) !== 0) flags[slot] = flag & ~IN_PLAIN
|
|
889
|
+
continue
|
|
890
|
+
}
|
|
865
891
|
}
|
|
866
892
|
const base = slot * stride
|
|
867
893
|
let still = true
|
|
@@ -873,16 +899,19 @@ const stepPlain = <S>(state: State<S>, clamped: number): void => {
|
|
|
873
899
|
let speed = velocities[at]
|
|
874
900
|
// Only the part of this tick past the delay moves it: all of it, or, the frame its delay ends, a part.
|
|
875
901
|
const simDt = Math.max(0, Math.min(clamped, time - delays[at]))
|
|
902
|
+
// A key moves only in these two branches, so they say so: no compare per key (bench:core's `batch`).
|
|
876
903
|
if (simDt === clamped) {
|
|
877
904
|
const d = position - goal
|
|
878
905
|
position = goal + dd * d + dv * speed
|
|
879
906
|
speed = vd * d + vv * speed
|
|
907
|
+
moved = true
|
|
880
908
|
}
|
|
881
909
|
if (simDt > 0 && simDt < clamped) {
|
|
882
910
|
const part = Spring.matrixFor(spring, simDt)
|
|
883
911
|
const d = position - goal
|
|
884
912
|
position = goal + part.dd * d + part.dv * speed
|
|
885
913
|
speed = part.vd * d + part.vv * speed
|
|
914
|
+
moved = true
|
|
886
915
|
}
|
|
887
916
|
const settled = simDt > 0 && Math.abs(speed) <= restSpeeds[at] && Math.abs(position - goal) <= restDeltas[at]
|
|
888
917
|
if (settled) {
|
|
@@ -894,7 +923,8 @@ const stepPlain = <S>(state: State<S>, clamped: number): void => {
|
|
|
894
923
|
velocities[at] = speed
|
|
895
924
|
elapsed[at] = time
|
|
896
925
|
}
|
|
897
|
-
write
|
|
926
|
+
// One a delay holds still isn't written: an unchanged write is a style write all the same.
|
|
927
|
+
if (moved) write(subjects[slot] as S, positions, base)
|
|
898
928
|
// At rest: still its member's, in neither list.
|
|
899
929
|
if (still) {
|
|
900
930
|
flags[slot] = LIVE
|
|
@@ -975,6 +1005,9 @@ const stepRuled = <S>(state: State<S>, clamped: number): void => {
|
|
|
975
1005
|
}
|
|
976
1006
|
const base = slot * stride
|
|
977
1007
|
let still = true
|
|
1008
|
+
// Whether to write it: this step moved a key, or a change outside a step left it due.
|
|
1009
|
+
let moved = (flag & DUE) !== 0
|
|
1010
|
+
if (moved) flags[slot] = flag & ~DUE
|
|
978
1011
|
for (let k = 0; k < stride; k++) {
|
|
979
1012
|
const at = base + k
|
|
980
1013
|
const rule = rules[at]
|
|
@@ -983,7 +1016,9 @@ const stepRuled = <S>(state: State<S>, clamped: number): void => {
|
|
|
983
1016
|
elapsed[at] = time
|
|
984
1017
|
// A tween, out of line.
|
|
985
1018
|
if (kind === TWEEN) {
|
|
1019
|
+
const was = positions[at]
|
|
986
1020
|
if (!stepTween(state, at, entries[rule].tween, time, clamped)) still = false
|
|
1021
|
+
if (positions[at] !== was) moved = true
|
|
987
1022
|
continue
|
|
988
1023
|
}
|
|
989
1024
|
// A spring, as `springValues`': only the part of this tick past the delay moves it.
|
|
@@ -997,17 +1032,21 @@ const stepRuled = <S>(state: State<S>, clamped: number): void => {
|
|
|
997
1032
|
const d = position - goal
|
|
998
1033
|
position = goal + matrices[mi] * d + matrices[mi + 1] * speed
|
|
999
1034
|
speed = matrices[mi + 2] * d + matrices[mi + 3] * speed
|
|
1035
|
+
moved = true
|
|
1000
1036
|
}
|
|
1001
1037
|
if (simDt > 0 && simDt < clamped) {
|
|
1002
1038
|
const part = Spring.matrixFor(entries[rule].spring, simDt)
|
|
1003
1039
|
const d = position - goal
|
|
1004
1040
|
position = goal + part.dd * d + part.dv * speed
|
|
1005
1041
|
speed = part.vd * d + part.vv * speed
|
|
1042
|
+
moved = true
|
|
1006
1043
|
}
|
|
1007
|
-
// A spring rests by its thresholds; one that ends at its duration, there (#359)
|
|
1044
|
+
// A spring rests by its thresholds; one that ends at its duration, there (#359), with no step if its
|
|
1045
|
+
// duration is 0: a settle that moves it says so, once a key.
|
|
1008
1046
|
let settled = simDt > 0 && Math.abs(speed) <= restSpeeds[at] && Math.abs(position - goal) <= restDeltas[at]
|
|
1009
1047
|
if (kind === TIMED) settled = time - delay >= entries[rule].spring.duration
|
|
1010
1048
|
if (settled) {
|
|
1049
|
+
if (position !== goal) moved = true
|
|
1011
1050
|
position = goal
|
|
1012
1051
|
speed = 0
|
|
1013
1052
|
}
|
|
@@ -1015,7 +1054,7 @@ const stepRuled = <S>(state: State<S>, clamped: number): void => {
|
|
|
1015
1054
|
positions[at] = position
|
|
1016
1055
|
velocities[at] = speed
|
|
1017
1056
|
}
|
|
1018
|
-
write(subjects[slot] as S, positions, base)
|
|
1057
|
+
if (moved) write(subjects[slot] as S, positions, base)
|
|
1019
1058
|
// At rest: still its member's, in neither list (a member is in one at most).
|
|
1020
1059
|
if (still) {
|
|
1021
1060
|
flags[slot] = LIVE
|
|
@@ -1051,6 +1090,9 @@ const stepRuledDriven = <S>(state: State<S>): void => {
|
|
|
1051
1090
|
}
|
|
1052
1091
|
const base = slot * stride
|
|
1053
1092
|
let still = true
|
|
1093
|
+
// Whether to write it: this step moved a key, or a change outside a step left it due. Paused, none moves.
|
|
1094
|
+
let moved = (flag & DUE) !== 0
|
|
1095
|
+
if (moved) flags[slot] = flag & ~DUE
|
|
1054
1096
|
for (let k = 0; k < stride; k++) {
|
|
1055
1097
|
const at = base + k
|
|
1056
1098
|
const rule = rules[at]
|
|
@@ -1058,19 +1100,25 @@ const stepRuledDriven = <S>(state: State<S>): void => {
|
|
|
1058
1100
|
const dt = dts[rule]
|
|
1059
1101
|
// Played backwards: its value worked out again where its Playhead has gone back to, out of line.
|
|
1060
1102
|
if (dt < 0) {
|
|
1103
|
+
const was = positions[at]
|
|
1061
1104
|
if (!stepBack(state, at, rule, dt)) still = false
|
|
1105
|
+
if (positions[at] !== was) moved = true
|
|
1062
1106
|
continue
|
|
1063
1107
|
}
|
|
1064
1108
|
const time = elapsed[at] + dt
|
|
1065
1109
|
elapsed[at] = time
|
|
1066
1110
|
// A tween, out of line.
|
|
1067
1111
|
if (kind === TWEEN) {
|
|
1112
|
+
const was = positions[at]
|
|
1068
1113
|
if (!stepTween(state, at, entries[rule].tween, time, dt)) still = false
|
|
1114
|
+
if (positions[at] !== was) moved = true
|
|
1069
1115
|
continue
|
|
1070
1116
|
}
|
|
1071
1117
|
// Keyframes, out of line: only a driven change's.
|
|
1072
1118
|
if (kind === KEYFRAMES) {
|
|
1119
|
+
const was = positions[at]
|
|
1073
1120
|
if (!stepKeyframes(state, at, rule, time, dt)) still = false
|
|
1121
|
+
if (positions[at] !== was) moved = true
|
|
1074
1122
|
continue
|
|
1075
1123
|
}
|
|
1076
1124
|
// A spring, as `springValues`': only the part of this tick past the delay moves it.
|
|
@@ -1084,12 +1132,14 @@ const stepRuledDriven = <S>(state: State<S>): void => {
|
|
|
1084
1132
|
const d = position - goal
|
|
1085
1133
|
position = goal + matrices[mi] * d + matrices[mi + 1] * speed
|
|
1086
1134
|
speed = matrices[mi + 2] * d + matrices[mi + 3] * speed
|
|
1135
|
+
moved = true
|
|
1087
1136
|
}
|
|
1088
1137
|
if (simDt > 0 && simDt < dt) {
|
|
1089
1138
|
const part = Spring.matrixFor(entries[rule].spring, simDt)
|
|
1090
1139
|
const d = position - goal
|
|
1091
1140
|
position = goal + part.dd * d + part.dv * speed
|
|
1092
1141
|
speed = part.vd * d + part.vv * speed
|
|
1142
|
+
moved = true
|
|
1093
1143
|
}
|
|
1094
1144
|
// A spring rests by its thresholds; one that ends at its duration, there (#359). Held by a paused
|
|
1095
1145
|
// Playhead, one already on its target is at rest.
|
|
@@ -1097,6 +1147,7 @@ const stepRuledDriven = <S>(state: State<S>): void => {
|
|
|
1097
1147
|
if (kind === TIMED) settled = time - delay >= entries[rule].spring.duration
|
|
1098
1148
|
if (dt === 0) settled = speed === 0 && position === goal && time >= delay
|
|
1099
1149
|
if (settled) {
|
|
1150
|
+
if (position !== goal) moved = true
|
|
1100
1151
|
position = goal
|
|
1101
1152
|
speed = 0
|
|
1102
1153
|
}
|
|
@@ -1104,7 +1155,7 @@ const stepRuledDriven = <S>(state: State<S>): void => {
|
|
|
1104
1155
|
positions[at] = position
|
|
1105
1156
|
velocities[at] = speed
|
|
1106
1157
|
}
|
|
1107
|
-
write(subjects[slot] as S, positions, base)
|
|
1158
|
+
if (moved) write(subjects[slot] as S, positions, base)
|
|
1108
1159
|
// At rest: still its member's, in neither list (a member is in one at most).
|
|
1109
1160
|
if (still) {
|
|
1110
1161
|
flags[slot] = LIVE
|
|
@@ -1368,7 +1419,10 @@ const startedPartway = <S>(state: State<S>, slot: number, dt: number): boolean =
|
|
|
1368
1419
|
if (velocities[at] === 0 && positions[at] === targets[at]) continue
|
|
1369
1420
|
stepKey(state, at, rules[at], dt)
|
|
1370
1421
|
}
|
|
1371
|
-
if (started)
|
|
1422
|
+
if (started) {
|
|
1423
|
+
state.flags[slot] = state.flags[slot] & ~DUE
|
|
1424
|
+
state.write(state.subjects[slot] as S, positions, base)
|
|
1425
|
+
}
|
|
1372
1426
|
return started
|
|
1373
1427
|
}
|
|
1374
1428
|
|
|
@@ -1912,7 +1966,9 @@ export const play = (self: Animation): number => {
|
|
|
1912
1966
|
|
|
1913
1967
|
/** The member at `slot` moving in the ruled list, so the next step draws it and rests it: 1 when that sets it off from rest. */
|
|
1914
1968
|
const moving = <S>(state: State<S>, slot: number): number => {
|
|
1915
|
-
|
|
1969
|
+
// Its values were set outside a step (a play, a seek, a stop or a cancel): drawn at the next, moved or not.
|
|
1970
|
+
const flag = state.flags[slot] | DUE
|
|
1971
|
+
state.flags[slot] = flag
|
|
1916
1972
|
if ((flag & IN_RULED) !== 0) return 0
|
|
1917
1973
|
state.flags[slot] = (flag & ~IN_PLAIN) | IN_RULED
|
|
1918
1974
|
state.ruledList[state.ruledCount] = slot
|
package/src/DefaultTransition.ts
CHANGED
|
@@ -58,4 +58,4 @@ export const ONE_TWEEN: KeyframesTransition = { type: "tween" }
|
|
|
58
58
|
* program.pipe(Effect.provide(DefaultTransition.layerOneSpring))
|
|
59
59
|
*/
|
|
60
60
|
// #429.
|
|
61
|
-
export const layerOneSpring: Layer.Layer<DefaultTransition> = Layer.succeed(DefaultTransition, { transitionFor: () => ONE_SPRING, keyframes: ONE_TWEEN })
|
|
61
|
+
export const layerOneSpring: Layer.Layer<DefaultTransition> = /*#__PURE__*/ Layer.succeed(DefaultTransition, { transitionFor: () => ONE_SPRING, keyframes: ONE_TWEEN })
|
package/src/LiveValue.ts
CHANGED
|
@@ -173,7 +173,7 @@ export const transform: {
|
|
|
173
173
|
<O extends number | string>(source: Atom.Atom<number>, input: ReadonlyArray<number>, output: ReadonlyArray<O>, options?: TransformOptions<O>): Effect.Effect<Atom.Atom<O>, never, InterpolatorRegistry.InterpolatorRegistry>
|
|
174
174
|
<O>(source: Atom.Atom<number>, input: ReadonlyArray<number>, output: ReadonlyArray<O>, options: MixedTransformOptions<O>): Effect.Effect<Atom.Atom<O>, never, InterpolatorRegistry.InterpolatorRegistry>
|
|
175
175
|
} = <O>(source: Atom.Atom<number>, input: ReadonlyArray<number>, output: ReadonlyArray<O>, options: TransformOptions<O> = {}) =>
|
|
176
|
-
Effect.map(interpolateWith(input, output, options), (map) => Atom.make((get) => map(get(source))))
|
|
176
|
+
Effect.map(interpolateWith(input, output, options), (map) => transformedFrom(Atom.make((get) => map(get(source))), source, input, output, options))
|
|
177
177
|
|
|
178
178
|
/** `v`'s stretch, as Motion's: the first that ends above it, else the last. Read on each change of the source. */
|
|
179
179
|
const stretchAt = <O>(stretches: Arr.NonEmptyReadonlyArray<Stretch<O>>, v: number): Stretch<O> =>
|
|
@@ -542,13 +542,137 @@ export const scroll: (options?: ScrollSource.Options) => Effect.Effect<ScrollVal
|
|
|
542
542
|
const source = yield* ScrollSource.ScrollSource
|
|
543
543
|
const info = yield* source.scroll(options)
|
|
544
544
|
return {
|
|
545
|
-
scrollX: Atom.make((get) => get(info).x.current),
|
|
546
|
-
scrollY: Atom.make((get) => get(info).y.current),
|
|
547
|
-
scrollXProgress: Atom.make((get) => get(info).x.progress),
|
|
548
|
-
scrollYProgress: Atom.make((get) => get(info).y.progress),
|
|
545
|
+
scrollX: derivedFrom(Atom.make((get) => get(info).x.current), options, "current", "x"),
|
|
546
|
+
scrollY: derivedFrom(Atom.make((get) => get(info).y.current), options, "current", "y"),
|
|
547
|
+
scrollXProgress: derivedFrom(Atom.make((get) => get(info).x.progress), options, "progress", "x"),
|
|
548
|
+
scrollYProgress: derivedFrom(Atom.make((get) => get(info).y.progress), options, "progress", "y"),
|
|
549
549
|
}
|
|
550
550
|
})
|
|
551
551
|
|
|
552
|
+
/** One `transform` a scroll-derived value went through: its ranges and options, as given. */
|
|
553
|
+
export interface ScrollTransform {
|
|
554
|
+
/** Its input stops, in the terms of the value it maps. */
|
|
555
|
+
readonly input: ReadonlyArray<number>
|
|
556
|
+
/** Its outputs, one a stop. */
|
|
557
|
+
readonly output: ReadonlyArray<unknown>
|
|
558
|
+
/** Its `ease` as given: one for every stretch, or a list, one a stretch; `None` for linear. */
|
|
559
|
+
readonly ease: Option.Option<Easing.Definition | ReadonlyArray<Easing.Definition>>
|
|
560
|
+
/** Whether the ends hold past the first and last stops: `clamp` not `false`. */
|
|
561
|
+
readonly clamp: boolean
|
|
562
|
+
/** Whether a `mixer` blends its outputs, rather than the registry. */
|
|
563
|
+
readonly mixed: boolean
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
/**
|
|
567
|
+
* How a Live value derives from a container's scroll, in no Environment's terms: the scroll it
|
|
568
|
+
* reads, as `scroll` was given it; whether it reads how far the container is scrolled (`current`) or
|
|
569
|
+
* its progress; on which axis; and each `transform` it went through since, in order. An Environment
|
|
570
|
+
* that can run a scroll-linked value with the scroll itself, as the DOM's native scroll timelines do (a
|
|
571
|
+
* **Timeline value**), reads it to decide whether it can, and how.
|
|
572
|
+
*/
|
|
573
|
+
export interface ScrollDerivation {
|
|
574
|
+
/** The scroll's options, as `scroll` was given them. */
|
|
575
|
+
readonly scroll: ScrollSource.Options
|
|
576
|
+
/** How far the container is scrolled, or its progress. */
|
|
577
|
+
readonly read: "current" | "progress"
|
|
578
|
+
/** The axis the value is read on. */
|
|
579
|
+
readonly axis: "x" | "y"
|
|
580
|
+
/** The `transform`s since, first to last: none for one of `scroll`'s own values. */
|
|
581
|
+
readonly transforms: ReadonlyArray<ScrollTransform>
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
// Module state (#460, Q7): each of `scroll`'s values' derivation, keyed by the Atom and held weakly, so
|
|
585
|
+
// an Atom gone takes its entry with it.
|
|
586
|
+
const derivations = new WeakMap<Atom.Atom<unknown>, ScrollDerivation>()
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* What an Atom derives from, as `transform` or `derivesAs` said: its source, and the transform it adds
|
|
590
|
+
* (none for `derivesAs`'s). Read through when its derivation is asked for, so a source described after
|
|
591
|
+
* the Atom was made, or described again, counts. `sourceDerivation` and `derivation` are the last
|
|
592
|
+
* answer, kept while the source's derivation is the same object.
|
|
593
|
+
*/
|
|
594
|
+
interface Link {
|
|
595
|
+
readonly source: Atom.Atom<unknown>
|
|
596
|
+
readonly step: ScrollTransform | undefined
|
|
597
|
+
sourceDerivation: ScrollDerivation | undefined
|
|
598
|
+
derivation: ScrollDerivation | undefined
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
// Module state (#460, Q7): each `transform`'s and each `derivesAs` Atom's link, keyed by the Atom and
|
|
602
|
+
// held weakly, so an Atom gone takes its entry with it. A link for every `transform`, scroll or not: its
|
|
603
|
+
// source may be described after it's made (a binding's, #240's PR 2), so none can be skipped as it's made.
|
|
604
|
+
const links = new WeakMap<Atom.Atom<unknown>, Link>()
|
|
605
|
+
|
|
606
|
+
/** `atom`, described as one of `scroll`'s values. */
|
|
607
|
+
const derivedFrom = <A>(atom: Atom.Atom<A>, scroll: ScrollSource.Options, read: ScrollDerivation["read"], axis: ScrollDerivation["axis"]): Atom.Atom<A> => {
|
|
608
|
+
derivations.set(atom, { scroll, read, axis, transforms: [] })
|
|
609
|
+
return atom
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
/** `atom`, `transform`'s over `source`: linked to it, so it derives as `source` does, then this transform, whenever `source` does. */
|
|
613
|
+
const transformedFrom = <A, O>(atom: Atom.Atom<A>, source: Atom.Atom<number>, input: ReadonlyArray<number>, output: ReadonlyArray<O>, options: TransformOptions<O>): Atom.Atom<A> => {
|
|
614
|
+
const step: ScrollTransform = { input, output, ease: Option.fromUndefinedOr(options.ease), clamp: options.clamp !== false, mixed: Predicate.isNotUndefined(options.mixer) }
|
|
615
|
+
links.set(atom, { source, step, sourceDerivation: undefined, derivation: undefined })
|
|
616
|
+
return atom
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
/**
|
|
620
|
+
* `atom`'s derivation now, read through its links: the same object while nothing it derives from
|
|
621
|
+
* changed. Statements, and nothing built while nothing changed.
|
|
622
|
+
*/
|
|
623
|
+
const derivationNow = (atom: Atom.Atom<unknown>): ScrollDerivation | undefined => {
|
|
624
|
+
const own = derivations.get(atom)
|
|
625
|
+
if (Predicate.isNotUndefined(own)) return own
|
|
626
|
+
const link = links.get(atom)
|
|
627
|
+
if (Predicate.isUndefined(link)) return undefined
|
|
628
|
+
const from = derivationNow(link.source)
|
|
629
|
+
if (Predicate.isUndefined(from)) return undefined
|
|
630
|
+
if (Predicate.isUndefined(link.step)) return from
|
|
631
|
+
if (link.sourceDerivation === from) return link.derivation
|
|
632
|
+
link.sourceDerivation = from
|
|
633
|
+
link.derivation = { ...from, transforms: [...from.transforms, link.step] }
|
|
634
|
+
return link.derivation
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
/**
|
|
638
|
+
* Describe `atom` as deriving from a container's scroll as `source` does: for an Atom a binding
|
|
639
|
+
* keeps for a value's life and sets from `source`, made after it, as a `createScroll` does once its
|
|
640
|
+
* elements are there. A `transform` made over `atom` before then derives through it too. Called again,
|
|
641
|
+
* it derives as the new `source` does. `source` mustn't derive from `atom`.
|
|
642
|
+
*
|
|
643
|
+
* @example
|
|
644
|
+
* const own = Atom.make(0)
|
|
645
|
+
* const { scrollYProgress } = yield* LiveValue.scroll({ container })
|
|
646
|
+
* LiveValue.derivesAs(own, scrollYProgress)
|
|
647
|
+
* registry.subscribe(scrollYProgress, (v: number) => registry.set(own, v))
|
|
648
|
+
*/
|
|
649
|
+
// #240 (ADR-0043 *Amendment (#240)*): a binding's Atom made before its source, as `createScroll`'s are.
|
|
650
|
+
// Tier 2 (ADR-0008): for binding authors.
|
|
651
|
+
export const derivesAs: {
|
|
652
|
+
(source: Atom.Atom<unknown>): <A>(atom: Atom.Atom<A>) => Atom.Atom<A>
|
|
653
|
+
<A>(atom: Atom.Atom<A>, source: Atom.Atom<unknown>): Atom.Atom<A>
|
|
654
|
+
} = dual(2, <A>(atom: Atom.Atom<A>, source: Atom.Atom<unknown>): Atom.Atom<A> => {
|
|
655
|
+
links.set(atom, { source, step: undefined, sourceDerivation: undefined, derivation: undefined })
|
|
656
|
+
return atom
|
|
657
|
+
})
|
|
658
|
+
|
|
659
|
+
/**
|
|
660
|
+
* How `atom` derives from a container's scroll, now: one of `scroll`'s values, an Atom
|
|
661
|
+
* `derivesAs` one, or a `transform` over either, a `transform` over that, and so on; `None` for any
|
|
662
|
+
* other, a `spring` or a `velocity` of one among them. Read again while nothing it derives from
|
|
663
|
+
* changed, it's the same object. An Environment reads it to run the value on a native scroll timeline
|
|
664
|
+
* where it can (a **Timeline value**).
|
|
665
|
+
*
|
|
666
|
+
* @example
|
|
667
|
+
* const { scrollYProgress } = yield* LiveValue.scroll({ container })
|
|
668
|
+
* const opacity = yield* LiveValue.transform(scrollYProgress, [0, 1], [1, 0])
|
|
669
|
+
* LiveValue.scrollDerivationOf(opacity)
|
|
670
|
+
* // Some({ scroll: { container }, read: "progress", axis: "y", transforms: [{ input: [0, 1], output: [1, 0], … }] })
|
|
671
|
+
*/
|
|
672
|
+
// #240 (ADR-0043 *Amendment (#240)*), read through `transform`'s and `derivesAs`'s links. Tier 2
|
|
673
|
+
// (ADR-0008): for Environment authors.
|
|
674
|
+
export const scrollDerivationOf = (atom: Atom.Atom<unknown>): Option.Option<ScrollDerivation> => Option.fromUndefinedOr(derivationNow(atom))
|
|
675
|
+
|
|
552
676
|
/** A machine of one number a tick, from a run's step. */
|
|
553
677
|
const numberMachine = (name: string, settles: boolean, start: () => (dt: number) => Frame.Frame<number>): Machine.Machine<Frame.Frame<number>> =>
|
|
554
678
|
Machine.make({ settles, span: { name, attributes: {} }, start })
|