Skip to content

Commit

Permalink
Fix delay for scrolled callback
Browse files Browse the repository at this point in the history
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 orizens#198
  • Loading branch information
adrienverge committed Feb 10, 2018
1 parent ed90961 commit f979597
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/services/scroll-register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit f979597

Please sign in to comment.