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,4 +1,4 @@
import { isArray, EMPTY_OBJ } from '@vue/shared'
import { EMPTY_OBJ } from '@vue/shared'
import {
ComponentInternalInstance,
callWithAsyncErrorHandling
@@ -128,25 +128,12 @@ function createInvoker(
// 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