GraphReFlyTS

API Reference

fromRaf()

Browser animation-frame source.

Import

import { fromRaf } from "@graphrefly/ts/sources/browser";

Signature

function fromRaf(opts: FromRafOptions = {}): Operator<never, number>

Parameters

ParameterTypeDescription
optsFromRafOptionsOptional scheduler, fallback timer cadence, visibility document, and strict background parking flag.

Returns

An open-ended source operator that emits animation-frame timestamps as DATA.

Example

import { graph } from "@graphrefly/ts/graph";
import { fromRaf } from "@graphrefly/ts/sources/browser";

const frames = graph().initNode(fromRaf({ pauseWhenHidden: true }), [], { name: "frames" });
frames.subscribe((time) => {
  console.log("frame", time);
});

Remarks

  • Browser boundary: Each frame timestamp enters the graph as DATA through ctx.down, and teardown cancels the pending host callback.
  • Hidden tabs: pauseWhenHidden: true parks completely while the document is hidden; the default preserves the timer fallback behavior.

Source

packages/ts/src/sources/browser.ts