Example 1:
var obsNumber = /* observable that produce numbers */;
var obsText1 = /* observable that produce text */;
var obsText2 = /* observable that produce text */;
var obsContext = /* IF obsNumber < 5 THEN obsText1 ELSE obsText2 */;
obsContext
is an observable that will return either data from obsText1
or obsText2
, depending on the value of obsNumber
.
Example 2:
var arrOfObservables = /* an array of observables */;
var obsNumber = /* observable that produce numbers */;
var obsSelect = /* arrOfObservables[obsNumber] */;
obsSelect
is an observable, that will return data from the selected observable from the arrOfObservables
array determined by the value produced by obsNumber
.
I cannot figure out how to specify this behavior using RxJS. It seems to me I need to be able to subscribe/unsubscribe dynamically between multiple observables.
How to make the two examples work using RxJS?