我有两个可观察的流,它们执行非常独立的映射逻辑,但最终以以下 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
..