`_http.get().pipe(publishReplay(), refCount())` behavior differs - if returned from a getterMethod() and - if declared as a property$

36 views Asked by At

I created a mini app which shows the Continent & the Country selections

You can checkout to ng-conf/learn-rxjs-01 branch on https://stackblitz.com/edit/stackblitz-starters-hvcdxw to view the app components

In the app.component.ts file

if API call is returned from an observable property - the call is triggered only once - for each & every CONTINENT dropdown select

fetchCountryByContinent$ = this._http.get<ContinentCountry[]>(this.countriesUrl).pipe(publishReplay(), refCount())

API call is returned from an observable property - the call is triggered only once API call is returned from an observable property - the call is triggered only once

if API call is returned from a getter method - Call is triggered for each & every CONTINENT dropdown select

get fetchCountryByContinent$() {
    return this._http.get<ContinentCountry[]>(this.countriesUrl).pipe(publishReplay(), refCount());
}

API call is returned from a getter method - Call is triggered for each & every CONTINENT dropdown select API call is returned from a getter method - Call is triggered for each & every CONTINENT dropdown select

and

if I remove the .pipe(publishReplay(), refCount()) & run the code - both the instances behave in the same manner by providing duplicate API calls - for each and every CONTINENT dropdown select

Duplicate calls on .pipe(publishReplay(), refCount()) removal Duplicate calls on .pipe(publishReplay(), refCount()) removal

Why is the behavior like this for all these cases?

0

There are 0 answers