Files
polymer/lib/legacy/polymer-fn.js
2018-04-19 16:26:04 -07:00

46 lines
1.5 KiB
JavaScript

/**
@license
Copyright (c) 2017 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
*/
import { Class } from './class.js';
import '../utils/boot.js';
/**
* Legacy class factory and registration helper for defining Polymer
* elements.
*
* This method is equivalent to
* `customElements.define(info.is, Polymer.Class(info));`
*
* See `Polymer.Class` for details on valid legacy metadata format for `info`.
*
* @global
* @override
* @function Polymer
* @param {!PolymerInit} info Object containing Polymer metadata and functions
* to become class methods.
* @return {function(new: HTMLElement)} Generated class
* @suppress {duplicate, invalidCasts, checkTypes}
*/
const Polymer = function(info) {
// if input is a `class` (aka a function with a prototype), use the prototype
// remember that the `constructor` will never be called
let klass;
if (typeof info === 'function') {
klass = info;
} else {
klass = Polymer.Class(info);
}
customElements.define(klass.is, /** @type {!HTMLElement} */(klass));
return klass;
};
Polymer.Class = Class;
export { Polymer };