UNPKG

@polymer/polymer

Version:

The Polymer library makes it easy to create your own web components. Give your element some markup and properties, and then use it on a site. Polymer provides features like dynamic templates and data binding to reduce the amount of boilerplate you need to

85 lines (75 loc) 2.92 kB
// tslint:disable:variable-name Describing an API that's defined elsewhere. // tslint:disable:no-any describes the API as best we are able today import {calculateSplices} from './array-splice.js'; import {microTask} from './async.js'; export {FlattenedNodesObserver}; /** * Class that listens for changes (additions or removals) to * "flattened nodes" on a given `node`. The list of flattened nodes consists * of a node's children and, for any children that are `<slot>` elements, * the expanded flattened list of `assignedNodes`. * For example, if the observed node has children `<a></a><slot></slot><b></b>` * and the `<slot>` has one `<div>` assigned to it, then the flattened * nodes list is `<a></a><div></div><b></b>`. If the `<slot>` has other * `<slot>` elements assigned to it, these are flattened as well. * * The provided `callback` is called whenever any change to this list * of flattened nodes occurs, where an addition or removal of a node is * considered a change. The `callback` is called with one argument, an object * containing an array of any `addedNodes` and `removedNodes`. * * Note: the callback is called asynchronous to any changes * at a microtask checkpoint. This is because observation is performed using * `MutationObserver` and the `<slot>` element's `slotchange` event which * are asynchronous. * * An example: * ```js * class TestSelfObserve extends PolymerElement { * static get is() { return 'test-self-observe';} * connectedCallback() { * super.connectedCallback(); * this._observer = new FlattenedNodesObserver(this, (info) => { * this.info = info; * }); * } * disconnectedCallback() { * super.disconnectedCallback(); * this._observer.disconnect(); * } * } * customElements.define(TestSelfObserve.is, TestSelfObserve); * ``` */ declare class FlattenedNodesObserver { /** * eslint-disable-next-line */ constructor(target: any, callback: any); /** * eslint-disable-next-line */ static getFlattenedNodes(node: any): any; /** * Activates an observer. This method is automatically called when * a `FlattenedNodesObserver` is created. It should only be called to * re-activate an observer that has been deactivated via the `disconnect` method. */ connect(): void; /** * Deactivates the flattened nodes observer. After calling this method * the observer callback will not be called when changes to flattened nodes * occur. The `connect` method may be subsequently called to reactivate * the observer. */ disconnect(): void; /** * Flushes the observer causing any pending changes to be immediately * delivered the observer callback. By default these changes are delivered * asynchronously at the next microtask checkpoint. * * @returns Returns true if any pending changes caused the observer * callback to run. */ flush(): boolean; }