Skip to content

@epikodelabs/streamix


@epikodelabs/streamix / dom/src/public-api / onAnimationFrame

Function: onAnimationFrame()

onAnimationFrame(): Stream<number>

Defined in: projects/libraries/streamix/dom/src/lib/streams/onAnimationFrame.ts:19

Creates a reactive stream that emits the time delta (in milliseconds) between consecutive animation frames.

This stream is driven by requestAnimationFrame when available, with a timer-based fallback for non-browser environments.

Behavior:

  • A shared RAF loop starts when the first subscriber subscribes.
  • Emits the delta between consecutive frames.
  • Stops the RAF loop when the last subscriber unsubscribes.
  • Safe to import and subscribe in SSR (no-op).
  • Fully compatible with async iteration.

Returns

Stream<number>

A stream emitting frame-to-frame time deltas.

Released under the GNU AGPL v3 or later.