Skip to content

Commit

Permalink
Fix some closure warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Orvell committed Apr 26, 2017
1 parent 89b1230 commit 5185554
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 18 deletions.
26 changes: 22 additions & 4 deletions externs/closure-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){};
/**
Expand Down Expand Up @@ -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
*/
Expand Down
38 changes: 31 additions & 7 deletions lib/legacy/legacy-element-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
/**
* @constructor
* @extends {base}
* @implements {Polymer_ElementMixin}
* @implements {Polymer_GestureEventListeners}
* @implements {Polymer_ElementMixin}
*/
const legacyElementBase = Polymer.GestureEventListeners(Polymer.ElementMixin(base));

Expand All @@ -61,14 +61,17 @@

/**
* @polymerMixinClass
* @implements {Polymer_LegacyElement}
* @implements {Polymer_LegacyElementMixin}
*/
class LegacyElement extends legacyElementBase {

constructor() {
super();
this.root = this;
this.created();
this.isAttached = false;
this.__boundListeners = null;
this._debouncers = null;
}

/**
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -188,7 +212,7 @@
* @return {string} Serialized value
*/
serialize(value) {
return this._serializeValue(value);
return this._serializeValue(value) || '';
}

/**
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -433,8 +457,8 @@
* that contains an insertion point (<slot>) inside its subtree.
*/
distributeContent() {
if (window.ShadyDOM && this.shadowRoot) {
this.shadowRoot.forceRender();
if (window.ShadyDOM) {
window.ShadyDOM.flush();
}
}

Expand Down
31 changes: 24 additions & 7 deletions lib/legacy/polymer.dom.html
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
*/
Expand All @@ -38,6 +41,9 @@
*/
class DomApi {

/**
* @param {Node} node Node for which to create a Polymer.dom helper object.
*/
constructor(node) {
this.node = node;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand All @@ -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];
},
Expand Down Expand Up @@ -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;
};
Expand Down
3 changes: 3 additions & 0 deletions lib/mixins/element-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 5185554

Please sign in to comment.