describe('mounting/unmount', () => {
const E = defineCustomElement({
- render: () => h('div', 'hello')
+ props: {
+ msg: {
+ type: String,
+ default: 'hello'
+ }
+ },
+ render() {
+ return h('div', this.msg)
+ }
})
customElements.define('my-element', E)
})
test('should work w/ manual instantiation', () => {
- const e = new E()
+ const e = new E({ msg: 'inline' })
// should lazy init
expect(e._instance).toBe(null)
// should initialize on connect
container.appendChild(e)
expect(e._instance).toBeTruthy()
- expect(e.shadowRoot!.innerHTML).toBe(`<div>hello</div>`)
+ expect(e.shadowRoot!.innerHTML).toBe(`<div>inline</div>`)
})
test('should unmount on remove', async () => {
import { camelize, extend, hyphenate, isArray, toNumber } from '@vue/shared'
import { hydrate, render } from '.'
-type VueElementConstructor<P = {}> = {
- new (): VueElement & P
+export type VueElementConstructor<P = {}> = {
+ new (initialProps?: Record<string, any>): VueElement & P
}
// defineCustomElement provides the same type inference as defineComponent
static get observedAttributes() {
return attrKeys
}
- constructor() {
- super(Comp, attrKeys, propKeys, hydate)
+ constructor(initialProps?: Record<string, any>) {
+ super(Comp, initialProps, attrKeys, propKeys, hydate)
}
}
) as typeof HTMLElement
export class VueElement extends BaseClass {
- /**
- * @internal
- */
- _props: Record<string, any> = {}
/**
* @internal
*/
constructor(
private _def: ComponentOptions & { styles?: string[] },
+ private _props: Record<string, any> = {},
private _attrKeys: string[],
private _propKeys: string[],
hydrate?: RootHydrateFunction