Skip to content

Commit 1385e4a

Browse files
committed
feat(runtime-vapor): support setup fn and render fn co-usage
1 parent 5ee8913 commit 1385e4a

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

packages/runtime-vapor/src/component.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ export function setupComponent(
412412
)
413413
}
414414
} else {
415-
handleSetupResult(setupResult, component, instance, setupFn)
415+
handleSetupResult(setupResult, component, instance)
416416
}
417417

418418
setActiveSub(prevSub)
@@ -802,12 +802,7 @@ export function mountComponent(
802802
) {
803803
const component = instance.type
804804
instance.suspense.registerDep(instance, setupResult => {
805-
handleSetupResult(
806-
setupResult,
807-
component,
808-
instance,
809-
isFunction(component) ? component : component.setup,
810-
)
805+
handleSetupResult(setupResult, component, instance)
811806
mountComponent(instance, parent, anchor)
812807
})
813808
return
@@ -952,7 +947,6 @@ function handleSetupResult(
952947
setupResult: any,
953948
component: VaporComponent,
954949
instance: VaporComponentInstance,
955-
setupFn: VaporSetupFn | undefined,
956950
) {
957951
if (__DEV__) {
958952
pushWarningContext(instance)
@@ -980,12 +974,22 @@ function handleSetupResult(
980974
} else {
981975
// component has a render function but no setup function
982976
// (typically components with only a template and no state)
983-
if (!setupFn && component.render) {
984-
instance.block = callWithErrorHandling(
985-
component.render,
986-
instance,
987-
ErrorCodes.RENDER_FUNCTION,
988-
)
977+
// support setup fn and render fn co-usage for defineComponent expose
978+
if (!isBlock(setupResult) && component.render) {
979+
instance.setupState = setupResult
980+
instance.block =
981+
callWithErrorHandling(
982+
component.render,
983+
instance,
984+
ErrorCodes.RENDER_FUNCTION,
985+
[
986+
instance.setupState,
987+
instance.props,
988+
instance.emit,
989+
instance.attrs,
990+
instance.slots,
991+
],
992+
) || []
989993
} else {
990994
// in prod result can only be block
991995
instance.block = setupResult as Block

0 commit comments

Comments
 (0)