Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(runtime-vapor): cache delegate event handlers on element #12610

Merged
merged 1 commit into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions packages/runtime-vapor/src/componentMetadata.ts

This file was deleted.

16 changes: 8 additions & 8 deletions packages/runtime-vapor/src/dom/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@ import {
onEffectCleanup,
onScopeDispose,
} from '@vue/reactivity'
import {
MetadataKind,
getMetadata,
recordEventMetadata,
} from '../componentMetadata'
import { queuePostFlushCb } from '@vue/runtime-dom'
import { remove } from '@vue/shared'

export function addEventListener(
el: Element,
Expand Down Expand Up @@ -49,13 +45,17 @@ export type DelegatedHandler = {
}

export function delegate(
el: HTMLElement,
el: any,
event: string,
handlerGetter: () => undefined | ((...args: any[]) => any),
): void {
const handler: DelegatedHandler = eventHandler(handlerGetter)
handler.delegate = true
recordEventMetadata(el, event, handler)

const cacheKey = `$evt${event}`
const handlers: DelegatedHandler[] = el[cacheKey] || (el[cacheKey] = [])
handlers.push(handler)
onScopeDispose(() => remove(handlers, handler))
}

function eventHandler(getter: () => undefined | ((...args: any[]) => any)) {
Expand Down Expand Up @@ -98,7 +98,7 @@ const delegatedEventHandler = (e: Event) => {
},
})
while (node !== null) {
const handlers = getMetadata(node)[MetadataKind.event][e.type]
const handlers = node[`$evt${e.type}`] as DelegatedHandler[]
if (handlers) {
for (const handler of handlers) {
if (handler.delegate && !node.disabled) {
Expand Down
Loading