Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RxJS 6 switchMap Deprecated Symbol used

I've updated from Angular 5 to Angular 6. Now I'm trying to update my code to make it compatible with RxJS 6.

.pipe(
  map(job => job[0]),
  switchMap((job) => {
    return job ? this.bookingService.findByID(job.property.id) : Observable.empty();
  }, (job: Job, bookings: Booking[]) => {
    this.mark_jobs_unavailable(job, bookings);
    return job;
  })
)

I'm getting warning on using switchMap that Deprecated Symbol is used.

These are my imports: import {map, switchMap} from 'rxjs/operators';

Is there any alternative way to use switchMap in v6? Also, If I don't change my code the rxjs-compat should make my existing code work (which i have installed) but I get the following error with the same code but in RxJS 5 style:

.map(job => job[0])
.switchMap((job) => {
    return job ? this.bookingService.findByID(job.property.id) : Observable.empty();
}, (job: Job, bookings: Booking[]) => {
    this.mark_jobs_unavailable(job, bookings);
    return job;
})

Error: Expected 1 argument but got 2.

like image 341
Subhan Avatar asked May 23 '18 01:05

Subhan


1 Answers

.pipe(
  map(job => job[0]),
  switchMap((job) => {
    return job ? this.bookingService.findByID(job.property.id).pipe(
      map((bookings: Booking[]) => {
        return {
          job: job,
          bookings: bookings
        };
      })
    ) : Observable.empty();
  }
).subscribe((job, bookings: Booking[]) => {
  ...
})
like image 164
Eduardo Avatar answered Sep 24 '22 10:09

Eduardo