Filter an observable using values from another observable

You can use withLatestFrom. . source.withLatestFrom(checkboxes, (data, checkbox) => ({data, checkbox})) .filter(({data, checkbox}) => …) Here, checkboxes is an observable representing a list of checkbox inputs. source is an observable representing a stream of events coming from the server. In the filter function you can check if the data is valid compared to the checkbox … Read more

RxJS takeWhile but include the last value

Since RxJS 6.4.0 this is now possible with takeWhile(predicate, true). There’s already an opened PR that adds an optional inclusive parameter to takeWhile: https://github.com/ReactiveX/rxjs/pull/4115 There’re at least two possible workarounds: using concatMap(): of(‘red’, ‘blue’, ‘green’, ‘orange’).pipe( concatMap(color => { if (color === ‘green’) { return of(color, null); } return of(color); }), takeWhile(color => color), ) … Read more

Where is RxJS 6 static merge?

Importing has been made easy in RxJS 6: import { merge } from ‘rxjs’; You may want to read the official migration guide. Another useful resource regarding importing in RxJS 6 is this talk by Ben Lesh who is the RxJS lead.

How to force observables to execute in sequence?

If you want to be sure the order of emissions is the same as the order in which you specified the source Observables you can use concat or concatMap operators. The concat* operators subscribe to an Observable only after the previous Observable completes (it works with Promises as well, see http://reactivex.io/rxjs/class/es6/MiscJSDoc.js~ObservableInputDoc.html). In you case it’d … Read more

RxJs – forkJoin with empty array

That’s because forkJoin requires all source Observables to emit at least one item and when there are no source Observables there’s nothing to emit. However, forkJoin will still send the complete notification so you can use for example defaultIfEmpty operator to make sure it always emits at least one next. forkJoin(observables).pipe( defaultIfEmpty(null), ).subscribe(…); Demo: https://stackblitz.com/edit/rxjs-kkd1qa?file=index.ts

combineLatest deprecated in favor of static combineLatest

In rxjs 6.5+ import { combineLatest } from ‘rxjs’; combineLatest([a$, b$, c$]); And for most applications it’s helpful to map the array of observables to a new value as well: combineLatest([a$, b$, c$]).pipe( map(([a$, b$, c$]) => ({ a: a$, b: b$, c: c$ })) ); Also see: https://www.learnrxjs.io/learn-rxjs/operators/combination/combinelatest

RxJS Observables nested subscriptions?

As mentioned in comments, you are looking for the flatMap operator. You can find more details in previous answers : How to do the chain sequence in rxjs Why do we need to use flatMap? Your example would read as : this.returnsObservable1(…) .flatMap(success => this.returnsObservable2(…)) .flatMap(success => this.returnsObservable3(…)) .subscribe(success => {(…)});

tech