refactor(errorHandlling): handle array in callWithAsyncErrorHandling (#332)

This commit is contained in:
Jooger
2019-10-22 01:59:10 +08:00
committed by Evan You
parent 74d8c5919d
commit 67eb29f63b
4 changed files with 32 additions and 60 deletions

View File

@@ -12,7 +12,7 @@ return withDirectives(h(comp), [
*/
import { VNode } from './vnode'
import { isArray, isFunction, EMPTY_OBJ, makeMap } from '@vue/shared'
import { isFunction, EMPTY_OBJ, makeMap } from '@vue/shared'
import { warn } from './warning'
import { ComponentInternalInstance } from './component'
import { currentRenderingInstance } from './componentRenderUtils'
@@ -140,17 +140,8 @@ export function invokeDirectiveHook(
vnode: VNode,
prevVNode: VNode | null = null
) {
const args = [vnode, prevVNode]
if (isArray(hook)) {
for (let i = 0; i < hook.length; i++) {
callWithAsyncErrorHandling(
hook[i],
instance,
ErrorCodes.DIRECTIVE_HOOK,
args
)
}
} else if (isFunction(hook)) {
callWithAsyncErrorHandling(hook, instance, ErrorCodes.DIRECTIVE_HOOK, args)
}
callWithAsyncErrorHandling(hook, instance, ErrorCodes.DIRECTIVE_HOOK, [
vnode,
prevVNode
])
}