UNPKG

soo.js

Version:

custom-elements with renderer

2 lines (1 loc) 1.05 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.soo=t()}(this,function(){"use strict";return class extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"})}async connectedCallback(){this.install.apply(this),this.beforeRender();const e=await this.render();this.css&&this.shadowRoot.appendChild(function(e){const t=document.createElement("style");return t.textContent=e,t}(this.css())),this.shadowRoot.appendChild(e),this.installed()}disconnectedCallback(){this.uninstall()}fire(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t}))}fireGlobal(e,t){document.dispatchEvent(new CustomEvent(e,{detail:t}))}async update(){this.beforeUpdate();const e=await this.render();11===e.nodeType?(this.shadowRoot.childNodes.forEach(e=>{"STYLE"!==e.tagName&&3!==e.nodeType&&e.remove()}),this.shadowRoot.appendChild(e)):this.shadowRoot.lastChild.replaceWith(e),this.updated()}install(){}installed(){}uninstall(){}beforeUpdate(){}updated(){}beforeRender(){}}});