Skip to content

Latest commit

 

History

History
51 lines (35 loc) · 1.39 KB

resultSelector.md

File metadata and controls

51 lines (35 loc) · 1.39 KB

ResultSelector Parameter

Some operator supported a resultSelector argument that acted as mapping function on the result of that operator. The same behavior can be reproduced with the map operator, therefore this argument became deprecated.

This deprecation was introduced in RxJS 6.0 and will become breaking with RxJS 8.

There were two reasons for actually deprecating those parameters:

  1. It increases the bundle size of every operator
  2. In some scenarios values had to be retained in memory causing a general memory pressure

Operators affected by this Change

How to Refactor

Instead of using the resultSelector Argument, you can leverage the map operator on the inner Observable:

import {fromEvent, interval} from 'rxjs';
import {switchMap, map} from 'rxjs/operators';

// deprecated
fromEvent(document, 'click').pipe(
    switchMap(x => interval(0, 1000), (x) => x+1)
);
// suggested change
fromEvent(document, 'click').pipe(
    switchMap(x => interval(0, 1000).pipe(
        map(x => x+1)
    ))
);