Performance: switchMap for flattening
MEDIUM IMPACT
This affects how asynchronous streams are handled, impacting interaction responsiveness and CPU usage during observable flattening.
this.input$.pipe( switchMap(value => this.apiCall(value)) ).subscribe(result => this.handleResult(result));
this.input$.pipe( mergeMap(value => this.apiCall(value)) ).subscribe(result => this.handleResult(result));
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| mergeMap with rapid inputs | N/A | N/A | High CPU and network usage | [X] Bad |
| switchMap with rapid inputs | N/A | N/A | Minimal CPU and network usage | [OK] Good |