RxJS 6缓冲区,带有反跳为closeNotifier

时间:2018-10-16 13:24:32

标签: javascript buffer rxjs6 debounce

如何在 RxJS 6 中实现 Observables 以实现以下行为?

RxMarble diagram

说明: 我正在尝试创建传入的Observable [0]值的缓冲区[1],该缓冲区在相同Observable [0]的去抖动[2]时间后缓冲。

这是我现在所拥有的:

const Observable = rxjs.Observable;
const buffer = rxjs.operators.buffer;
const debounceTime = rxjs.operators.debounceTime;

const DEBOUNCE_TIME_SPAN = 2000;
let $observableObserver = null;

// Custom cold observable.
const $observable = Observable.create((observer) => {
  // Exposed observer
  $observableObserver = observer;
  // Manual entries
  observer.next(0);
});

// Debounce time observable (OK)
const $debouncedObservable = $observable
  .pipe(debounceTime(DEBOUNCE_TIME_SPAN));

// Buffered observable (THIS DOES NOT WORK)
const $bufferObservable = $debouncedObservable
  .pipe(buffer($observable));

// So this doesn't print something correct.
$bufferObservable.subscribe({
  next: v => console.log(v),
});

0 个答案:

没有答案