Sub*_*med 7 rxjs angularfire2 angular angular5 angular6
我已更新Angular 5至Angular 6.现在我正在尝试更新我的代码以使其兼容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;
})
)
Run Code Online (Sandbox Code Playgroud)
我正在收到有关使用switchMap的警告Deprecated Symbol is used.
这些是我的进口: import {map, switchMap} from 'rxjs/operators';
在v6中有没有其他方法可以使用switchMap?此外,如果我不更改我的代码rxjs-compat应该使我现有的代码工作(我已经安装)但我得到以下错误相同的代码,但在RxJS 5样式:
.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;
})
Run Code Online (Sandbox Code Playgroud)
Error: Expected 1 argument but got 2.
给定的作为第二个参数的resultSelector功能switchMap被弃用.您需要删除它并使用map运算符实现目标.
这里最棘手的部分是决定把map操作员放在哪里.实际上map操作符进入函数体内作为参数提供switchMap.
没有结果选择器功能的代码将类似于以下内容:
.pipe(
map(job => job[0]),
switchMap((job) => {
return (job ? this.bookingService.findByID(job.property.id) : Observable.empty()).pipe(
// This is the mapping function provided as the alternative to the deprecated result selector function
// This should be placed inside the body of the function which is the 1st (and only one) argument of switchMap
map((bookings: Booking[])=>{
this.mark_jobs_unavailable(job, bookings);
return job;
})
);
}
)
)
Run Code Online (Sandbox Code Playgroud)
.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[]) => {
...
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5008 次 |
| 最近记录: |