aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/helpers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-08-02 15:29:09 +0200
committerChocobozzz <me@florianbigard.com>2021-08-02 15:40:09 +0200
commit3da38d6e9f8d600476be276666ac7223aa5f172c (patch)
treedaec25cccb900a0f90fc9d2273099683b42d8551 /client/src/app/helpers
parent200eaf5152ca72fe6b05a49caf819e22bd045b37 (diff)
downloadPeerTube-3da38d6e9f8d600476be276666ac7223aa5f172c.tar.gz
PeerTube-3da38d6e9f8d600476be276666ac7223aa5f172c.tar.zst
PeerTube-3da38d6e9f8d600476be276666ac7223aa5f172c.zip
Fetch things in bulk for the homepage
Diffstat (limited to 'client/src/app/helpers')
-rw-r--r--client/src/app/helpers/index.ts1
-rw-r--r--client/src/app/helpers/rxjs.ts29
2 files changed, 30 insertions, 0 deletions
diff --git a/client/src/app/helpers/index.ts b/client/src/app/helpers/index.ts
index cc61255ba..beff749ec 100644
--- a/client/src/app/helpers/index.ts
+++ b/client/src/app/helpers/index.ts
@@ -1,5 +1,6 @@
1export * from './locales' 1export * from './locales'
2export * from './constants' 2export * from './constants'
3export * from './i18n-utils' 3export * from './i18n-utils'
4export * from './rxjs'
4export * from './utils' 5export * from './utils'
5export * from './zone' 6export * from './zone'
diff --git a/client/src/app/helpers/rxjs.ts b/client/src/app/helpers/rxjs.ts
new file mode 100644
index 000000000..eb051f868
--- /dev/null
+++ b/client/src/app/helpers/rxjs.ts
@@ -0,0 +1,29 @@
1import { uniq } from 'lodash-es'
2import { asyncScheduler, Observable } from 'rxjs'
3import { bufferTime, distinctUntilChanged, filter, map, observeOn, share, switchMap } from 'rxjs/operators'
4import { NgZone } from '@angular/core'
5import { enterZone, leaveZone } from './zone'
6
7function buildBulkObservable <T extends number | string, R> (options: {
8 ngZone: NgZone
9 notifierObservable: Observable<T>
10 time: number
11 bulkGet: (params: T[]) => Observable<R>
12}) {
13 const { ngZone, notifierObservable, time, bulkGet } = options
14
15 return notifierObservable.pipe(
16 distinctUntilChanged(),
17 // We leave Angular zone so Protractor does not get stuck
18 bufferTime(time, leaveZone(ngZone, asyncScheduler)),
19 filter(params => params.length !== 0),
20 map(params => uniq(params)),
21 observeOn(enterZone(ngZone, asyncScheduler)),
22 switchMap(params => bulkGet(params)),
23 share()
24 )
25}
26
27export {
28 buildBulkObservable
29}