A cross browser document.registerElement without built-in extends.
Simply include the polyfill on top of your page and use document.registerElement(name, info) like the good old days.
<scriptsrc="https://unpkg.com/ce-v0@latest/min.js"></script>Same compatibility of original polyfill: every Mobile and Desktop browser.
You can verify your browser compatibility live.
varMyElement=document.registerElement('my-element',{prototype: Object.create(HTMLElement.prototype,{createdCallback: {value: function(){console.log('custom element ready/upgraded');// better than V1 constructor() {}// because the element here will always// be already upgraded}},attachedCallback: {value: function(){console.log('custom element connected');// same as connectedCallback}},detachedCallback: {value: function(){console.log('custom element disconnected');// same as disconnectedCallback}},attributeChangedCallback: {value: function(name,oldValue,newValue){console.log('*any* attribute change');// different from V1 in two ways:// * it does not trigger twice with same attribute value// * it triggers for any attribute change, no need// to define static get observedAttributes() {[...]}}}})});// example via createElementdocument.body.appendChild(document.createElement('my-element'));// using the class directlydocument.body.appendChild(newMyElement);No extends will be performed, create extends from your own classes if needed (i.e. from MyElement.prototype).
TL;DR with native V1 API available it's easy to re-create V0 behavior keeping performance while it's not true the other way around.
This projects solves all transpilations and compatibility issues, providing a reliable, battle tested, V0 API for every browser.
To know more, please read the related blog entry.
By no means this project wants to stop adoption or usage of V1 API, quite the opposite, it's waiting for the time where every browser ships it natively, and every part of V0 related code can be dropped to make it a 1KB downgrade fully based on V1, like it is already for both Chrome and Safari.
constMyElement=newComponent({// the Custom Element namename: 'my-element',// one or more static propertystatic: {TEST: 123,method(){}},// alias for createdCallback// the component is ready/upgraded hereconstructor(){},// alias for attributeChangedCallbackonattribute(){},// alias for attachedCallbackonconnected(){},// alias for detachedCallbackondisconnected(){}// any other prototype definition is allowed// including getters and setters});If you use static methods / properties inside methods you need to define your components upfront.