Skip to content

Commit ccd42b1

Browse files
committed
refactor: adjust vapor/vdom interop
1 parent be5c2a2 commit ccd42b1

File tree

6 files changed

+33
-40
lines changed

6 files changed

+33
-40
lines changed

packages/runtime-core/src/apiCreateApp.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
type Component,
3+
type ComponentInternalInstance,
34
type ConcreteComponent,
45
type Data,
56
type GenericComponent,
@@ -32,7 +33,6 @@ import type { NormalizedPropsOptions } from './componentProps'
3233
import type { ObjectEmitsOptions } from './componentEmits'
3334
import { ErrorCodes, callWithAsyncErrorHandling } from './errorHandling'
3435
import type { DefineComponent } from './apiDefineComponent'
35-
import type { VaporInteropInterface } from './vaporInterop'
3636

3737
export interface App<HostElement = any> {
3838
version: string
@@ -178,6 +178,24 @@ export interface AppConfig extends GenericAppConfig {
178178
isCustomElement?: (tag: string) => boolean
179179
}
180180

181+
/**
182+
* The vapor in vdom implementation is in runtime-vapor/src/vdomInterop.ts
183+
* @internal
184+
*/
185+
export interface VaporInteropInterface {
186+
mount(
187+
vnode: VNode,
188+
container: any,
189+
anchor: any,
190+
parentComponent: ComponentInternalInstance | null,
191+
): GenericComponentInstance // VaporComponentInstance
192+
update(n1: VNode, n2: VNode, shouldUpdate: boolean): void
193+
unmount(vnode: VNode, doRemove?: boolean): void
194+
move(vnode: VNode, container: any, anchor: any): void
195+
vdomMount: (component: ConcreteComponent, props?: any, slots?: any) => any
196+
vdomUnmount: UnmountComponentFn
197+
}
198+
181199
/**
182200
* Minimal app context shared between vdom and vapor
183201
*/
@@ -194,17 +212,9 @@ export interface GenericAppContext {
194212
reload?: () => void
195213

196214
/**
197-
* @internal vapor interop only, for creating vapor components in vdom
215+
* @internal vapor interop only
198216
*/
199217
vapor?: VaporInteropInterface
200-
/**
201-
* @internal vapor interop only, for creating vdom components in vapor
202-
*/
203-
vdomMount?: (component: ConcreteComponent, props?: any, slots?: any) => any
204-
/**
205-
* @internal
206-
*/
207-
vdomUnmount?: UnmountComponentFn
208218
}
209219

210220
export interface AppContext extends GenericAppContext {

packages/runtime-core/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ export { type NormalizedPropsOptions } from './componentProps'
501501
/**
502502
* @internal
503503
*/
504-
export { type VaporInteropInterface } from './vaporInterop'
504+
export { type VaporInteropInterface } from './apiCreateApp'
505505
/**
506506
* @internal
507507
*/

packages/runtime-core/src/renderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ import { isAsyncWrapper } from './apiAsyncComponent'
9696
import { isCompatEnabled } from './compat/compatConfig'
9797
import { DeprecationTypes } from './compat/compatConfig'
9898
import type { TransitionHooks } from './components/BaseTransition'
99-
import type { VaporInteropInterface } from './vaporInterop'
99+
import type { VaporInteropInterface } from './apiCreateApp'
100100

101101
export interface Renderer<HostElement = RendererElement> {
102102
render: RootRenderFunction<HostElement>

packages/runtime-core/src/vaporInterop.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

packages/runtime-vapor/src/component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ export function createComponent(
150150
emptyContext,
151151
): VaporComponentInstance {
152152
// vdom interop enabled and component is not an explicit vapor component
153-
if (appContext.vdomMount && !component.__vapor) {
154-
return appContext.vdomMount(component as any, rawProps, rawSlots)
153+
if (appContext.vapor && !component.__vapor) {
154+
return appContext.vapor.vdomMount(component as any, rawProps, rawSlots)
155155
}
156156

157157
if (
@@ -526,7 +526,7 @@ export function unmountComponent(
526526
instance.children = EMPTY_ARR as any
527527

528528
if (instance.vdomChildren) {
529-
const unmount = instance.appContext.vdomUnmount!
529+
const unmount = instance.appContext.vapor!.vdomUnmount
530530
for (const c of instance.vdomChildren) {
531531
unmount(c, null)
532532
}

packages/runtime-vapor/src/vdomInterop.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ import { extend, remove } from '@vue/shared'
2323
import { type RawProps, rawPropsProxyHandlers } from './componentProps'
2424
import type { RawSlots } from './componentSlots'
2525

26-
const vaporInteropImpl: VaporInteropInterface = {
26+
const vaporInteropImpl: Omit<
27+
VaporInteropInterface,
28+
'vdomMount' | 'vdomUnmount'
29+
> = {
2730
mount(vnode, container, anchor, parentComponent) {
2831
const selfAnchor = (vnode.anchor = document.createComment('vapor'))
2932
container.insertBefore(selfAnchor, anchor)
@@ -114,8 +117,9 @@ function createVDOMComponent(
114117
}
115118

116119
export const vaporInteropPlugin: Plugin = app => {
117-
app._context.vapor = extend(vaporInteropImpl)
118120
const internals = ensureRenderer().internals
119-
app._context.vdomMount = createVDOMComponent.bind(null, internals)
120-
app._context.vdomUnmount = internals.umt
121+
app._context.vapor = extend(vaporInteropImpl, {
122+
vdomMount: createVDOMComponent.bind(null, internals),
123+
vdomUnmount: internals.umt,
124+
})
121125
}

0 commit comments

Comments
 (0)