angular2: How to debounce Observable.combineLatest calls?

The combineLatest method's project function is essentially a map operator. You could re-arrange things like this:

myData$ = Observable.combineLatest(
  this.store.let(fromRoot.getFoo),
  this.store.let(fromRoot.getBar),
  this.store.let(fromRoot.getFoobar),
  this.store.let(fromRoot.getBarfoo)
)
.debounceTime(300)
.map(([foo, bar, foobar, barfoo]) => {
  ...
});

With rxjs > v6 you have to use the rxjs pipe function combined with the debounceTime operator e.g.

import {combineLatest, timer} from 'rxjs';
import {debounceTime} from 'rxjs/operators';

function testCombineLatest() {

  const startTime = Date.now();
  const timerOne$ = timer(1000, 1000);
  const timerTwo$ = timer(1300, 1000);

  combineLatest(timerOne$, timerTwo$)
    .pipe(debounceTime(600))
    .subscribe(([timer1, timer2]) => {
      console.log('TimeElapsed:', Date.now() - startTime);
      console.log('Timer Latest:', timer1, timer2);
    });
}
testCombineLatest();

Tags:

Angular

Rxjs