Skip to content

@epikodelabs/streamix


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

Function: onMutation()

onMutation(element, options?): Stream<MutationRecord[]>

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

Creates a reactive stream that emits arrays of MutationRecord objects whenever mutations are observed on a given DOM element.

This stream is a wrapper around the MutationObserver API and is useful for reacting to DOM structure or attribute changes.

Behavior:

  • Resolves the target element and options once on first subscription.
  • Emits mutation records whenever changes occur.
  • Starts observing on first subscriber.
  • Stops observing when the last subscriber unsubscribes.
  • Safe to import and subscribe in SSR (no-op).
  • Fully compatible with async iteration.

Parameters

element

MaybePromise<Element>

The DOM element (or promise) to observe.

options?

MaybePromise<MutationObserverInit>

Optional MutationObserver options (or promise).

Returns

Stream<MutationRecord[]>

A stream of mutation records.

Released under the GNU AGPL v3 or later.