const propKeys = rawKeys.map(camelize)
class VueCustomElement extends VueElement {
+ static def = Comp
static get observedAttributes() {
return attrKeys
}
)
}
this.attachShadow({ mode: 'open' })
- if (_def.styles) {
- _def.styles.forEach(css => {
- const s = document.createElement('style')
- s.textContent = css
- this.shadowRoot!.appendChild(s)
- })
- }
+ this._applyStyles()
}
}
vnode.ce = instance => {
this._instance = instance
instance.isCE = true
+ // HMR
+ if (__DEV__) {
+ instance.appContext.reload = () => {
+ render(this._createVNode(), this.shadowRoot!)
+ this.shadowRoot!.querySelectorAll('style').forEach(s => {
+ this.shadowRoot!.removeChild(s)
+ })
+ this._applyStyles()
+ }
+ }
// intercept emit
instance.emit = (event: string, ...args: any[]) => {
}
return vnode
}
+
+ private _applyStyles() {
+ if (this._def.styles) {
+ this._def.styles.forEach(css => {
+ const s = document.createElement('style')
+ s.textContent = css
+ this.shadowRoot!.appendChild(s)
+ })
+ }
+ }
}