-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Changes from all commits
3c8dc2a
f706d5b
579541b
2870070
354cc57
3d13cde
ccdcdaa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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. | ||
*/ | ||
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() {}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably add /**
* 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) {}; There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()` | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. async also takes functions by name, and returns a handle (for There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) {}; |
There was a problem hiding this comment.
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 aname
is also valid (though not seen in the wild that frequently ...yet?). Not sure if that's worth it for the externs, though.There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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#L25However, I'm there with ya on making the type expression work :P Punt!