Performance: Effects for side effects
MEDIUM IMPACT
This affects the responsiveness and smoothness of user interactions by managing side effects outside the component rendering cycle.
readonly loadDataEffect = effect(() => { this.http.get('/api/data').subscribe(data => { this.data.set(data); this.logService.log('Data loaded'); }); });this.http.get('/api/data').subscribe(data => { this.data = data; this.logService.log('Data loaded'); });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Direct subscription in component | Multiple DOM updates | Multiple reflows per update | Higher paint cost due to frequent updates | [X] Bad |
| Angular Effects for side effects | Minimal DOM updates triggered | Single or no reflows per effect | Lower paint cost with batched updates | [OK] Good |