-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hybrid compatibility for PolymerDomApi and Polymer.Iconset types.
Polymer V1 applications are compiled with hand-written externs at https://github.com/google/closure-compiler/blob/master/contrib/externs/polymer-1.0.js. These externs contain some types that do not exist in the V2 code. PolymerDomApi is the type returned by the V1 Polymer.dom API, but in V2 it returns Polymer.DomApi. This adds the PolymerDomApi interface to the V2 externs, and annotates that Polymer.DomApi implements it. This allows both V1 and V2 code to use the PolymerDomApi type. Similar story for PolymerDomApi.ObserveCallback. Polymer.Iconset would ideally live in the iron-iconset repo, but many packages reference the type without actually depending on that library, so its simpler to just include it here, similar to how it worked for Polymer V1.
- Loading branch information
Showing
5 changed files
with
230 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
/** | ||
* @externs | ||
* @fileoverview Externs for PolymerDomApi for backwards compatibility with | ||
* the Polymer 1 externs. | ||
*/ | ||
|
||
/** | ||
* A Polymer DOM API for manipulating DOM such that local DOM and light DOM | ||
* trees are properly maintained. | ||
* | ||
* This type exists only to provide compatibility between compiled hybrid | ||
* Polymer V1 and V2 code. Polymer V2 only code should simply use the DomApi | ||
* class type. | ||
* | ||
* @interface | ||
*/ | ||
var PolymerDomApi = function() {}; | ||
|
||
/** | ||
* @param {?Node} node | ||
* @return {boolean} | ||
*/ | ||
PolymerDomApi.prototype.deepContains = function(node) {}; | ||
|
||
/** @param {!Node} node */ | ||
PolymerDomApi.prototype.appendChild = function(node) {}; | ||
|
||
/** | ||
* @param {!Node} oldNode | ||
* @param {!Node} newNode | ||
*/ | ||
PolymerDomApi.prototype.replaceChild = function(oldNode, newNode) {}; | ||
|
||
/** | ||
* @param {!Node} node | ||
* @param {?Node} beforeNode | ||
*/ | ||
PolymerDomApi.prototype.insertBefore = function(node, beforeNode) {}; | ||
|
||
/** @param {!Node} node */ | ||
PolymerDomApi.prototype.removeChild = function(node) {}; | ||
|
||
/** @type {!Array<!HTMLElement>|!NodeList<!HTMLElement>} */ | ||
PolymerDomApi.prototype.children; | ||
|
||
/** @type {!Array<!Node>|!NodeList<!Node>} */ | ||
PolymerDomApi.prototype.childNodes; | ||
|
||
/** @type {?Node} */ | ||
PolymerDomApi.prototype.parentNode; | ||
|
||
/** @type {?Node} */ | ||
PolymerDomApi.prototype.firstChild; | ||
|
||
/** @type {?Node} */ | ||
PolymerDomApi.prototype.lastChild; | ||
|
||
/** @type {?HTMLElement} */ | ||
PolymerDomApi.prototype.firstElementChild; | ||
|
||
/** @type {?HTMLElement} */ | ||
PolymerDomApi.prototype.lastElementChild; | ||
|
||
/** @type {?Node} */ | ||
PolymerDomApi.prototype.previousSibling; | ||
|
||
/** @type {?Node} */ | ||
PolymerDomApi.prototype.nextSibling; | ||
|
||
/** @type {?HTMLElement} */ | ||
PolymerDomApi.prototype.previousElementSibling; | ||
|
||
/** @type {?HTMLElement} */ | ||
PolymerDomApi.prototype.nextElementSibling; | ||
|
||
/** @type {string} */ | ||
PolymerDomApi.prototype.textContent; | ||
|
||
/** @type {string} */ | ||
PolymerDomApi.prototype.innerHTML; | ||
|
||
/** @type {?HTMLElement} */ | ||
PolymerDomApi.prototype.activeElement; | ||
|
||
/** | ||
* @param {string} selector | ||
* @return {?Element} | ||
*/ | ||
PolymerDomApi.prototype.querySelector = function(selector) {}; | ||
|
||
/** | ||
* @param {string} selector | ||
* @return {!Array<!Element>|!NodeList<!Element>} | ||
*/ | ||
PolymerDomApi.prototype.querySelectorAll = function(selector) {}; | ||
|
||
/** @return {!Array<!Node>} */ | ||
PolymerDomApi.prototype.getDistributedNodes = function() {}; | ||
|
||
/** @return {!Array<!Node>} */ | ||
PolymerDomApi.prototype.getDestinationInsertionPoints = function() {}; | ||
|
||
/** @return {?Node} */ | ||
PolymerDomApi.prototype.getOwnerRoot = function() {}; | ||
|
||
/** | ||
* @param {string} attribute | ||
* @param {string} value | ||
*/ | ||
PolymerDomApi.prototype.setAttribute = function(attribute, value) {}; | ||
|
||
/** @param {string} attribute */ | ||
PolymerDomApi.prototype.removeAttribute = function(attribute) {}; | ||
|
||
/** | ||
* @typedef {function(!PolymerDomApi.ObserveInfo)} | ||
*/ | ||
PolymerDomApi.ObserveCallback; | ||
|
||
/** | ||
* @typedef {{ | ||
* target: !Node, | ||
* addedNodes: !Array<!Node>, | ||
* removedNodes: !Array<!Node> | ||
* }} | ||
*/ | ||
PolymerDomApi.ObserveInfo; | ||
|
||
/** | ||
* A virtual type for observer callback handles. | ||
* | ||
* @interface | ||
*/ | ||
PolymerDomApi.ObserveHandle = function() {}; | ||
|
||
/** | ||
* @return {void} | ||
*/ | ||
PolymerDomApi.ObserveHandle.prototype.disconnect = function() {}; | ||
|
||
/** | ||
* Notifies callers about changes to the element's effective child nodes, | ||
* the same list as returned by `getEffectiveChildNodes`. | ||
* | ||
* @param {!PolymerDomApi.ObserveCallback} callback The supplied callback | ||
* is called with an `info` argument which is an object that provides | ||
* the `target` on which the changes occurred, a list of any nodes | ||
* added in the `addedNodes` array, and nodes removed in the | ||
* `removedNodes` array. | ||
* | ||
* @return {!PolymerDomApi.ObserveHandle} Handle which is the argument to | ||
* `unobserveNodes`. | ||
*/ | ||
PolymerDomApi.prototype.observeNodes = function(callback) {}; | ||
|
||
/** | ||
* Stops observing changes to the element's effective child nodes. | ||
* | ||
* @param {!PolymerDomApi.ObserveHandle} handle The handle for the | ||
* callback that should no longer receive notifications. This | ||
* handle is returned from `observeNodes`. | ||
*/ | ||
PolymerDomApi.prototype.unobserveNodes = function(handle) {}; | ||
|
||
/** @type {?DOMTokenList} */ | ||
PolymerDomApi.prototype.classList; | ||
|
||
/** | ||
* @param {string} selector | ||
* @return {!Array<!HTMLElement>} | ||
*/ | ||
PolymerDomApi.prototype.queryDistributedElements = function(selector) {}; | ||
|
||
/** | ||
* Returns a list of effective child nodes for this element. | ||
* | ||
* @return {!Array<!HTMLElement>} | ||
*/ | ||
PolymerDomApi.prototype.getEffectiveChildNodes = function() {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* @externs | ||
* @fileoverview Externs for Polymer.Iconset. | ||
*/ | ||
|
||
/** | ||
* The interface that iconsets should obey. Iconsets are registered by setting | ||
* their name in the IronMeta 'iconset' db, and a value of type Polymer.Iconset. | ||
* | ||
* Used by iron-icon but needs to live here since iron-icon, iron-iconset, etc don't | ||
* depend on each other at all and talk only through iron-meta. | ||
* | ||
* @interface | ||
*/ | ||
Polymer.Iconset = function() {}; | ||
|
||
/** | ||
* Applies an icon to the given element as a css background image. This | ||
* method does not size the element, and it's usually necessary to set | ||
* the element's height and width so that the background image is visible. | ||
* | ||
* @param {Element} element The element to which the icon is applied. | ||
* @param {string} icon The name of the icon to apply. | ||
* @param {string=} theme (optional) The name or index of the icon to apply. | ||
* @param {number=} scale (optional, defaults to 1) Icon scaling factor. | ||
*/ | ||
Polymer.Iconset.prototype.applyIcon = function( | ||
element, icon, theme, scale) {}; | ||
|
||
/** | ||
* Remove an icon from the given element by undoing the changes effected | ||
* by `applyIcon`. | ||
* | ||
* @param {Element} element The element from which the icon is removed. | ||
*/ | ||
Polymer.Iconset.prototype.removeIcon = function(element) {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters