-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
thenSource of if() still running even though condition is false #2768
Comments
The
That isn't an RxJS issue it is a javascript one. Personally I have always wished that Observable.if(
() => !!whatever,
Observable.defer(() => Observable.of(`true: ${whatever.something}`))
) |
Got it. At least I'm not going crazy. Put another way, I think, is that the word "if" has fooled me into expecting it to work as an if/else statement, and caused me to forget that Thanks for the defer tip. That looks way less hacky than my solution. And congrats on the book release btw. I'm looking forward to another read when I get my dead tree version. |
No problem and thanks! |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
RxJS version:
5.4.2
Code to reproduce:
I have an issue where
Observable.if()
isn't protecting me against a null value like I expect it would.If I have a variable,
whatever
, that can be null or a simple object......and if I use
Observable.if()
like this......when
whatever
isnull
, I get an error: Cannot read property 'something' of null.Shouldn't the false condition stop the
thenSource
from running?If I "wrap" the
thenSource
stream in aswitchMap
, it works; I'm protected from the null value and theelseSource
runs.Additional information:
Here's a codepen to play with:
https://codepen.io/patrickmcd/pen/BZeeQK?editors=0010
The text was updated successfully, but these errors were encountered: