From 518555414f04953774ac0fca4c4191f014222124 Mon Sep 17 00:00:00 2001 From: Steven Orvell Date: Wed, 26 Apr 2017 15:21:29 -0700 Subject: [PATCH] Fix some closure warnings. --- externs/closure-types.js | 26 ++++++++++++++++--- lib/legacy/legacy-element-mixin.html | 38 +++++++++++++++++++++++----- lib/legacy/polymer.dom.html | 31 ++++++++++++++++++----- lib/mixins/element-mixin.html | 3 +++ 4 files changed, 80 insertions(+), 18 deletions(-) diff --git a/externs/closure-types.js b/externs/closure-types.js index c420bc296b..118f0085c6 100644 --- a/externs/closure-types.js +++ b/externs/closure-types.js @@ -396,9 +396,9 @@ Polymer_ElementMixin.prototype._readyClients = function(){}; Polymer_ElementMixin.prototype._attachDom = function(dom){}; /** * @override -* @param {*} name -* @param {*} old -* @param {*} value +* @param {string} name +* @param {string} old +* @param {string} value */ Polymer_ElementMixin.prototype.attributeChangedCallback = function(name, old, value){}; /** @@ -437,14 +437,32 @@ function Polymer_LegacyElementMixin(){} */ Polymer_LegacyElementMixin.prototype.created = function(){}; /** +* @override +*/ +Polymer_LegacyElementMixin.prototype.connectedCallback = function(){}; +/** */ Polymer_LegacyElementMixin.prototype.attached = function(){}; /** +* @override +*/ +Polymer_LegacyElementMixin.prototype.disconnectedCallback = function(){}; +/** */ Polymer_LegacyElementMixin.prototype.detached = function(){}; /** +* @override +* @param {string} name +* @param {string} old +* @param {string} value +*/ +Polymer_LegacyElementMixin.prototype.attributeChangedCallback = function(name, old, value){}; +/** +* @param {string} name +* @param {string} old +* @param {string} value */ -Polymer_LegacyElementMixin.prototype.attributeChanged = function(){}; +Polymer_LegacyElementMixin.prototype.attributeChanged = function(name, old, value){}; /** * @override */ diff --git a/lib/legacy/legacy-element-mixin.html b/lib/legacy/legacy-element-mixin.html index e831d6c1ef..4e0b5cfec3 100644 --- a/lib/legacy/legacy-element-mixin.html +++ b/lib/legacy/legacy-element-mixin.html @@ -43,8 +43,8 @@ /** * @constructor * @extends {base} - * @implements {Polymer_ElementMixin} * @implements {Polymer_GestureEventListeners} + * @implements {Polymer_ElementMixin} */ const legacyElementBase = Polymer.GestureEventListeners(Polymer.ElementMixin(base)); @@ -61,7 +61,7 @@ /** * @polymerMixinClass - * @implements {Polymer_LegacyElement} + * @implements {Polymer_LegacyElementMixin} */ class LegacyElement extends legacyElementBase { @@ -69,6 +69,9 @@ super(); this.root = this; this.created(); + this.isAttached = false; + this.__boundListeners = null; + this._debouncers = null; } /** @@ -77,6 +80,11 @@ */ created() {} + /** + * Provides an implementation of `connectedCallback` + * which adds Polymer legacy API's `attached` method. + * @override + */ connectedCallback() { super.connectedCallback(); this.isAttached = true; @@ -89,6 +97,11 @@ */ attached() {} + /** + * Provides an implementation of `disconnectedCallback` + * which adds Polymer legacy API's `detached` method. + * @override + */ disconnectedCallback() { super.disconnectedCallback(); this.isAttached = false; @@ -101,6 +114,14 @@ */ detached() {} + /** + * Provides an override implementation of `attributeChangedCallback` + * which adds the Polymer legacy API's `attributeChanged` method. + * @param {string} name Name of attribute. + * @param {string} old Old value of attribute. + * @param {string} value Current value of attribute. + * @override + */ attributeChangedCallback(name, old, value) { if (old !== value) { super.attributeChangedCallback(name, old, value); @@ -111,8 +132,11 @@ /** * Legacy callback called during `attributeChangedChallback`, for overriding * by the user. + * @param {string} name Name of attribute. + * @param {string} old Old value of attribute. + * @param {string} value Current value of attribute. */ - attributeChanged() {} + attributeChanged(name, old, value) {} // eslint-disable-line no-unused-vars /** * Overrides the default `Polymer.PropertyEffects` implementation to @@ -188,7 +212,7 @@ * @return {string} Serialized value */ serialize(value) { - return this._serializeValue(value); + return this._serializeValue(value) || ''; } /** @@ -421,7 +445,7 @@ */ get domHost() { let root = this.getRootNode(); - return (root instanceof DocumentFragment) ? root.host : root; + return (root instanceof DocumentFragment) ? /** @type {ShadowRoot} */ (root).host : root; } /** @@ -433,8 +457,8 @@ * that contains an insertion point () inside its subtree. */ distributeContent() { - if (window.ShadyDOM && this.shadowRoot) { - this.shadowRoot.forceRender(); + if (window.ShadyDOM) { + window.ShadyDOM.flush(); } } diff --git a/lib/legacy/polymer.dom.html b/lib/legacy/polymer.dom.html index ae9ba4bbc1..0d7f62dc8d 100644 --- a/lib/legacy/polymer.dom.html +++ b/lib/legacy/polymer.dom.html @@ -15,6 +15,9 @@ 'use strict'; const p = Element.prototype; + /** + * @const {function(this:Element, string): boolean} + */ const normalizedMatchesSelector = p.matches || p.matchesSelector || p.mozMatchesSelector || p.msMatchesSelector || p.oMatchesSelector || p.webkitMatchesSelector; @@ -24,7 +27,7 @@ * * @function matchesSelector * @memberof Polymer.dom - * @param {Node} node Node to check selector against + * @param {!Element} node Node to check selector against * @param {string} selector Selector to match * @return {boolean} True if node matched selector */ @@ -38,6 +41,9 @@ */ class DomApi { + /** + * @param {Node} node Node for which to create a Polymer.dom helper object. + */ constructor(node) { this.node = node; } @@ -146,10 +152,8 @@ } /** - * Returns a flattened list of all child nodes and nodes distributed + * @return {Array} Returns a flattened list of all child nodes and nodes assigned * to child slots. - * - * @return {type} Description */ getEffectiveChildNodes() { return Polymer.FlattenedNodesObserver.getFlattenedNodes(this.node); @@ -189,6 +193,10 @@ function forwardMethods(proto, methods) { for (let i=0; i < methods.length; i++) { let method = methods[i]; + /** + * @this {DomApi} + * @return {*} Returns method value + */ proto[method] = function() { return this.node[method].apply(this.node, arguments); } @@ -199,6 +207,10 @@ for (let i=0; i < properties.length; i++) { let name = properties[i]; Object.defineProperty(proto, name, { + /** + * @this {DomApi} + * @return {*} Returns property value + */ get: function() { return this.node[name]; }, @@ -288,14 +300,19 @@ * @summary Legacy DOM and Event manipulation API wrapper factory used to * abstract differences between native Shadow DOM and "Shady DOM." * @memberof Polymer - * @param {Node|Event} obj Node or event to operate on + * @param {!Node|Event} obj Node or event to operate on * @return {DomApi|EventApi} Wrapper providing either node API or event API */ Polymer.dom = function(obj) { obj = obj || document; - let ctor = obj instanceof Event ? EventApi : DomApi; if (!obj.__domApi) { - obj.__domApi = new ctor(obj); + let helper; + if (obj instanceof Event) { + helper = new EventApi(obj); + } else { + helper = new DomApi(obj); + } + obj.__domApi = helper; } return obj.__domApi; }; diff --git a/lib/mixins/element-mixin.html b/lib/mixins/element-mixin.html index 92b728d714..4bef530fb2 100644 --- a/lib/mixins/element-mixin.html +++ b/lib/mixins/element-mixin.html @@ -717,6 +717,9 @@ * same name. "Dash-cased" attributes are deserialzed to "camelCase" * properties. * + * @param {string} name Name of attribute. + * @param {string} old Old value of attribute. + * @param {string} value Current value of attribute. * @override */ attributeChangedCallback(name, old, value) {