isFunction,
capitalize,
NOOP,
- isArray,
isObject,
NO,
makeMap,
const props = instance.vnode.props || EMPTY_OBJ
const handler = props[`on${event}`] || props[`on${capitalize(event)}`]
if (handler) {
- if (isArray(handler)) {
- for (let i = 0; i < handler.length; i++) {
- callWithAsyncErrorHandling(
- handler[i],
- instance,
- ErrorCodes.COMPONENT_EVENT_HANDLER,
- args
- )
- }
- } else {
- callWithAsyncErrorHandling(
- handler,
- instance,
- ErrorCodes.COMPONENT_EVENT_HANDLER,
- args
- )
- }
+ callWithAsyncErrorHandling(
+ handler,
+ instance,
+ ErrorCodes.COMPONENT_EVENT_HANDLER,
+ args
+ )
}
}
}
*/
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'
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
+ ])
}
import { VNode } from './vnode'
import { ComponentInternalInstance, LifecycleHooks } from './component'
import { warn, pushWarningContext, popWarningContext } from './warning'
-import { isPromise } from '@vue/shared'
+import { isPromise, isFunction } from '@vue/shared'
// contexts where user provided function may be executed, in addition to
// lifecycle hooks.
}
export function callWithAsyncErrorHandling(
- fn: Function,
+ fn: Function | Function[],
instance: ComponentInternalInstance | null,
type: ErrorTypes,
args?: any[]
) {
- const res = callWithErrorHandling(fn, instance, type, args)
- if (res != null && !res._isVue && isPromise(res)) {
- res.catch((err: Error) => {
- handleError(err, instance, type)
- })
+ if (isFunction(fn)) {
+ const res = callWithErrorHandling(fn, instance, type, args)
+ if (res != null && !res._isVue && isPromise(res)) {
+ res.catch((err: Error) => {
+ handleError(err, instance, type)
+ })
+ }
+ return res
+ }
+
+ for (let i = 0; i < fn.length; i++) {
+ callWithAsyncErrorHandling(fn[i], instance, type, args)
}
- return res
}
export function handleError(
-import { isArray, EMPTY_OBJ } from '@vue/shared'
+import { EMPTY_OBJ } from '@vue/shared'
import {
ComponentInternalInstance,
callWithAsyncErrorHandling
// and the handler would only fire if the event passed to it was fired
// AFTER it was attached.
if (e.timeStamp >= invoker.lastUpdated - 1) {
- const args = [e]
- const value = invoker.value
- if (isArray(value)) {
- for (let i = 0; i < value.length; i++) {
- callWithAsyncErrorHandling(
- value[i],
- instance,
- ErrorCodes.NATIVE_EVENT_HANDLER,
- args
- )
- }
- } else {
- callWithAsyncErrorHandling(
- value,
- instance,
- ErrorCodes.NATIVE_EVENT_HANDLER,
- args
- )
- }
+ callWithAsyncErrorHandling(
+ invoker.value,
+ instance,
+ ErrorCodes.NATIVE_EVENT_HANDLER,
+ [e]
+ )
}
}
invoker.value = initialValue