Skip to content

Commit

Permalink
refactor(runtime-vapor): remove public instance
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Dec 24, 2023
1 parent 3d4bc01 commit efc32b7
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 37 deletions.
2 changes: 1 addition & 1 deletion packages/runtime-vapor/__tests__/apiWatch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions packages/runtime-vapor/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ export interface ComponentInternalInstance {

parent: ComponentInternalInstance | null

// TODO: type
proxy: Data | null

// state
props: Data
setupState: Data
Expand Down Expand Up @@ -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,
Expand Down
22 changes: 0 additions & 22 deletions packages/runtime-vapor/src/componentPublicInstance.ts

This file was deleted.

6 changes: 1 addition & 5 deletions packages/runtime-vapor/src/errorHandling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
}
}
Expand Down
6 changes: 1 addition & 5 deletions packages/runtime-vapor/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down Expand Up @@ -51,17 +50,14 @@ 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) {
instance.setupState = proxyRefs(state)
const currentlyRenderingActivity = isRenderingActivity
isRenderingActivity = true
try {
block = component.render(instance.proxy)
block = component.render(instance.setupState)
} finally {
isRenderingActivity = currentlyRenderingActivity
}
Expand Down

0 comments on commit efc32b7

Please sign in to comment.