diff --git a/src/modules/infinite-scroll.directive.ts b/src/modules/infinite-scroll.directive.ts index 4f903dd4..5e02956e 100644 --- a/src/modules/infinite-scroll.directive.ts +++ b/src/modules/infinite-scroll.directive.ts @@ -25,12 +25,7 @@ export class InfiniteScroll implements OnDestroy, OnInit { @Input('immediateCheck') _immediate: boolean = false; @Input('horizontal') _horizontal: boolean = false; @Input('alwaysCallback') _alwaysCallback: boolean = false; - @Input() - set debounce(value: string | boolean) { - this.throttleType = value === '' || !!value ? 'debounce' : 'throttle'; - } - private throttleType: string = 'throttle'; private disposeScroller: Subscription; constructor( @@ -50,7 +45,6 @@ export class InfiniteScroll implements OnDestroy, OnInit { }); const options: ScrollRegisterConfig = { container: positionResolver.container, - throttleType: this.throttleType, throttleDuration: this._throttle, filterBefore: () => !this._disabled, mergeMap: () => positionResolver.calculatePoints(this.element), diff --git a/src/services/scroll-register.ts b/src/services/scroll-register.ts index b27823f5..8161f34a 100644 --- a/src/services/scroll-register.ts +++ b/src/services/scroll-register.ts @@ -3,28 +3,25 @@ import { Injectable, ElementRef } from '@angular/core'; import { Observable } from 'rxjs/Observable'; import { Subscription } from 'rxjs/Subscription'; import 'rxjs/add/observable/fromEvent'; -import 'rxjs/add/observable/timer'; import 'rxjs/add/observable/of'; -import 'rxjs/add/operator/debounce'; -import 'rxjs/add/operator/throttle'; +import 'rxjs/add/operator/sampleTime'; import 'rxjs/add/operator/filter'; import 'rxjs/add/operator/mergeMap'; export interface ScrollRegisterConfig { container: ContainerRef; - throttleType: string; throttleDuration: number; - filterBefore: Function; + filterBefore: () => boolean; mergeMap: Function; - scrollHandler: Function; + scrollHandler: (value: any) => void; } @Injectable() export class ScrollRegister { attachEvent (options: ScrollRegisterConfig): Subscription { const scroller$: Subscription = Observable.fromEvent(options.container, 'scroll') - [options.throttleType](() => Observable.timer(options.throttleDuration)) + .sampleTime(options.throttleDuration) .filter(options.filterBefore) .mergeMap((ev: any) => Observable.of(options.mergeMap(ev))) .subscribe(options.scrollHandler); diff --git a/tests/services/scroll-register.spec.ts b/tests/services/scroll-register.spec.ts index 08e629d0..e4c851d2 100644 --- a/tests/services/scroll-register.spec.ts +++ b/tests/services/scroll-register.spec.ts @@ -34,7 +34,6 @@ describe('Scroll Regsiter', () => { mergeMap: (e: any) => e, scrollHandler: (ev: any) => ev, throttleDuration: 300, - throttleType: 'throttle' }; const scroller$: Subscription = scrollRegister.attachEvent(scrollConfig);