如何在 RxJS 6 中实现 Observables 以实现以下行为?
说明: 我正在尝试创建传入的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),
});