fix(runtime-dom/v-on): support event.stopImmediatePropagation on multiple listeners
close #916
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { EMPTY_OBJ } from '@vue/shared'
|
||||
import { EMPTY_OBJ, isArray } from '@vue/shared'
|
||||
import {
|
||||
ComponentInternalInstance,
|
||||
callWithAsyncErrorHandling
|
||||
@@ -130,7 +130,7 @@ function createInvoker(
|
||||
// AFTER it was attached.
|
||||
if (e.timeStamp >= invoker.lastUpdated - 1) {
|
||||
callWithAsyncErrorHandling(
|
||||
invoker.value,
|
||||
patchStopImmediatePropagation(e, invoker.value),
|
||||
instance,
|
||||
ErrorCodes.NATIVE_EVENT_HANDLER,
|
||||
[e]
|
||||
@@ -142,3 +142,19 @@ function createInvoker(
|
||||
invoker.lastUpdated = getNow()
|
||||
return invoker
|
||||
}
|
||||
|
||||
function patchStopImmediatePropagation(
|
||||
e: Event,
|
||||
value: EventValue
|
||||
): EventValue {
|
||||
if (isArray(value)) {
|
||||
const originalStop = e.stopImmediatePropagation
|
||||
e.stopImmediatePropagation = () => {
|
||||
originalStop.call(e)
|
||||
;(e as any)._stopped = true
|
||||
}
|
||||
return value.map(fn => (e: Event) => !(e as any)._stopped && fn(e))
|
||||
} else {
|
||||
return value
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user