-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
feat: add svelte/events package and export on function #11912
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
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create_event
calls addEventListener
, it's not using event delegation. What am I missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see. The documentation is a bit misleading in that case, will rewrite it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good.
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/events
package, which exports theon
function. The function should be used in place of imperatively doingaddEventListener
, as it co-ordinates the event handling with Svelte's internal event delegation system.