feat: add svelte/events package and export on function#11912
feat: add svelte/events package and export on function#11912Rich-Harris merged 15 commits intomainfrom
Conversation
🦋 Changeset detectedLatest commit: 38dbd78 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
sites/svelte-5-preview/src/routes/docs/content/01-api/05-imports.md
Outdated
Show resolved
Hide resolved
sites/svelte-5-preview/src/routes/docs/content/01-api/05-imports.md
Outdated
Show resolved
Hide resolved
sites/svelte-5-preview/src/routes/docs/content/01-api/05-imports.md
Outdated
Show resolved
Hide resolved
| * @param {AddEventListenerOptions} [options] | ||
| */ | ||
| export function attach(dom, event_name, handler, options = {}) { | ||
| var target_handler = create_event(event_name, dom, handler, options); |
There was a problem hiding this comment.
create_event calls addEventListener, it's not using event delegation. What am I missing?
There was a problem hiding this comment.
It uses the target function which ensures any delegated events run as expected, whilst still attaching the event to the target manually.
There was a problem hiding this comment.
Ah, I see. The documentation is a bit misleading in that case, will rewrite it
|
Wait so we should not use addEventListener at all now? What about non svelte libraries? |
|
This is only relevant in edge cases where you rely on the elements getting invoked in the right order or when calling |
|
Thanks for clarification! |
This PR introduces the
svelte/eventspackage, which exports theonfunction. The function should be used in place of imperatively doingaddEventListener, as it co-ordinates the event handling with Svelte's internal event delegation system.