Performance: Event forwarding
MEDIUM IMPACT
Event forwarding affects interaction responsiveness and event handling efficiency in the browser.
/* Child.svelte */ <button on:click>Click me</button> /* Parent.svelte */ <Child on:click={handleChildClick} />
/* Child.svelte */ <script> import { createEventDispatcher } from 'svelte'; const dispatch = createEventDispatcher(); function handleClick(event) { dispatch('click', event); } </script> <button on:click={handleClick}>Click me</button> /* Parent.svelte */ <Child on:click={handleChildClick} />
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Manual event dispatch forwarding | Adds extra event listeners | 0 | 0 | [X] Bad |
| Native event forwarding (Svelte default) | No extra listeners | 0 | 0 | [OK] Good |