Typescript transform forkJoin results with pipe and cleanup

What is the best way transforming result of forkJoin() so in subscribe() method I can write something like this:


Here is how it works right now:

  loadAll(): void {
    const dependencies = this.dependencyService.query();
    const microservices = this.microserviceService.query();

    forkJoin({dependencies, microservices})
      .subscribe(results => {
        this.refreshGraph(results.dependencies.body || [], results.microservices.body || []);

  refreshGraph(dependencies: IDependency[], microservices: IMicroservice[]): void {

Do I need to store result of forkJoin().subscribe() in Subscription and unsubscribe manually when component is destroyed? dependencyService and microserviceService in my case just wrap http:

  query(req?: any): Observable<EntityArrayResponseType> {
    const options = createRequestOption(req);
    return this.http.get<IDependency[]>(this.resourceUrl, { params: options, observe: 'response' });

Full source code is available here

Read more here: https://stackoverflow.com/questions/64400054/typescript-transform-forkjoin-results-with-pipe-and-cleanup

Content Attribution

This content was originally published by tillias at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: