Improve infinite scroll
authorChocobozzz <me@florianbigard.com>
Fri, 9 Mar 2018 08:21:34 +0000 (09:21 +0100)
committerChocobozzz <me@florianbigard.com>
Fri, 9 Mar 2018 08:22:35 +0000 (09:22 +0100)
client/src/app/shared/video/infinite-scroller.directive.ts

index ed49a9e81e63dfa89a6fd2f2fd89af76f7ca6c37..e0f9f4f836fc74b89ec96adc963bc6e44e2bda33 100644 (file)
@@ -38,12 +38,13 @@ export class InfiniteScrollerDirective implements OnInit {
 
   initialize () {
     // Emit the last value
-    const throttleOptions = { leading: false, trailing: true }
+    const throttleOptions = { leading: true, trailing: true }
 
     const scrollObservable = fromEvent(window, 'scroll')
       .startWith(true)
       .throttleTime(200, undefined, throttleOptions)
       .map(() => ({ current: window.scrollY, maximumScroll: document.body.clientHeight - window.innerHeight }))
+      .distinctUntilChanged((o1, o2) => o1.current === o2.current)
       .share()
 
     // Scroll Down