I've been experimenting with the RXJS scan operator, but I'm struggling to understand it fully. My goal is to make the scan operator not return the accumulated result, but rather the emitted items
from the source if bufferResults
is set to false. The code snippet below demonstrates how only a single value from items
is emitted instead of the entire array.
const refreshedItems$ = items$.pipe(
withLatestFrom(this.bufferResults$.pipe(startWith(undefined))),
scan<any>((acc, [src, buffer]) => {
return !buffer ? src : acc.concat(src);
}),
map(([items, ]) => items),
shareReplay(),
tap((items) => console.warn('shareReplay', items)),
);
Does anyone have a clear explanation of how this code works, or know of a good article that explains its functionality?