Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a basic jsdoc externs file for Polymer #769

Merged
merged 7 commits into from
Oct 16, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions polymer.externs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/**
* @fileoverview Closure compiler externs for the Polymer library.
*
* @externs
* @license
* Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at
* http://polymer.github.io/LICENSE.txt. The complete set of authors may be
* found at http://polymer.github.io/AUTHORS.txt. The complete set of
* contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt. Code
* distributed by Google as part of the polymer project is also subject to an
* additional IP rights grant found at http://polymer.github.io/PATENTS.txt.
*/

/**
* @param {string} name The name of the declared Polymer element.
* @param {PolymerElement} prototype The prototype of the element.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note we overload this too: Polymer({}) without a name is also valid (though not seen in the wild that frequently ...yet?). Not sure if that's worth it for the externs, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My preference would be to punt on this for the moment, as the existing use cases I've seen for compilation would put the Polymer() calls far away and uncorrelated with the element declaration such that I suspect that it will not be possible to infer the name.

(ok, that and I don't know how to set up the types such that Polymer('hello-world', {}) and Polymer({}) are both accepted but Polymer({}, {}) is rejected)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think vulcanize handles this now by attaching a name to the containing element, and we respect that: https://github.com/Polymer/polymer-dev/blob/master/src/declaration/polymer.js#L25

However, I'm there with ya on making the type expression work :P Punt!

*/
var Polymer = function(name, prototype) {};


/** @constructor @extends {HTMLElement} */
var PolymerElement = function() {
/** @type {Object.<string, !HTMLElement>} */
this.$;
};

// Canonical docs for these lifecycle callbacks are here:
// http://www.polymer-project.org/docs/polymer/polymer.html#lifecyclemethods

/** On create callback. */
PolymerElement.prototype.created = function() {};
/** On ready callback. */
PolymerElement.prototype.ready = function() {};
/** On attached to the DOM callback. */
PolymerElement.prototype.attached = function() {};
/** On DOM ready callback. */
PolymerElement.prototype.domReady = function() {};
/** On detached from the DOM callback. */
PolymerElement.prototype.detached = function() {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably add attributeChanged, too:

/**
 * Callback fired when an attribute on the element has been added, changed, or removed.
 *
 * @param {string} name The name of the attribute that changed.
 * @param {*} oldValue The previous value of the attribute, or null if it was added.
 * @param {*} newValue The new value of the attribute, or null if it was removed.
 * @param {string} namespace The namespace of the attribute.
 */
PolymerElement.prototype.attributeChanged = function(name, oldValue, newValue, namespace) {};

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh neat! Done


/**
* Callback fired when an attribute on the element has been added, changed, or removed.
*
* @param {string} name The name of the attribute that changed.
* @param {*} oldValue The previous value of the attribute, or null if it was added.
* @param {*} newValue The new value of the attribute, or null if it was removed.
* @param {string} namespace The namespace of the attribute.
*/
PolymerElement.prototype.attributeChanged = function(
name, oldValue, newValue, namespace) {};

/**
* Fire a callback when the light DOM children of an element changes.
* `callback` is called at most once, and should re-register with onMutation
* if it cares about further changes to the light DOM.
*
* @param {!Node} domNode The node to observe for changes. Often
* the polymerElement itself.
* @param {function(!MutationObserver, !Array.<!MutationRecord>)} callback
* The function to call when changes happen.
*/
PolymerElement.prototype.onMutation = function(domNode, callback) {};


/**
* Call the callback after a given timeout.
*
* @param {(Function|string)} callback The function to call after the delay.
* Called with `this` bound to the polymerElement.
* @param {Array=} opt_args Arguments to pass to callback.
* @param {number=} opt_timeoutMillis Minimum delay in milliseconds before
* calling the callback.
* @return {number} A handle for `#cancelAsync()`
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

async also takes functions by name, and returns a handle (for cancelAsync): https://github.com/Polymer/polymer-dev/blob/master/src/instance/utils.js#L18-59

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

PolymerElement.prototype.async = function(
callback, opt_args, opt_timeoutMillis) {};

/**
* Cancels the async operation with the given handle from executing if
* it hasn't yet run. See `#async()`.
*
* @param {number} handle The handle for the async operation to cancel.
*/
PolymerElement.prototype.cancelAsync = function(handle) {};


/**
* Call the callback after a timeout. Calling job again with the same name
* resets the timer but will not result in additional calls to callback.
*
* @param {string} name
* @param {Function} callback
* @param {number} timeoutMillis The minimum delay in milliseconds before
* calling the callback.
*/
PolymerElement.prototype.job = function(name, callback, timeoutMillis) {};


/**
* Fire an event.
*
* @param {string} type An event name.
* @param {*=} detail
* @param {Node=} onNode Target node.
* @param {boolean=} bubbles Set false to prevent bubbling, defaults to true.
* @param {boolean=} cancelable Set false to prevent cancellation, defaults to
* true.
* @return {Object} event
*/
PolymerElement.prototype.fire =
function(type, detail, onNode, bubbles, cancelable) {};