@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
108 lines (97 loc) • 4.28 kB
TypeScript
/**
* DO NOT EDIT
*
* This file was automatically generated by
* https://github.com/Polymer/tools/tree/master/packages/gen-typescript-declarations
*
* To modify these typings, edit the source file(s):
* lib/utils/flattened-nodes-observer.html
*/
// tslint:disable:variable-name Describing an API that's defined elsewhere.
// tslint:disable:no-any describes the API as best we are able today
/// <reference path="boot.d.ts" />
/// <reference path="array-splice.d.ts" />
/// <reference path="async.d.ts" />
declare namespace Polymer {
/**
* 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 Polymer.Element {
* static get is() { return 'test-self-observe';}
* connectedCallback() {
* super.connectedCallback();
* this._observer = new Polymer.FlattenedNodesObserver(this, (info) => {
* this.info = info;
* });
* }
* disconnectedCallback() {
* super.disconnectedCallback();
* this._observer.disconnect();
* }
* }
* customElements.define(TestSelfObserve.is, TestSelfObserve);
* ```
*/
class FlattenedNodesObserver {
/**
* @param target Node on which to listen for changes.
* @param callback Function called when there are additions
* or removals from the target's list of flattened nodes.
*/
constructor(target: _Element|null, callback: ((p0: _Element, p1: {target: _Element, addedNodes: _Element[], removedNodes: _Element[]}) => void)|null);
/**
* Returns the list of flattened nodes for the given `node`.
* This list 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.
*
* @param node The node for which to return the list of flattened nodes.
* @returns The list of flattened nodes for the given `node`.
*/
static getFlattenedNodes(node: HTMLElement|HTMLSlotElement|null): any[]|null;
/**
* 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;
}
}