Hot and Cold observables: are there ‘hot’ and ‘cold’ operators?

I am coming back a few months later to my original question and wanted to share the gained knowledge in the meanwhile. I will use the following code as an explanation support (jsfiddle): var ta_count = document.getElementById(‘ta_count’); var ta_result = document.getElementById(‘ta_result’); var threshold = 3; function emits ( who, who_ ) {return function ( x … Read more

RxJS: takeUntil() Angular component’s ngOnDestroy()

You could leverage a ReplaySubject for that: EDIT: Different since RxJS 6.x: Note the use of the pipe() method. class myComponent { private destroyed$: ReplaySubject<boolean> = new ReplaySubject(1); constructor( private serviceA: ServiceA, private serviceB: ServiceB, private serviceC: ServiceC) {} ngOnInit() { this.serviceA .pipe(takeUntil(this.destroyed$)) .subscribe(…); this.serviceB .pipe(takeUntil(this.destroyed$)) .subscribe(…); this.serviceC .pipe(takeUntil(this.destroyed$)) .subscribe(…); } ngOnDestroy() { this.destroyed$.next(true); this.destroyed$.complete(); … Read more

Chaining Observables in RxJS

About promise composition vs. Rxjs, as this is a frequently asked question, you can refer to a number of previously asked questions on SO, among which : How to do the chain sequence in rxjs RxJS Promise Composition (passing data) RxJS sequence equvalent to promise.then()? Basically, flatMap is the equivalent of Promise.then. For your second … Read more

Difference between .unsubscribe to .take(1)

Each serves a different purpose so it’s hard to compare them. In general if you take this source: const source = range(1,3); … and consume it with subscribe() followed immediately by unsubscribe(): source.subscribe( console.log, undefined, () => console.log(‘complete’) ).unsubscribe(); … then all values from source are going to be emitted even though we called unsubscribe() … Read more

When to use asObservable() in rxjs?

When to use Subject.prototype.asObservable() The purpose of this is to prevent leaking the “observer side” of the Subject out of an API. Basically to prevent a leaky abstraction when you don’t want people to be able to “next” into the resulting observable. Example (NOTE: This really isn’t how you should make a data source like … Read more

Observable Finally on Subscribe

The current “pipable” variant of this operator is called finalize() (since RxJS 6). The older and now deprecated “patch” operator was called finally() (until RxJS 5.5). I think finalize() operator is actually correct. You say: do that logic only when I subscribe, and after the stream has ended which is not a problem I think. … Read more

What is pipe for in RxJS?

The “pipeable” (former “lettable”) operators is the current and recommended way of using operators since RxJS 5.5. I strongly recommend you to read the official documentation on pipeable operators The main difference is that it’s easier to make custom operators and that it’s better treeshakable while not altering some global Observable object that could possible … Read more

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