Performance of using same observable in multiple places in template with async pipe

Every use of observable$ | async will create a new subscription(and therefor an individual stream) to the given observable$ – if this observable contains parts with heavy calculations or rest-calls, those calculations and rest-calls are executed individually for each async – so yes – this can have performance implications. However this is easily fixed by … Read more

Angular 6 RXJS Import Syntax?

From rxjs 5.5, catch has been renamed to catchError function to avoid name clash. Due to having operators available independent of an Observable, operator names cannot conflict with JavaScript keyword restrictions. Therefore the names of the pipeable version of some operators have changed. import { catchError } from ‘rxjs/operators’; For throw you can use ErrorObservable. … Read more

Catch error in combined pipe of pipeable rxjs operators

After refactoring you moved map out of switchMap projection, so any error will close the outer stream. To keep both streams equivalent, you need to use pipe in the projection itself like that: import { EMPTY } from ‘rxjs’; // … @Effect() loadData$ = this.actions$ .ofType(LOAD_DATA) .pipe( map((action: LoadData) => action.payload), withLatestFrom(this.store.select(getCultureCode)), switchMap(([payload, cultureCode]) => … Read more

rxjs 7 update – Subject – Expected 1 arguments, but got 0

tl;dr: Either indicate the type explicitly with void: new Subject<void>(); or pass a fake value: this.destroy$.next(true); Rxjs 7 changes After checking the changelog and several github issues about this situation, Subject: resolve issue where Subject constructor errantly allowed an argument (#5476) (e1d35dc) Subject: no default generic (e678e81) Changelog 7.0.0-beta.1 and the commit where empty value … Read more

RxJS skipWhile vs filter

The difference is that upon its expression evaluating to false, skipWhile changes over to mirroring its source observable – so it will cease to filter out any further values. For example: Observable.from([1,2,3,4,5]) .pipe(filter(val => val % 2 == 0)) // filters out odd numbers .subscribe(val => console.log(val)); // emits 2,4 Observable.from([1,2,3,4,5]) .pipe(skipWhile(val => val % … Read more

Why handle errors with catchError and not in the subscribe error callback in Angular

1 It’s all about separation of concern in Angular One major benefit of using catchError is to separate the whole data retrieval logic including all errors that can occur along the way from the presentation of the data. 1.1 Let Components only care about the presentation of data Components should only care about data (whether … Read more

RxJS distinctUntilChanged – object comparison

I had the same problem, and fixed it with using JSON.stringify to compare the objects: .distinctUntilChanged((a, b) => JSON.stringify(a) === JSON.stringify(b)) This code will work if the attriutes are in the same order, if not it may break, so here’s a quick fix for that (be careful this method is slower) .distinctUntilChanged((a, b) => JSON.stringify(a).split(”).sort().join(”) … Read more

tap() vs subscribe() to set a class property

Edit: Ignore this answer! Here is a good answer: https://stackoverflow.com/a/50882183/5932590 See JMD’s comment below for more context! Good question. In the source code for the tap operator, this comment pretty much sums it up: This operator is useful for debugging your Observables for the correct values or performing other side effects. Note: this is different … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)