vue3-core/packages/runtime-vapor/src/apiCreateApp.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

40 lines
1.1 KiB
TypeScript
Raw Normal View History

2024-12-04 13:50:54 +08:00
import { normalizeContainer } from './_old/apiRender'
import { insert } from './dom/element'
import { type VaporComponent, createComponent } from './component'
2024-12-04 11:54:26 +08:00
import {
type AppMountFn,
type AppUnmountFn,
type CreateAppFunction,
createAppAPI,
} from '@vue/runtime-core'
2024-12-04 13:50:54 +08:00
let _createApp: CreateAppFunction<ParentNode, VaporComponent>
2024-12-04 11:54:26 +08:00
const mountApp: AppMountFn<ParentNode> = (app, container) => {
// clear content before mounting
if (container.nodeType === 1 /* Node.ELEMENT_NODE */) {
container.textContent = ''
}
const instance = createComponent(app._component)
insert(instance.block, container)
return instance
}
const unmountApp: AppUnmountFn = app => {
// TODO
}
2024-12-03 16:48:28 +08:00
2024-12-04 13:50:54 +08:00
export const createVaporApp: CreateAppFunction<
ParentNode,
VaporComponent
> = comp => {
2024-12-04 11:54:26 +08:00
if (!_createApp) _createApp = createAppAPI(mountApp, unmountApp)
const app = _createApp(comp)
const mount = app.mount
app.mount = (container, ...args: any[]) => {
container = normalizeContainer(container) // TODO reuse from runtime-dom
return mount(container, ...args)
2024-12-03 16:48:28 +08:00
}
2024-12-04 11:54:26 +08:00
return app
2024-12-03 16:48:28 +08:00
}