You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The documentation says, that only trueResult of the given observables will be subscribed, but both of the falseResult and trueResult will be subsrcibed to, and only returns the trueResult observable's value.
Expected behavior
Only subsrcibe to the trueResult observable.
Reproduction code
iif(()=>false,firstObs(),secondObs())functionfirstObs(): Observable<string>{console.log("Why?");// <--- this got loggedreturnof("one way");}functionsecondObs(): Observable<string>{console.log("Why not?");// <--- this got loggedreturnof("other way");}
Reproduction URL
No response
Version
7.8.1
Environment
No response
Additional context
No response
The text was updated successfully, but these errors were encountered:
If you subscribe to your iif Observable, you'll see that it only logs other way. one way is not logged and will not be logged as long as the function passed as the first parameter to iif returns falsy value. Please visit this link for demo.
The reason why Why? gets logged is because you're actually calling firstObs function when preparing the second parameter for iif which calls console.log("Why?") before returning of("one way"). This has nothing to do with RxJS, it's just how JavaScript works.
If you need to postpone execution of firstObs, you can use this:
Describe the bug
The documentation says, that only
trueResult
of the given observables will be subscribed, but both of thefalseResult
andtrueResult
will be subsrcibed to, and only returns thetrueResult
observable's value.Expected behavior
Only subsrcibe to the
trueResult
observable.Reproduction code
Reproduction URL
No response
Version
7.8.1
Environment
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: