Performance: Action return data
MEDIUM IMPACT
This concept affects how efficiently Svelte actions communicate data back to components, impacting interaction responsiveness and rendering updates.
function myAction(node) { const data = node.getAttribute('data-info'); return { data }; } // Component accesses returned data directly from action result
function myAction(node) { node.addEventListener('click', () => { const data = node.getAttribute('data-info'); node.dispatchEvent(new CustomEvent('data', { detail: data })); }); return {}; } // Component listens for 'data' event and reads detail
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Return data via event dispatch | Multiple event listeners | 0 | Low | [!] OK |
| Return data directly from action | No extra listeners | 0 | Low | [OK] Good |