(
el: Element & { [veiKey]?: Record<string, Invoker | undefined> },
rawName: string,
prevValue: EventValue | null,
nextValue: EventValue | unknown,
instance: ComponentInternalInstance | null = null,
)
| 34 | const veiKey: unique symbol = Symbol('_vei') |
| 35 | |
| 36 | export function patchEvent( |
| 37 | el: Element & { [veiKey]?: Record<string, Invoker | undefined> }, |
| 38 | rawName: string, |
| 39 | prevValue: EventValue | null, |
| 40 | nextValue: EventValue | unknown, |
| 41 | instance: ComponentInternalInstance | null = null, |
| 42 | ): void { |
| 43 | // vei = vue event invokers |
| 44 | const invokers = el[veiKey] || (el[veiKey] = {}) |
| 45 | const existingInvoker = invokers[rawName] |
| 46 | if (nextValue && existingInvoker) { |
| 47 | // patch |
| 48 | existingInvoker.value = __DEV__ |
| 49 | ? sanitizeEventValue(nextValue, rawName) |
| 50 | : (nextValue as EventValue) |
| 51 | } else { |
| 52 | const [name, options] = parseName(rawName) |
| 53 | if (nextValue) { |
| 54 | // add |
| 55 | const invoker = (invokers[rawName] = createInvoker( |
| 56 | __DEV__ |
| 57 | ? sanitizeEventValue(nextValue, rawName) |
| 58 | : (nextValue as EventValue), |
| 59 | instance, |
| 60 | )) |
| 61 | addEventListener(el, name, invoker, options) |
| 62 | } else if (existingInvoker) { |
| 63 | // remove |
| 64 | removeEventListener(el, name, existingInvoker, options) |
| 65 | invokers[rawName] = undefined |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | const optionsModifierRE = /(Once|Passive|Capture)$/ |
| 71 | const optionsModifierEventRE = /^on:?(?:Once|Passive|Capture)$/ |
no test coverage detected