import { uniq } from 'lodash-es' import { Observable } from 'rxjs' import { bufferTime, distinctUntilChanged, filter, map, share, switchMap } from 'rxjs/operators' function buildBulkObservable

(options: { notifierObservable: Observable

time: number bulkGet: (params: P[]) => Observable }) { const { notifierObservable, time, bulkGet } = options return notifierObservable.pipe( distinctUntilChanged(), bufferTime(time), filter(params => params.length !== 0), map(params => uniq(params)), switchMap(params => { return bulkGet(params) .pipe(map(response => ({ params, response }))) }), share() ) } export { buildBulkObservable }