Skip to content
PACKAGES

fromRaf()

Browser animation-frame source.

import { fromRaf } from "@graphrefly/ts/sources/browser";
function fromRaf(opts: FromRafOptions = {}): Operator<never, number>
ParameterTypeDescription
optsFromRafOptionsOptional scheduler, fallback timer cadence, visibility document, and strict background parking flag.

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

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);
});
  • 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.

packages/ts/src/sources/browser.ts