FrameLoop

The Frame loop: the one loop per Environment that steps every running animation once a tick, in one pass, so many animations cost one loop and not a fiber each. A binding runs its animations on it with Machine.run, each Frame handed to its sink. CheckFrames turns on a check for development, which fails a run whose step gives a NaN or an Infinity, with NonFiniteFrame.

import * as FrameLoop from "@wardic/core/FrameLoop"

// In development, beside the Environment you hand your provider:
const checked = Layer.mergeAll(environment, Layer.succeed(FrameLoop.CheckFrames, true))

Its exports also name types the module doesn't export: its internal types.

Classes

FrameLoop

The Frame loop: run runs a machine on it, as Machine.run does, and runLast one stepped after every other in each tick, for one that reads what the others wrote.

Extends


NonFiniteFrame

A Frame with a NaN or an Infinity in its value: the defect a checked run dies with. key is the key that held it, None when the value is the number itself, and value is what it held.

Extends

  • YieldableError<this> & object & Readonly<{ key: Option<string>; message: string; value: unknown; }>

Constructors

Constructor
new NonFiniteFrame(args): NonFiniteFrame;
Parameters
args
key

Option<string>

message

string

value

unknown

Returns

NonFiniteFrame

Inherited from

Data.TaggedError("NonFiniteFrame")<{ readonly key: Option.Option<string> readonly value: unknown readonly message: string }>.constructor

Properties

key
readonly key: Option<string>;
Inherited from

Data.TaggedError("NonFiniteFrame").key

message
message: string;
Inherited from

Data.TaggedError("NonFiniteFrame").message

value
readonly value: unknown;
Inherited from

Data.TaggedError("NonFiniteFrame").value

Type Aliases

Sink

type Sink<F> = (frame) => undefined;

Where a run's Frames go: a plain call, never an Effect. It returns undefined, so a sink that returns an Effect doesn't compile, where a void one would drop the Effect silently. A Frame handed to a sink is the run's until the next tick, which may rewrite it in place: a sink that keeps a Frame, its value or its velocity, copies it.

Type Parameters

F

F

Parameters

frame

F

Returns

undefined

Variables

CheckFrames

const CheckFrames: Context.Reference<boolean>;

A check for development, off by default: on, every run started where it's on checks each Frame before its sink gets it, and fails with NonFiniteFrame on a NaN or an Infinity. Read once a run, from the caller's fiber, so an app turns it on by merging Layer.succeed(CheckFrames, true) beside its Environment.


layer

const layer: Layer<FrameLoop, never, Clock>;

The Frame loop over the Environment's Clock. Every Environment merges it in.