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

@@ -1,7 +1,7 @@
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.
@@ -66,18 +66,24 @@ export function callWithErrorHandling(
}
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(