mirror of
https://gitee.com/vuejs/vue.git
synced 2024-12-03 12:38:24 +08:00
refactor: simplify mergeVNodeHook usage
This commit is contained in:
parent
664cee6377
commit
53b77f8054
@ -1,9 +1,13 @@
|
||||
/* @flow */
|
||||
|
||||
import VNode from '../vnode'
|
||||
import { createFnInvoker } from './update-listeners'
|
||||
import { remove, isDef, isUndef, isTrue } from 'shared/util'
|
||||
|
||||
export function mergeVNodeHook (def: Object, hookKey: string, hook: Function) {
|
||||
if (def instanceof VNode) {
|
||||
def = def.data.hook || (def.data.hook = {})
|
||||
}
|
||||
let invoker
|
||||
const oldHook = def[hookKey]
|
||||
|
||||
|
@ -54,14 +54,14 @@ function _update (oldVnode, vnode) {
|
||||
}
|
||||
}
|
||||
if (isCreate) {
|
||||
mergeVNodeHook(vnode.data.hook || (vnode.data.hook = {}), 'insert', callInsert)
|
||||
mergeVNodeHook(vnode, 'insert', callInsert)
|
||||
} else {
|
||||
callInsert()
|
||||
}
|
||||
}
|
||||
|
||||
if (dirsWithPostpatch.length) {
|
||||
mergeVNodeHook(vnode.data.hook || (vnode.data.hook = {}), 'postpatch', () => {
|
||||
mergeVNodeHook(vnode, 'postpatch', () => {
|
||||
for (let i = 0; i < dirsWithPostpatch.length; i++) {
|
||||
callHook(dirsWithPostpatch[i], 'componentUpdated', vnode, oldVnode)
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ const directive = {
|
||||
if (vnode.tag === 'select') {
|
||||
// #6903
|
||||
if (oldVnode.elm && !oldVnode.elm._vOptions) {
|
||||
mergeVNodeHook(vnode.data.hook || (vnode.data.hook = {}), 'postpatch', () => {
|
||||
mergeVNodeHook(vnode, 'postpatch', () => {
|
||||
directive.componentUpdated(el, binding, vnode)
|
||||
})
|
||||
} else {
|
||||
|
@ -130,7 +130,7 @@ export function enter (vnode: VNodeWithData, toggleDisplay: ?() => void) {
|
||||
|
||||
if (!vnode.data.show) {
|
||||
// remove pending leave element on enter by injecting an insert hook
|
||||
mergeVNodeHook(vnode.data.hook || (vnode.data.hook = {}), 'insert', () => {
|
||||
mergeVNodeHook(vnode, 'insert', () => {
|
||||
const parent = el.parentNode
|
||||
const pendingNode = parent && parent._pending && parent._pending[vnode.key]
|
||||
if (pendingNode &&
|
||||
|
Loading…
Reference in New Issue
Block a user