1 import { uniq } from 'lodash-es'
2 import { Observable } from 'rxjs'
3 import { bufferTime, distinctUntilChanged, filter, map, share, switchMap } from 'rxjs/operators'
5 function buildBulkObservable <P extends number | string, R> (options: {
6 notifierObservable: Observable<P>
8 bulkGet: (params: P[]) => Observable<R>
10 const { notifierObservable, time, bulkGet } = options
12 return notifierObservable.pipe(
13 distinctUntilChanged(),
15 filter(params => params.length !== 0),
16 map(params => uniq(params)),
18 return bulkGet(params)
19 .pipe(map(response => ({ params, response })))