Performance: Store contract (subscribe method)
MEDIUM IMPACT
This affects how efficiently components update when store data changes, impacting interaction responsiveness and rendering speed.
let previous; const unsubscribe = store.subscribe(value => { if (value !== previous) { previous = value; efficientUpdate(value); } });
const unsubscribe = store.subscribe(value => { // heavy computation or DOM updates here expensiveUpdate(value); });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Subscribe triggers update on every change | Many DOM updates | Multiple reflows per update | High paint cost | [X] Bad |
| Subscribe updates only on real data change | Minimal DOM updates | Single reflow per real change | Low paint cost | [OK] Good |