Performance: Action with event dispatching
MEDIUM IMPACT
This affects interaction responsiveness and event handling efficiency in the browser.
function myAction(node) { const handleClick = () => { node.dispatchEvent(new CustomEvent('myEvent', { detail: { clicked: true } })); }; node.addEventListener('click', handleClick); return { destroy() { node.removeEventListener('click', handleClick); } }; }
function myAction(node) { node.addEventListener('click', () => { node.dispatchEvent(new CustomEvent('myEvent', { detail: { clicked: true } })); }); return { destroy() { node.removeEventListener('click', () => {}); } }; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Anonymous event listener in action | No extra DOM nodes | 0 reflows | Minimal paint | [X] Bad |
| Named event listener with proper cleanup | No extra DOM nodes | 0 reflows | Minimal paint | [OK] Good |