Reputation: 1783
I have 2 observables
that I want to combine
, and use their combined version inside a combineLatest
with other observables
.
I'm not sure how to combine
them correctly for my Use Case.
First of all let's call them ObsA
and ObsB
, and their combined version ObsCombined
.
this.api.ObsA(),
this.api.ObsB(),
this.api.ObsCombined()
I need that their combined version only EMITS
values following these rules:
ObsB
is a BehaviourSubject
and its starting value is Null
.ObsA
emits, always make ObsCombined
emitObsA
emits "null
" as next value, then ObsB
value must be reset (I will call observable.next(null)
), and ObsCombined
should then emit both null
valuesSo basically, ObsA
is the most important, and the special thing is, when it emits Null
, I want to make the other Obs
reset and emit Null
as well.
If ObsB
emits a value, and ObsA
last emitted was not Null
, then emit this new value and the previous one from ObsA
Upvotes: 0
Views: 123
Reputation: 83
You can try with RxJs forkJoin
const obA = this.api.ObsA();
const obB = this.api.ObsB();
forkJoin([obA, obB]).subscribe(res=>{
console.log(res[0]);
console.log(res[1]);
});
Upvotes: 1
Reputation: 32517
maybe (not checked)
merge(
obsA.pipe(tap((v)=>{if(v==null) b.next(null)}),
obsB
).subscribe();
Upvotes: 0