Skip to content

Commit 3421a79

Browse files
authored
chore(type): lifecycle hooks return type (#776)
Co-authored-by: webfansplz <>
1 parent ae81056 commit 3421a79

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/apis/lifecycle.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ const genName = (name: string) => `on${name[0].toUpperCase() + name.slice(1)}`
1111
function createLifeCycle(lifeCyclehook: string) {
1212
return (callback: Function) => {
1313
const vm = currentVMInFn(genName(lifeCyclehook))
14-
if (vm) {
15-
injectHookOption(getVueConstructor(), vm, lifeCyclehook, callback)
16-
}
14+
return (
15+
vm && injectHookOption(getVueConstructor(), vm, lifeCyclehook, callback)
16+
)
1717
}
1818
}
1919

@@ -25,10 +25,12 @@ function injectHookOption(
2525
) {
2626
const options = vm.$options as Record<string, unknown>
2727
const mergeFn = Vue.config.optionMergeStrategies[hook]
28-
options[hook] = mergeFn(options[hook], wrapHookCall(vm, val))
28+
const wrappedHook = wrapHookCall(vm, val)
29+
options[hook] = mergeFn(options[hook], wrappedHook)
30+
return wrappedHook
2931
}
3032

31-
function wrapHookCall(vm: ComponentInstance, fn: Function) {
33+
function wrapHookCall(vm: ComponentInstance, fn: Function): Function {
3234
return (...args: any) => {
3335
let preVm = getCurrentInstance()?.proxy
3436
setCurrentInstance(vm)

0 commit comments

Comments
 (0)