Skip to content

Latest commit

 

History

History
57 lines (42 loc) · 1.99 KB

frommutationobserver.md

File metadata and controls

57 lines (42 loc) · 1.99 KB

Rx.DOM.fromMutationObserver(target, options)

Creates an observable sequence from a MutationObserver. The MutationObserver provides developers a way to react to changes in a DOM. This requires MutationObserver to be supported in your browser/JavaScript runtime.

Arguments

  1. target (Node): The Node on which to observe DOM mutations.
  2. options (MutationObserverInit): A MutationObserverInit object, specifies which DOM mutations should be reported.

Returns

(Observable): An observable sequence which contains mutations on the given DOM target.

Example

var foo = document.getElementById('foo');

var obs = Rx.DOM.fromMutationObserver(foo, {
  attributes: true,
  childList: true,
  characterData: true,
  attributeFilter: ["id", "dir"],
  attributeOldValue: true
});

foo.dir = 'rtl';

// Listen for mutations
obs.subscribe(function (mutations) {
    mutations.forEach(function(mutation) {
    console.log("Type of mutation: " + mutation.type);

    if ("attributes" === mutation.type) {
      console.log("Old attribute value: " + mutation.oldValue);
    }
  });
});

Location

File:

Dist:

Prerequisites:

NPM Packages:

NuGet Packages:

Unit Tests: