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.

67 lines
1.5 KiB
TypeScript
Raw Normal View History

import {
type VaporComponent,
type VaporComponentInstance,
createComponent,
2024-12-10 17:00:35 +08:00
getExposed,
mountComponent,
unmountComponent,
} from './component'
2024-12-04 11:54:26 +08:00
import {
type AppMountFn,
type AppUnmountFn,
type CreateAppFunction,
createAppAPI,
2024-12-04 14:22:26 +08:00
normalizeContainer,
2024-12-10 12:49:47 +08:00
warn,
2024-12-04 14:22:26 +08:00
} from '@vue/runtime-dom'
import type { RawProps } from './componentProps'
2024-12-04 11:54:26 +08:00
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 = ''
}
2024-12-10 12:49:47 +08:00
const instance = createComponent(
app._component,
app._props as RawProps,
null,
false,
app._context,
)
mountComponent(instance, container)
2024-12-04 11:54:26 +08:00
return instance
}
const unmountApp: AppUnmountFn = app => {
unmountComponent(app._instance as VaporComponentInstance, app._container)
2024-12-04 11:54:26 +08:00
}
2024-12-03 16:48:28 +08:00
2024-12-09 22:04:15 +08:00
export const createVaporApp: CreateAppFunction<ParentNode, VaporComponent> = (
comp,
props,
) => {
2024-12-10 17:00:35 +08:00
if (!_createApp) _createApp = createAppAPI(mountApp, unmountApp, getExposed)
2024-12-09 22:04:15 +08:00
const app = _createApp(comp, props)
2024-12-10 12:49:47 +08:00
if (__DEV__) {
app.config.globalProperties = new Proxy(
{},
{
set() {
warn(`app.config.globalProperties is not supported in vapor mode.`)
return false
},
},
)
}
2024-12-04 11:54:26 +08:00
const mount = app.mount
app.mount = (container, ...args: any[]) => {
2024-12-04 14:22:26 +08:00
container = normalizeContainer(container) as ParentNode
2024-12-04 11:54:26 +08:00
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
}