【发布时间】:2020-05-25 17:45:24
【问题描述】:
我有两个可观察的流,它们执行非常独立的映射逻辑,但最终以以下 3 个运算符结束:
this.selection
.pipe(
..Custom mapping operators
tap(_ => this.devicesLoading = true),
switchMap(d => this.mapService.findLocationForDevices(d)),
map(loc => marker([loc.latitude, loc.longitude])
)
.subscribe(markers => this.plotMarkers(markers));
我想将最后一个 tap, switchMap, map 运算符移动到一个通用函数中,这样我就可以在我的两个可观察流中应用它们。
我想过做:
private resolveLocationsAndConvertToMarkers = (devices: String[]) => [
tap(_ => this.devicesLoading = true),
switchMap((devices: string[]) => this.mapService.findLocationForDevices(devices)),
map(loc => marker([loc.latitude, loc.longitude])
];
但我不确定如何将这些运算符传播到管道参数中,例如:#
this.selection
.pipe(
// Custom mapping operators
... this.resolveLocationsAndConvertToMarkers
)
.subscribe(markers => this.plotMarkers(markers));
there are no overloads that expect 3 or 5 arguments..的这个错误。
【问题讨论】:
标签: rxjs rxjs-pipeable-operators rxjs-observables