I want to use Rx.Observable.if
to run one of two observables should a conditional observable resolve to true or false.
What I want to achieve would look something like this:
Rx.Observable.if(conditionalObservable.map(x => x.length > 0), firstObservable, secondObservable).subscribe()
If conditionalObservable
sends a next and then completes with a true value, firstObservable
should be run and otherwise, secondObservable
should run.
Now obviously that doesn't work because Rx.Observable.if
expects a function conditional, not an observable. How can I achieve the exact same functionality in RXJS?
Note: This issue is almost the same but I don't think it's concise enough because 1) you have to have two pausable
statements and 2) unless you append a take(1)
to your conditional observables, you can't guarantee the conditional won't emit more next events. IMO it's a workaround and subject to much more human error.