Reputation: 83
I have three source of data :
let insightsFromDB$;// Return observable of insight object
let insightsFromAPI$;// Return observable of insight object
let insightsFromWebsockets; // Return observable of insight object
otherObservable$
.merge(insightsFromDB$, insightsFromAPI$) // Return observable of insight object
.map(insight=>insight.likes)
I want to add the insightsFromWebsockets$
to the otherObservable$
in such a way that if it's emits a value, it cancels the insight object coming from the merge operator and emit the object coming from insightsFromWebsockets$
to the map operator.
For more clarity, I have added the following marble diagram that summarize my code:
Upvotes: 0
Views: 304
Reputation: 9425
So if i understand your requirements correctly:
x
and z
(merge
)z
emits you no longer are interested in values of x
(takeUntil
)Example implementation:
var x = Rx.Observable.interval(300);
var y = Rx.Observable.timer(1500, 500).mapTo('y');
x.takeUntil(y)
.merge(y)
.take(8).subscribe(console.log)
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/5.5.12/Rx.js"></script>
Upvotes: 2