API Reference
fromRaf()
Browser animation-frame source.
Import
import { fromRaf } from "@graphrefly/ts/sources/browser";
Signature
function fromRaf(opts: FromRafOptions = {}): Operator<never, number>
Parameters
| Parameter | Type | Description |
|---|---|---|
opts | FromRafOptions | Optional 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
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
packages/ts/src/sources/browser.ts