I want to update my rxjs code to 6 got I don't get it.
Before I had the below that wouth poll for new data every 5 seconds:
import { Observable, interval } from 'rxjs'; import { switchMap, map } from 'rxjs/operators'; var result = interval(5000).switchMap(() => this._authHttp.get(url)).map(res => res.json().results);
Now...of course, it's broken and the documentation leaves me nowhere to go.
How do I write the above to conform to rxjs 6?
Thanks
map(function(value) { return value*10; }). subscribe(observer); SwitchMap - switchMap will subscribe to all the inner Observables inside the outer Observable but it does not merge the inner Observables. It instead switches to the latest Observable and passes that along to the chain.
RxJS switchMap() operator is a transformation operator that applies a project function on each source value of an Observable, which is later merged in the output Observable, and the value given is the most recent projected Observable.
RxJS interval() Creation OperatorRxJS interval() operator is a creation operator used to create an observable that emits a sequence of integers every time for the given time interval on a specified SchedulerLike. It emits incremented numbers periodically in time.
Angular Tap. Angular MergeMap. The Angular SwitchMap maps each value from the source observable into an inner observable, subscribes to it, and then starts emitting the values from it. It creates a new inner observable for every value it receives from the Source.
The code should be something like the following. You need to use the pipe
operator.
import { interval } from 'rxjs'; import { switchMap, map } from 'rxjs/operators'; const result = interval(5000).pipe( switchMap(() => this._authHttp.get(url)), map(res => res.results) )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With