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

Function invoker

packages/runtime-dom/src/modules/events.ts:99–148  ·  view source on GitHub ↗
(e: Event & { _vts?: number })

Source from the content-addressed store, hash-verified

97 instance: ComponentInternalInstance | null,
98) {
99 const invoker: Invoker = (e: Event & { _vts?: number }) => {
100 // async edge case vuejs/vue#6566
101 // inner click event triggers patch, event handler
102 // attached to outer element during patch, and triggered again. This
103 // happens because browsers fire microtask ticks between event propagation.
104 // this no longer happens for templates in Vue 3, but could still be
105 // theoretically possible for hand-written render functions.
106 // the solution: we save the timestamp when a handler is attached,
107 // and also attach the timestamp to any event that was handled by vue
108 // for the first time (to avoid inconsistent event timestamp implementations
109 // or events fired from iframes, e.g. #2513)
110 // The handler would only fire if the event passed to it was fired
111 // AFTER it was attached.
112 if (!e._vts) {
113 e._vts = Date.now()
114 } else if (e._vts <= invoker.attached) {
115 return
116 }
117 const value = invoker.value
118 if (isArray(value)) {
119 const originalStop = e.stopImmediatePropagation
120 e.stopImmediatePropagation = () => {
121 originalStop.call(e)
122 ;(e as any)._stopped = true
123 }
124 const handlers = value.slice()
125 const args = [e]
126 for (let i = 0; i < handlers.length; i++) {
127 if ((e as any)._stopped) {
128 break
129 }
130 const handler = handlers[i]
131 if (handler) {
132 callWithAsyncErrorHandling(
133 handler,
134 instance,
135 ErrorCodes.NATIVE_EVENT_HANDLER,
136 args,
137 )
138 }
139 }
140 } else {
141 callWithAsyncErrorHandling(
142 value,
143 instance,
144 ErrorCodes.NATIVE_EVENT_HANDLER,
145 [e],
146 )
147 }
148 }
149 invoker.value = initialValue
150 invoker.attached = getNow()
151 return invoker

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected