Skip to content

fix infinite loop when scrolling end#278

Open
leekzhu wants to merge 1 commit intosroze:masterfrom
leekzhu:master
Open

fix infinite loop when scrolling end#278
leekzhu wants to merge 1 commit intosroze:masterfrom
leekzhu:master

Conversation

@leekzhu
Copy link

@leekzhu leekzhu commented Apr 26, 2016

The problem has been stated in issue #186 , I found out the infinite loop will occur when using AJAX calls to retrieve data which normally requires the use of infinite-scroll-disabled. When its value switches from true to false, it will trigger scroll function again if checkWhenEnabled is true.
handleInfiniteScrollDisabled = (v) -> scrollEnabled = !v if scrollEnabled && checkWhenEnabled checkWhenEnabled = false handler()
In the handler() function:
if shouldScroll checkWhenEnabled = true if scrollEnabled if scope.$$phase || $rootScope.$$phase scope.infiniteScroll() else scope.$apply(scope.infiniteScroll) else checkWhenEnabled = false
if shouldScroll is always true (when scroll to then end), then checkWhenEnabled is also always true. When we toggle infinite-scroll-disabled in our infinite scroll function, 'handler()' will be constantly triggered by handleInfiniteScrollDisabled() causing infinite scroll function jumps into infinite loop.
I think checkWhenEnabled should be set back to false if the infinite scroll function is able to be triggered in handler() so there is no need for handleInfiniteScrollDisabled to trigger it again:
if shouldScroll checkWhenEnabled = true if scrollEnabled checkWhenEnabled = false if scope.$$phase || $rootScope.$$phase scope.infiniteScroll() else scope.$apply(scope.infiniteScroll) else checkWhenEnabled = false
It works for me.

@graingert
Copy link
Collaborator

@leozhucong hey there, please include tests for this change.

matthewborgman added a commit to VouchLabs/ngInfiniteScroll that referenced this pull request Sep 8, 2016
@graingert graingert force-pushed the master branch 2 times, most recently from 21036ac to 79473ca Compare October 10, 2016 09:22
@logan-jobzmall
Copy link

@graingert @sroze - Any idea when this will be merged? Running into this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants