Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

forkJoin is deprecated: resultSelector is deprecated, pipe to map instead

Tags:

angular

rxjs6

I'm working on an Angular 6 project.

Running ng lint gives the following Warning:

"forkJoin is deprecated: resultSelector is deprecated, pipe to map instead"

 forkJoin(...observables).subscribe( 

Any idea? Can't seem to find any information about this deprecation.

I just generated a brand new Angular application "ng new forkApp" with Angular CLI: 6.1.5

source:

import { Component, OnInit } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { forkJoin } from 'rxjs';  @Component({   selector: 'app-root',   templateUrl: './app.component.html',   styleUrls: ['./app.component.css'] }) export class AppComponent implements OnInit {   title = 'forkApp';    constructor(private http: HttpClient) {}    ngOnInit() {     console.log('ngOnInit...');      const obs = [];     for (let i = 1; i < 4; i++) {        const ob = this.http.get('https://swapi.co/api/people/' + i);       obs.push(ob);      }      forkJoin(...obs)       .subscribe(         datas => {           console.log('received data', datas);         }       );    } } 

"dependencies" section from package.json file:

  "dependencies": {     "@angular/animations": "^6.1.0",     "@angular/common": "^6.1.0",     "@angular/compiler": "^6.1.0",     "@angular/core": "^6.1.0",     "@angular/forms": "^6.1.0",     "@angular/http": "^6.1.0",     "@angular/platform-browser": "^6.1.0",     "@angular/platform-browser-dynamic": "^6.1.0",     "@angular/router": "^6.1.0",     "core-js": "^2.5.4",     "rxjs": "^6.0.0",     "zone.js": "~0.8.26"   }, 

Once all three GET requests are done I got all data in "datas" array. The issue is that once I run: ng lint I got this:

C:\forkApp>ng lint

WARNING: C:/forkApp/src/app/app.component.ts[26, 5]: forkJoin is deprecated: resultSelector is deprecated, pipe to map instead

like image 281
robert Avatar asked Sep 24 '18 20:09

robert


People also ask

Is forkJoin deprecated?

forkJoin Improvements Moreover, there is one deprecation — forkJoin(a, b, c, d) should no longer be used; Instead, pass an array such as forkJoin([a, b, c, d]) .

What can I use instead of forkJoin?

concat() which will handle each observable in sequence.

How do you handle errors in forkJoin?

forkJoin is an operator that is best for use. If you are having issues in handling multiple requests on page load or want to move to action when all the responses are received. You can easily group the observables and emit the final value for each error.

What is the difference between combineLatest and forkJoin?

forkJoin - When all observables complete, emit the last emitted value from each. combineLatest - When any observable emits a value, emit the latest value from each.


2 Answers

I was able to fix this by getting rid of the ellipsis:

forkJoin(observables).subscribe();

As long as observables is already an array, it should have the same result.

like image 104
Lani Avatar answered Sep 21 '22 23:09

Lani


forkJoin(observable1, observable2)   // WORKING - deprecation warning (memberObservables) => forkJoin(memberObservables)) // warning, too forkJoin([observable1, observable2]) // WORKING - no warning (memberObservables: Array<any>) => forkJoin(memberObservables)) // no warning 
like image 37
radeveloper Avatar answered Sep 21 '22 23:09

radeveloper