]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor(runtime-vapor): remove public instance
author三咲智子 Kevin Deng <sxzz@sxzz.moe>
Sun, 24 Dec 2023 18:40:31 +0000 (02:40 +0800)
committer三咲智子 Kevin Deng <sxzz@sxzz.moe>
Sun, 24 Dec 2023 18:51:51 +0000 (02:51 +0800)
packages/runtime-vapor/__tests__/apiWatch.spec.ts
packages/runtime-vapor/src/component.ts
packages/runtime-vapor/src/componentPublicInstance.ts [deleted file]
packages/runtime-vapor/src/errorHandling.ts
packages/runtime-vapor/src/render.ts

index 02f88dedb36b335c7e05b948cfd0a20c8d1c1f73..ce8eae5c85f71d69e85866e36ca77e8ae271a821 100644 (file)
@@ -137,7 +137,7 @@ describe('watchEffect and onEffectCleanup', () => {
     }
 
     const instance = render(demo as any, {}, '#host')
-    const { change } = instance.proxy as any
+    const { change } = instance.setupState as any
 
     expect(calls).toEqual(['pre 0', 'sync 0', 'render 0'])
     calls.length = 0
index 914f7beb6ef51e1c4e7a192595002e707ac4e052..240df9d85b94a6f0ee9cca410cf397cf7a828384 100644 (file)
@@ -37,9 +37,6 @@ export interface ComponentInternalInstance {
 
   parent: ComponentInternalInstance | null
 
-  // TODO: type
-  proxy: Data | null
-
   // state
   props: Data
   setupState: Data
@@ -144,7 +141,6 @@ export const createComponentInstance = (
     // resolved props and emits options
     propsOptions: normalizePropsOptions(component),
     // emitsOptions: normalizeEmitsOptions(type, appContext), // TODO:
-    proxy: null,
 
     // state
     props: EMPTY_OBJ,
diff --git a/packages/runtime-vapor/src/componentPublicInstance.ts b/packages/runtime-vapor/src/componentPublicInstance.ts
deleted file mode 100644 (file)
index 8bfacf9..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-import { hasOwn } from '@vue/shared'
-import { type ComponentInternalInstance } from './component'
-
-export interface ComponentRenderContext {
-  [key: string]: any
-  _: ComponentInternalInstance
-}
-
-export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
-  get({ _: instance }: ComponentRenderContext, key: string) {
-    let normalizedProps
-    const { setupState, props } = instance
-    if (hasOwn(setupState, key)) {
-      return setupState[key]
-    } else if (
-      (normalizedProps = instance.propsOptions[0]) &&
-      hasOwn(normalizedProps, key)
-    ) {
-      return props![key]
-    }
-  },
-}
index d7449f3b4c41126e7078302540937623d4d5b6b3..6f8bcb5c6ecf7ebb2db1a7511488b5b6a84758d2 100644 (file)
@@ -113,8 +113,6 @@ export function handleError(
 ) {
   if (instance) {
     let cur = instance.parent
-    // the exposed instance is the render proxy to keep it consistent with 2.x
-    const exposedInstance = ('proxy' in instance && instance.proxy) || null
     // in production the hook receives only the error code
     const errorInfo = __DEV__
       ? ErrorTypeStrings[type]
@@ -123,9 +121,7 @@ export function handleError(
       const errorCapturedHooks = 'ec' in cur ? cur.ec : null
       if (errorCapturedHooks) {
         for (let i = 0; i < errorCapturedHooks.length; i++) {
-          if (
-            errorCapturedHooks[i](err, exposedInstance, errorInfo) === false
-          ) {
+          if (errorCapturedHooks[i](err, instance, errorInfo) === false) {
             return
           }
         }
index 1f53978e81d1b507a83d6723a22d6573f821e7fc..dd6c2b2dff007d08e01b60afec69df399dce824b 100644 (file)
@@ -10,7 +10,6 @@ import {
 import { initProps } from './componentProps'
 import { invokeDirectiveHook } from './directive'
 import { insert, remove } from './dom'
-import { PublicInstanceProxyHandlers } from './componentPublicInstance'
 
 export type Block = Node | Fragment | Block[]
 export type ParentBlock = ParentNode | Node[]
@@ -51,9 +50,6 @@ export function mountComponent(
 
     const setupFn =
       typeof component === 'function' ? component : component.setup
-    instance.proxy = markRaw(
-      new Proxy({ _: instance }, PublicInstanceProxyHandlers),
-    )
     const state = setupFn && setupFn(props, ctx)
     let block: Block | null = null
     if (state && '__isScriptSetup' in state) {
@@ -61,7 +57,7 @@ export function mountComponent(
       const currentlyRenderingActivity = isRenderingActivity
       isRenderingActivity = true
       try {
-        block = component.render(instance.proxy)
+        block = component.render(instance.setupState)
       } finally {
         isRenderingActivity = currentlyRenderingActivity
       }