Skip to content

@epikodelabs/streamix


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

Function: onVisibilityChange()

onVisibilityChange(): Stream<DocumentVisibilityState>

Defined in: projects/libraries/streamix/dom/src/lib/streams/onVisibilityChange.ts:22

Creates a reactive stream that emits the document's visibility state whenever it changes.

This stream is useful for:

  • pausing animations or polling when the page is hidden
  • throttling background work
  • detecting tab switching or minimization

Behavior:

  • Emits the current visibility state on start.
  • Emits on every visibilitychange event.
  • Starts listening on first subscriber.
  • Stops listening when the last subscriber unsubscribes.
  • Safe to import and subscribe in SSR (no-op).
  • Fully compatible with async iteration.

Returns

Stream<DocumentVisibilityState>

Released under the GNU AGPL v3 or later.