MutationDiffObserver

Helper object to setup a MutationObserver to report mutations to MutationDiff. This is useful for simple cases where you don't need to reuse the MutationObserver for other purposes, or you don't need to do advanced filtering of the mutation records.

Constructor

new MutationDiffObserver(tracker, roots, filteropt, attributeFilteropt)

Construct a new observer and begin observing

Parameters:
NameTypeAttributesDefaultDescription
trackerMutationDiff

the MutationDiff object to attach to

rootsNode | Array.<Node>

a single or list of root nodes to observe

filternumber<optional>
ALL

A bitmask specifying which mutations to observe, such as character data, attribute, or child list changes.

attributeFilterArray.<string><optional>

An array of specific attribute names to watch. Ignored if the ATTRIBUTE flag is not included in filter

Members

observer :MutationObserver

The internal MutationObserver object that is observing root

Type:
  • MutationObserver

options :Object

The observer options passed to MutationObserver.observe()

Type:
  • Object

root :Array.<Node>

A list of root nodes that are being observed

Type:
  • Array.<Node>

tracker :MutationDiff

The MutationDiff object that mutations are being reported to

Methods

flush(synchronizeopt)

Flush any pending MutationRecords so that MutationDiff is up-to-date. This is necessary because MutationObserver is async and batched, so the records lag behind the actual DOM mutations.

Parameters:
NameTypeAttributesDefaultDescription
synchronizeboolean<optional>
true

Whether to call MutationDiff#synchronize after flushing the records

reattach()

MutationObserver will observe descendants of root, and continues observing those descendants even when they are moved to a different part of the DOM tree (see explanation on MDN). This method will reattach the MutationObserver so that it is only observing the current descendants of root.

stop()

Stop the observer. You can call reattach to start observing again. Make sure to call stop when you are done, otherwise the object will not get garbage collected!