|
1 | 1 | import { invokeArrayFns } from '@vue/shared' |
2 | 2 | import type { VaporLifecycleHooks } from './apiLifecycle' |
3 | 3 | import { type ComponentInternalInstance, setCurrentInstance } from './component' |
4 | | -import { queuePostRenderEffect } from './scheduler' |
| 4 | +import { queuePostFlushCb } from './scheduler' |
5 | 5 | import { type DirectiveHookName, invokeDirectiveHook } from './directives' |
6 | 6 |
|
7 | 7 | export function invokeLifecycle( |
8 | 8 | instance: ComponentInternalInstance, |
9 | 9 | lifecycle: VaporLifecycleHooks, |
10 | 10 | directive: DirectiveHookName, |
| 11 | + cb?: (instance: ComponentInternalInstance) => void, |
11 | 12 | post?: boolean, |
12 | 13 | ) { |
13 | 14 | invokeArrayFns(post ? [invokeSub, invokeCurrent] : [invokeCurrent, invokeSub]) |
14 | 15 |
|
15 | 16 | function invokeCurrent() { |
| 17 | + cb && cb(instance) |
16 | 18 | const hooks = instance[lifecycle] |
17 | 19 | if (hooks) { |
18 | 20 | const fn = () => { |
19 | 21 | const reset = setCurrentInstance(instance) |
20 | 22 | instance.scope.run(() => invokeArrayFns(hooks)) |
21 | 23 | reset() |
22 | 24 | } |
23 | | - post ? queuePostRenderEffect(fn) : fn() |
| 25 | + post ? queuePostFlushCb(fn) : fn() |
24 | 26 | } |
25 | 27 |
|
26 | 28 | invokeDirectiveHook(instance, directive) |
27 | 29 | } |
28 | 30 |
|
29 | 31 | function invokeSub() { |
30 | 32 | instance.comps.forEach(comp => |
31 | | - invokeLifecycle(comp, lifecycle, directive, post), |
| 33 | + invokeLifecycle(comp, lifecycle, directive, cb, post), |
32 | 34 | ) |
33 | 35 | } |
34 | 36 | } |
0 commit comments