]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/helpers/rxjs.ts
Fix job progress column
[github/Chocobozzz/PeerTube.git] / client / src / app / helpers / rxjs.ts
1 import { uniq } from 'lodash-es'
2 import { Observable } from 'rxjs'
3 import { bufferTime, distinctUntilChanged, filter, map, share, switchMap } from 'rxjs/operators'
4
5 function buildBulkObservable <P extends number | string, R> (options: {
6 notifierObservable: Observable<P>
7 time: number
8 bulkGet: (params: P[]) => Observable<R>
9 }) {
10 const { notifierObservable, time, bulkGet } = options
11
12 return notifierObservable.pipe(
13 distinctUntilChanged(),
14 bufferTime(time),
15 filter(params => params.length !== 0),
16 map(params => uniq(params)),
17 switchMap(params => {
18 return bulkGet(params)
19 .pipe(map(response => ({ params, response })))
20 }),
21 share()
22 )
23 }
24
25 export {
26 buildBulkObservable
27 }