I have an Angular component that relies on 3 services, each of which has an observer I can subscribe to. The view of the component needs to be updated whenever there are changes in the observed data, which occurs through websockets (feathers.js). I want the method
doSomethingWithTheNewDataThatIsShownOnView()
to only be called once during ngInit, and I believe I can achieve this with forkJoin:
private ngOnInit(): void {
Observable.forkJoin(
this.filesService.inputs$,
this.filesService.outputs$,
this.processesService.items$
).subscribe(
data => {
this.inputs = data[0];
this.outputs = data[1];
this.processes = data[2];
this.doSomethingWithTheNewDataThatIsShownOnView();
this.ref.markForCheck();
},
err => console.error(err)
);
this.filesService.find();
this.processesService.find();
}
This implementation works as expected, but if there are updates in the inputs$ or outputs$ Observables, the subscription is not triggered again. It only gets triggered when all three Observables have new data. Is there a way to "wait for a 100ms interval to see if all three observables have received new data, and if not, use the individual new data from each observable until now?"
I hope my intention is clear :D
Regards,
Chris