Skip to content

Instantly share code, notes, and snippets.

View AnkitaSinghal's full-sized avatar
🎯
Learning

Ankita Singhal AnkitaSinghal

🎯
Learning
  • Berlin, Germany (from India)
View GitHub Profile
@AnkitaSinghal
AnkitaSinghal / map.js
Created September 15, 2020 15:43
Difference between MergeMap, switchMap, concatMap and exhaustMap
of(1, 2, 3).pipe(exhaustMap((x) => interval(2000)
.pipe(take(3),tap((t) => console.log(x, t)))) )
.subscribe((d) => console.log('GOT ', d));
// Merge Map : 1 0, 2 0, 3 0, 1 1, 2 1, 3 1, 1 2, 2 2, 3 2
// switchMap: 3 0, 3 1, 3 2
// ConcatMap: 1 0, 1 1, 1 2, 2 0, 2 1, 2 2, 3 0, 3 1, 3 2,
// exhaustMap: 1 0, 1 1, 1 2
@AnkitaSinghal
AnkitaSinghal / forkjoin.js
Created June 3, 2020 02:52
Fork Join best practice
// Fork join - subscribe to several parallel observables, wait for all to complete and do something with the result
// https://medium.com/better-programming/rxjs-forkjoin-never-use-array-indexes-in-subscribe-1f4005582ae8
forkJoin(
this.http.get('some/api/welcomeMessage'),
language$,
dateRange$
// Use tab to handle data processing for each observable separately
.pipe(tap(([startDate, endDate]) => {
this.startDate = startDate;
this.endDate = endDate;