aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/video/infinite-scroller.directive.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-05-15 11:55:51 +0200
committerChocobozzz <me@florianbigard.com>2018-05-16 09:42:54 +0200
commitdb400f447a9f7aae1c56fa25396e93069744483f (patch)
treef45af832a5d3f4eebafd2f885b7413d9f84fa374 /client/src/app/shared/video/infinite-scroller.directive.ts
parent54c3a22faa04bf13eea37f39be9149fc5eb95737 (diff)
downloadPeerTube-db400f447a9f7aae1c56fa25396e93069744483f.tar.gz
PeerTube-db400f447a9f7aae1c56fa25396e93069744483f.tar.zst
PeerTube-db400f447a9f7aae1c56fa25396e93069744483f.zip
Upgrade to rxjs 6
Diffstat (limited to 'client/src/app/shared/video/infinite-scroller.directive.ts')
-rw-r--r--client/src/app/shared/video/infinite-scroller.directive.ts68
1 files changed, 34 insertions, 34 deletions
diff --git a/client/src/app/shared/video/infinite-scroller.directive.ts b/client/src/app/shared/video/infinite-scroller.directive.ts
index e2730423f..0448e2c23 100644
--- a/client/src/app/shared/video/infinite-scroller.directive.ts
+++ b/client/src/app/shared/video/infinite-scroller.directive.ts
@@ -1,14 +1,6 @@
1import { distinct, distinctUntilChanged, filter, map, share, startWith, throttleTime } from 'rxjs/operators'
1import { Directive, EventEmitter, Input, OnDestroy, OnInit, Output } from '@angular/core' 2import { Directive, EventEmitter, Input, OnDestroy, OnInit, Output } from '@angular/core'
2import 'rxjs/add/operator/debounceTime' 3import { fromEvent, Subscription } from 'rxjs'
3import 'rxjs/add/operator/distinct'
4import 'rxjs/add/operator/distinctUntilChanged'
5import 'rxjs/add/operator/filter'
6import 'rxjs/add/operator/map'
7import 'rxjs/add/operator/share'
8import 'rxjs/add/operator/startWith'
9import 'rxjs/add/operator/throttleTime'
10import { fromEvent } from 'rxjs/observable/fromEvent'
11import { Subscription } from 'rxjs/Subscription'
12 4
13@Directive({ 5@Directive({
14 selector: '[myInfiniteScroller]' 6 selector: '[myInfiniteScroller]'
@@ -51,43 +43,51 @@ export class InfiniteScrollerDirective implements OnInit, OnDestroy {
51 const throttleOptions = { leading: true, trailing: true } 43 const throttleOptions = { leading: true, trailing: true }
52 44
53 const scrollObservable = fromEvent(window, 'scroll') 45 const scrollObservable = fromEvent(window, 'scroll')
54 .startWith(true) 46 .pipe(
55 .throttleTime(200, undefined, throttleOptions) 47 startWith(null),
56 .map(() => ({ current: window.scrollY, maximumScroll: document.body.clientHeight - window.innerHeight })) 48 throttleTime(200, undefined, throttleOptions),
57 .distinctUntilChanged((o1, o2) => o1.current === o2.current) 49 map(() => ({ current: window.scrollY, maximumScroll: document.body.clientHeight - window.innerHeight })),
58 .share() 50 distinctUntilChanged((o1, o2) => o1.current === o2.current),
51 share()
52 )
59 53
60 // Scroll Down 54 // Scroll Down
61 this.scrollDownSub = scrollObservable 55 this.scrollDownSub = scrollObservable
62 // Check we scroll down 56 .pipe(
63 .filter(({ current }) => { 57 // Check we scroll down
64 const res = this.lastCurrentBottom < current 58 filter(({ current }) => {
59 const res = this.lastCurrentBottom < current
65 60
66 this.lastCurrentBottom = current 61 this.lastCurrentBottom = current
67 return res 62 return res
68 }) 63 }),
69 .filter(({ current, maximumScroll }) => maximumScroll <= 0 || (current / maximumScroll) > this.decimalLimit) 64 filter(({ current, maximumScroll }) => maximumScroll <= 0 || (current / maximumScroll) > this.decimalLimit)
65 )
70 .subscribe(() => this.nearOfBottom.emit()) 66 .subscribe(() => this.nearOfBottom.emit())
71 67
72 // Scroll up 68 // Scroll up
73 this.scrollUpSub = scrollObservable 69 this.scrollUpSub = scrollObservable
74 // Check we scroll up 70 .pipe(
75 .filter(({ current }) => { 71 // Check we scroll up
76 const res = this.lastCurrentTop > current 72 filter(({ current }) => {
73 const res = this.lastCurrentTop > current
77 74
78 this.lastCurrentTop = current 75 this.lastCurrentTop = current
79 return res 76 return res
80 }) 77 }),
81 .filter(({ current, maximumScroll }) => { 78 filter(({ current, maximumScroll }) => {
82 return current !== 0 && (1 - (current / maximumScroll)) > this.decimalLimit 79 return current !== 0 && (1 - (current / maximumScroll)) > this.decimalLimit
83 }) 80 })
81 )
84 .subscribe(() => this.nearOfTop.emit()) 82 .subscribe(() => this.nearOfTop.emit())
85 83
86 // Page change 84 // Page change
87 this.pageChangeSub = scrollObservable 85 this.pageChangeSub = scrollObservable
88 .distinct() 86 .pipe(
89 .map(({ current }) => this.calculateCurrentPage(current)) 87 distinct(),
90 .distinctUntilChanged() 88 map(({ current }) => this.calculateCurrentPage(current)),
89 distinctUntilChanged()
90 )
91 .subscribe(res => this.pageChanged.emit(res)) 91 .subscribe(res => this.pageChanged.emit(res))
92 } 92 }
93 93