ally.observe.shadowMutations

September 28, 2016 ยท View on GitHub

Registers MutationObservers across nested ShadowRoots.

Description

This service registers a MutationObserver so that all ShadowRoots within the given context are observed as well.

Usage

var handle = ally.observe.shadowMutations({
  context: '.within-filter-selector',
  callback: function(mutations) {
    console.log(mutations);
  },
  config: {
    childList: true,
    subtree: true,
  },
});
// stop observing
handle.disengage();

Arguments

NameTypeDefaultDescription
context<selector>documentElementThe scope of the DOM in which to search. The first element of a collection is used.
callbackfunctionrequiredThe callback to be invoked by the observer.
configMutationObserverInitrequiredThe configuration to be used by the observer.

Returns

A <service> interface, providing the handle.disengage() method to stop the service.

Throws

  • TypeError if context option is not an HTMLElement.
  • TypeError if callback option is not specified or not a function.
  • TypeError if config option is not specified or not an object.

Callback signature

The callback is invoked with one argument, an array of MutationRecords.

Examples

Changes

  • Added in v1.1.0.

Notes

:::note In browsers that do not support MutationObserver (e.g. Internet Explorer 9 and 10) this service does nothing. Mutation Events are too much of a burden on the browser, so not an option to fill the gap. :::

:::note The creation of ShadowRoots cannot be detected reliably, w3c/webcomponents#390. :::

Contributing