|
1 | 1 | import { proxyRefs } from '@vue/reactivity'
|
2 |
| -import { invokeArrayFns, isArray, isFunction, isObject } from '@vue/shared' |
3 |
| -import { |
4 |
| - type ComponentInternalInstance, |
5 |
| - setCurrentInstance, |
6 |
| - unsetCurrentInstance, |
7 |
| -} from './component' |
8 |
| -import { invokeDirectiveHook } from './directives' |
| 2 | +import { isArray, isFunction, isObject } from '@vue/shared' |
| 3 | +import { type ComponentInternalInstance, setCurrentInstance } from './component' |
9 | 4 | import { insert, querySelector, remove } from './dom/element'
|
10 | 5 | import { flushPostFlushCbs, queuePostRenderEffect } from './scheduler'
|
| 6 | +import { VaporLifecycleHooks, invokeHook } from './apiLifecycle' |
11 | 7 |
|
12 | 8 | export const fragmentKey = Symbol(__DEV__ ? `fragmentKey` : ``)
|
13 | 9 |
|
@@ -71,39 +67,32 @@ function mountComponent(
|
71 | 67 | }
|
72 | 68 | return (instance.block = block)
|
73 | 69 | })!
|
74 |
| - const { bm, m } = instance |
| 70 | + reset() |
75 | 71 |
|
76 |
| - // hook: beforeMount |
77 |
| - bm && invokeArrayFns(bm) |
78 |
| - invokeDirectiveHook(instance, 'beforeMount') |
| 72 | + invokeHook(instance, VaporLifecycleHooks.BEFORE_MOUNT) |
79 | 73 |
|
80 | 74 | insert(block, instance.container)
|
81 | 75 | instance.isMounted = true
|
82 | 76 |
|
83 |
| - // hook: mounted |
84 | 77 | queuePostRenderEffect(() => {
|
85 |
| - invokeDirectiveHook(instance, 'mounted') |
86 |
| - m && invokeArrayFns(m) |
| 78 | + invokeHook(instance, VaporLifecycleHooks.MOUNTED) |
87 | 79 | })
|
88 |
| - reset() |
89 | 80 |
|
90 | 81 | return instance
|
91 | 82 | }
|
92 | 83 |
|
93 | 84 | export function unmountComponent(instance: ComponentInternalInstance) {
|
94 |
| - const { container, block, scope, um, bum } = instance |
| 85 | + const { container, block, scope } = instance |
95 | 86 |
|
96 |
| - // hook: beforeUnmount |
97 |
| - bum && invokeArrayFns(bum) |
98 |
| - invokeDirectiveHook(instance, 'beforeUnmount') |
| 87 | + invokeHook(instance, VaporLifecycleHooks.BEFORE_UNMOUNT) |
99 | 88 |
|
100 | 89 | scope.stop()
|
101 |
| - block && remove(block, container) |
102 |
| - instance.isMounted = false |
103 |
| - instance.isUnmounted = true |
104 | 90 |
|
105 |
| - // hook: unmounted |
106 |
| - invokeDirectiveHook(instance, 'unmounted') |
107 |
| - um && invokeArrayFns(um) |
108 |
| - unsetCurrentInstance() |
| 91 | + queuePostRenderEffect(() => { |
| 92 | + invokeHook(instance, VaporLifecycleHooks.UNMOUNTED) |
| 93 | + instance.isMounted = false |
| 94 | + instance.isUnmounted = true |
| 95 | + }) |
| 96 | + |
| 97 | + block && remove(block, container) |
109 | 98 | }
|
0 commit comments