Is there a more elegant solution for handling this particular piece of code?
return new Observable(subscriber => {
let subscription = this.anotherObservable().subscribe(
(next) => {
if (this.condition1(next)) {
subscriber.next(next);
} else if (this.condition2(next)) {
subscriber.complete();
} else {
subscriber.error('there was an error');
}
},
(error) => subscriber.error(error),
() => subscriber.complete()
);
return () => subscription.unsubscribe();
});
This code is located within a method in a specific class.
The anotherObservable
function returns an Observable that emits different types of data, hence the boolean conditions based on the value of next
.
I'm curious if there are any operator combinations that could achieve the same behavior with this Observable using pipes instead of creating a "custom" Observable.