Is it possible in RxJS 5.5 to implement condition using some operator to skip all subsequent operators and emit some value (false
)? For instance in this ng service method I would bypass bunch of this .map
chain and provide false
value immediately if response.length === 0
:
getProjectDrivers(projectId): Observable<any> {
return this.http.get('someUrl').pipe(
// if (response.length === 0) { return false; and skip whole operator chain bellow}
map((response: ProjectDriver[]) => response.filter((projectDriver: ProjectDriver) => projectDriver.streamName !== "AllRevenueStreamTotals")),
map((response: ProjectDriver[]) => command => ({})
)
)
.catch(this.handleError);
}
I suppose you always can play with switchMap
return this.http.get('someUrl').pipe(
switchMap(response => {
if (!response.length) {
return of(null);
} else {
return of(result).pipe(
map((response: ProjectDriver[]) => response.filter((projectDriver: ProjectDriver) => projectDriver.streamName !== "AllRevenueStreamTotals")),
map((response: ProjectDriver[]) => command => ({}))
)
}
}
)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments