]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor: adjust vapor/vdom interop
authorEvan You <evan@vuejs.org>
Wed, 5 Feb 2025 06:16:39 +0000 (14:16 +0800)
committerEvan You <evan@vuejs.org>
Wed, 5 Feb 2025 06:16:39 +0000 (14:16 +0800)
packages/runtime-core/src/apiCreateApp.ts
packages/runtime-core/src/index.ts
packages/runtime-core/src/renderer.ts
packages/runtime-core/src/vaporInterop.ts [deleted file]
packages/runtime-vapor/src/component.ts
packages/runtime-vapor/src/vdomInterop.ts

index 80532e9ed271bf57db20e55b77932cfe630b203b..66dac629181dc69910af7e21da6d6b5a4eb16b33 100644 (file)
@@ -1,5 +1,6 @@
 import {
   type Component,
+  type ComponentInternalInstance,
   type ConcreteComponent,
   type Data,
   type GenericComponent,
@@ -32,7 +33,6 @@ import type { NormalizedPropsOptions } from './componentProps'
 import type { ObjectEmitsOptions } from './componentEmits'
 import { ErrorCodes, callWithAsyncErrorHandling } from './errorHandling'
 import type { DefineComponent } from './apiDefineComponent'
-import type { VaporInteropInterface } from './vaporInterop'
 
 export interface App<HostElement = any> {
   version: string
@@ -178,6 +178,24 @@ export interface AppConfig extends GenericAppConfig {
   isCustomElement?: (tag: string) => boolean
 }
 
+/**
+ * The vapor in vdom implementation is in runtime-vapor/src/vdomInterop.ts
+ * @internal
+ */
+export interface VaporInteropInterface {
+  mount(
+    vnode: VNode,
+    container: any,
+    anchor: any,
+    parentComponent: ComponentInternalInstance | null,
+  ): GenericComponentInstance // VaporComponentInstance
+  update(n1: VNode, n2: VNode, shouldUpdate: boolean): void
+  unmount(vnode: VNode, doRemove?: boolean): void
+  move(vnode: VNode, container: any, anchor: any): void
+  vdomMount: (component: ConcreteComponent, props?: any, slots?: any) => any
+  vdomUnmount: UnmountComponentFn
+}
+
 /**
  * Minimal app context shared between vdom and vapor
  */
@@ -194,17 +212,9 @@ export interface GenericAppContext {
   reload?: () => void
 
   /**
-   * @internal vapor interop only, for creating vapor components in vdom
+   * @internal vapor interop only
    */
   vapor?: VaporInteropInterface
-  /**
-   * @internal vapor interop only, for creating vdom components in vapor
-   */
-  vdomMount?: (component: ConcreteComponent, props?: any, slots?: any) => any
-  /**
-   * @internal
-   */
-  vdomUnmount?: UnmountComponentFn
 }
 
 export interface AppContext extends GenericAppContext {
index 36614206b22abe65bb605fb6b0c47136b9f012b7..dee3010262dd885684b7b3aea4b8cebf237c5d8d 100644 (file)
@@ -501,7 +501,7 @@ export { type NormalizedPropsOptions } from './componentProps'
 /**
  * @internal
  */
-export { type VaporInteropInterface } from './vaporInterop'
+export { type VaporInteropInterface } from './apiCreateApp'
 /**
  * @internal
  */
index 08e6180818715de21fc5b3dd7c6f072d7da6e718..b78f789ee6142af2a8dffd42c79c0d50defd2088 100644 (file)
@@ -96,7 +96,7 @@ import { isAsyncWrapper } from './apiAsyncComponent'
 import { isCompatEnabled } from './compat/compatConfig'
 import { DeprecationTypes } from './compat/compatConfig'
 import type { TransitionHooks } from './components/BaseTransition'
-import type { VaporInteropInterface } from './vaporInterop'
+import type { VaporInteropInterface } from './apiCreateApp'
 
 export interface Renderer<HostElement = RendererElement> {
   render: RootRenderFunction<HostElement>
diff --git a/packages/runtime-core/src/vaporInterop.ts b/packages/runtime-core/src/vaporInterop.ts
deleted file mode 100644 (file)
index a0c8eb9..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-import type {
-  ComponentInternalInstance,
-  GenericComponentInstance,
-} from './component'
-import type { VNode } from './vnode'
-
-/**
- * The vapor in vdom implementation is in runtime-vapor/src/vdomInterop.ts
- * @internal
- */
-export interface VaporInteropInterface {
-  mount(
-    vnode: VNode,
-    container: any,
-    anchor: any,
-    parentComponent: ComponentInternalInstance | null,
-  ): GenericComponentInstance // VaporComponentInstance
-  update(n1: VNode, n2: VNode, shouldUpdate: boolean): void
-  unmount(vnode: VNode, doRemove?: boolean): void
-  move(vnode: VNode, container: any, anchor: any): void
-}
index bcf101cc86653d8fecc5abc95db00fe87e6d71d4..b2207f7d48a409a23db7b1fcea1120fab65b8896 100644 (file)
@@ -150,8 +150,8 @@ export function createComponent(
     emptyContext,
 ): VaporComponentInstance {
   // vdom interop enabled and component is not an explicit vapor component
-  if (appContext.vdomMount && !component.__vapor) {
-    return appContext.vdomMount(component as any, rawProps, rawSlots)
+  if (appContext.vapor && !component.__vapor) {
+    return appContext.vapor.vdomMount(component as any, rawProps, rawSlots)
   }
 
   if (
@@ -526,7 +526,7 @@ export function unmountComponent(
     instance.children = EMPTY_ARR as any
 
     if (instance.vdomChildren) {
-      const unmount = instance.appContext.vdomUnmount!
+      const unmount = instance.appContext.vapor!.vdomUnmount
       for (const c of instance.vdomChildren) {
         unmount(c, null)
       }
index 040239e23338d52a4f3dc764db5b596971672901..7b9ee19cbfe0385fa8f0c170f901eaf73403f052 100644 (file)
@@ -23,7 +23,10 @@ import { extend, remove } from '@vue/shared'
 import { type RawProps, rawPropsProxyHandlers } from './componentProps'
 import type { RawSlots } from './componentSlots'
 
-const vaporInteropImpl: VaporInteropInterface = {
+const vaporInteropImpl: Omit<
+  VaporInteropInterface,
+  'vdomMount' | 'vdomUnmount'
+> = {
   mount(vnode, container, anchor, parentComponent) {
     const selfAnchor = (vnode.anchor = document.createComment('vapor'))
     container.insertBefore(selfAnchor, anchor)
@@ -114,8 +117,9 @@ function createVDOMComponent(
 }
 
 export const vaporInteropPlugin: Plugin = app => {
-  app._context.vapor = extend(vaporInteropImpl)
   const internals = ensureRenderer().internals
-  app._context.vdomMount = createVDOMComponent.bind(null, internals)
-  app._context.vdomUnmount = internals.umt
+  app._context.vapor = extend(vaporInteropImpl, {
+    vdomMount: createVDOMComponent.bind(null, internals),
+    vdomUnmount: internals.umt,
+  })
 }