From f979597f2f46a28bb00ed4ffbf6bfbc34e9a6913 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Verg=C3=A9?= Date: Sat, 10 Feb 2018 09:50:35 +0100 Subject: [PATCH] Fix delay for `scrolled` callback Multiple users (including me) report a problem: the scroll function callback is called many seconds after it should be. It's not clear if the problem comes from `ngx-infinite-scroll` or another library (`RxJS`?). However, there's a simple fix that allows solving the bug by using `infiniteScrollThrottle="0"`. Let's apply it! Fixes https://github.com/orizens/ngx-infinite-scroll/issues/198 --- src/services/scroll-register.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/services/scroll-register.ts b/src/services/scroll-register.ts index 53c004e4..cc29cd97 100644 --- a/src/services/scroll-register.ts +++ b/src/services/scroll-register.ts @@ -63,9 +63,14 @@ export function createScroller(config: Models.IScroller) { } export function attachScrollEvent(options: Models.IScrollRegisterConfig): Observable<{}> { - return Observable - .fromEvent(options.container, 'scroll') - .sampleTime(options.throttle); + let obs = Observable.fromEvent(options.container, 'scroll'); + // For an unknown reason calling `sampleTime()` causes trouble for many users, even with `options.throttle = 0`. + // Let's avoid calling the function unless needed. + // See https://github.com/orizens/ngx-infinite-scroll/issues/198 + if (options.throttle) { + obs = obs.sampleTime(options.throttle); + } + return obs; } export function toInfiniteScrollParams(