wip: beforeXXX hooks

This commit is contained in:
Evan You 2019-05-29 10:47:09 +08:00
parent eac8a4baa3
commit 3f281d5ea6

View File

@ -365,6 +365,7 @@ export function createRenderer(options: RendererOptions) {
instance, instance,
needsSetup needsSetup
)) ))
// beforeMount hook
if (instance.bm !== null) { if (instance.bm !== null) {
invokeHooks(instance.bm) invokeHooks(instance.bm)
} }
@ -384,6 +385,10 @@ export function createRenderer(options: RendererOptions) {
} }
const prevTree = instance.subTree const prevTree = instance.subTree
const nextTree = (instance.subTree = renderComponentRoot(instance)) const nextTree = (instance.subTree = renderComponentRoot(instance))
// beforeUpdate hook
if (instance.bu !== null) {
invokeHooks(instance.bu)
}
patch( patch(
prevTree, prevTree,
nextTree, nextTree,
@ -678,9 +683,14 @@ export function createRenderer(options: RendererOptions) {
function unmount(vnode: VNode, doRemove?: boolean) { function unmount(vnode: VNode, doRemove?: boolean) {
const instance = vnode.component const instance = vnode.component
if (instance != null) { if (instance != null) {
// beforeUnmount hook
if (instance.bum !== null) {
invokeHooks(instance.bum)
}
// TODO teardown component // TODO teardown component
stop(instance.update) stop(instance.update)
unmount(instance.subTree, doRemove) unmount(instance.subTree, doRemove)
// unmounted hook
if (instance.um !== null) { if (instance.um !== null) {
queuePostFlushCb(instance.um) queuePostFlushCb(instance.um)
} }