@polymer/polymer
Version:
The Polymer library makes it easy to create your own web components. Give your element some markup and properties, and then use it on a site. Polymer provides features like dynamic templates and data binding to reduce the amount of boilerplate you need to
52 lines (48 loc) • 1.79 kB
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
*
* import {Class} from '@polymer/polymer/lib/legacy/class.js';
* customElements.define(info.is, Class(info));
*
* See `Class` for details on valid legacy metadata format for `info`.
*
* @global
* @override
* @function
* @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);
}
// Copy opt out for `legacyNoObservedAttributes` from info object to class.
if (info._legacyForceObservedAttributes) {
klass.prototype._legacyForceObservedAttributes = info._legacyForceObservedAttributes;
}
customElements.define(klass.is, /** @type {!HTMLElement} */(klass));
return klass;
};
Polymer.Class = Class;
export { Polymer };