Performance: Action parameters
MEDIUM IMPACT
This affects how efficiently event handlers and DOM manipulations run during user interactions.
function myAction(node, param) { node.textContent = param; return { update(newParam) { if (newParam !== param) { param = newParam; node.textContent = param; } } }; } <div use:myAction="hello"></div>
function myAction(node) { return { update(param) { node.textContent = param; } }; } <div use:myAction="hello"></div>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Update DOM on every param change (no check) | Multiple DOM writes | Triggers reflow each update | Higher paint cost | [X] Bad |
| Update DOM only on param change | Minimal DOM writes | Reflow only when needed | Lower paint cost | [OK] Good |