fromRaf()
Browser animation-frame source.
Import
Section titled “Import”import { fromRaf } from "@graphrefly/ts/sources/browser";Signature
Section titled “Signature”function fromRaf(opts: FromRafOptions = {}): Operator<never, number>Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
opts | FromRafOptions | Optional scheduler, fallback timer cadence, visibility document, and strict background parking flag. |
Returns
Section titled “Returns”An open-ended source operator that emits animation-frame timestamps as DATA.
Example
Section titled “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
Section titled “Remarks”- Browser boundary: Each frame timestamp enters the graph as
DATAthroughctx.down, and teardown cancels the pending host callback. - Hidden tabs:
pauseWhenHidden: trueparks completely while the document is hidden; the default preserves the timer fallback behavior.
Source
Section titled “Source”packages/ts/src/sources/browser.ts