From 6223a7e87e018a7a63cc703c095be1f448b82d42 Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Thu, 25 Jul 2024 10:35:18 +0200 Subject: [PATCH] docs: event delegation tweaks (#12597) closes #11317 --- documentation/docs/02-template-syntax/02-basic-markup.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/documentation/docs/02-template-syntax/02-basic-markup.md b/documentation/docs/02-template-syntax/02-basic-markup.md index 9a002bf5a7..a97f8b84e6 100644 --- a/documentation/docs/02-template-syntax/02-basic-markup.md +++ b/documentation/docs/02-template-syntax/02-basic-markup.md @@ -110,14 +110,16 @@ Because events are just attributes, the same rules as for attributes apply: - you can spread them: `` - component events are just (callback) properties and don't need a separate concept +Timing-wise, event attributes always fire after events from bindings (e.g. `oninput` always fires after an update to `bind:value`). Under the hood, events are either listened to directly through `addEventListener`, or the event is delegated. + ### Event delegation To reduce the memory footprint and increase performance, Svelte uses a technique called event delegation. This means that certain events are only listened to once at the application root, invoking a handler that then traverses the event call path and invokes listeners along the way. There are a few gotchas you need to be aware of when it comes to event delegation: -- when you dispatch events manually, make sure to set the `{ bubbles: true }` option -- when listening to events programmatically (i.e. not through `