MCPcopy
hub / github.com/vuejs/core / patchEvent

Function patchEvent

packages/runtime-dom/src/modules/events.ts:36–68  ·  view source on GitHub ↗
(
  el: Element & { [veiKey]?: Record<string, Invoker | undefined> },
  rawName: string,
  prevValue: EventValue | null,
  nextValue: EventValue | unknown,
  instance: ComponentInternalInstance | null = null,
)

Source from the content-addressed store, hash-verified

34const veiKey: unique symbol = Symbol('_vei')
35
36export 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
70const optionsModifierRE = /(Once|Passive|Capture)$/
71const optionsModifierEventRE = /^on:?(?:Once|Passive|Capture)$/

Callers 2

patchPropFunction · 0.90
vOn.spec.tsFile · 0.90

Calls 5

sanitizeEventValueFunction · 0.85
parseNameFunction · 0.85
createInvokerFunction · 0.85
addEventListenerFunction · 0.85
removeEventListenerFunction · 0.85

Tested by

no test coverage detected