I have two different observers, and upon geting the first result for each I perform an action:
Observer 1
specialties$.subscribe(
(value) => {
this.specialtiesOptions = value['result'].map((specialty) => {
return {...specialty, selected: false}
})
}
)
Observer 2:
partner$.subscribe({
next: (value: Partner) => {
// other stuff happening here
this.partner = mutate(value)
}
I have another method, which is related to both, which should only be called when I get the value for both observers, and both this.specialties and this.partner are correctly populated.
How can I do this?
Is it possible to do this while keeping the operations logically separated.
I ended up doing it like this. Not sure if it's the cleanest or most idiomatic solution... but it works for me so far. Leaving in case it helps someone else (and so I can tell it sucks if it does!)
I create a couple
Subjects:which I update on each
subscribe()call:And then subscribe to each
Subject, and check if the properties are set:It works. What I don't like is that I'm checking the status of the properties. In this specific case it works, but I'd prefer to check for example if both subjects are
complete(), but not sure how would I do that.