Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request : Debounce the scrollListener #32

Closed
froger opened this issue Oct 23, 2016 · 3 comments
Closed

Feature request : Debounce the scrollListener #32

froger opened this issue Oct 23, 2016 · 3 comments

Comments

@froger
Copy link

froger commented Oct 23, 2016

Hi,
I've passed some time trying to update the orginal react-infinite-scroller and shame on me, I didn't see your fork.

I ended making some improvements on the original script (the one your forked), but the most efficient change I did was to debounce the position checking and loadMore things. I've adapted to my needs, hope it's readable.

The idea is very simple :

  • in the constructor, you set a this.debounceTimeout to null
  • in the scrollListener you check if this.debounceTimeout is null. If yes, you set it to a setTimeout(load_more_if_needed, 250), if not you just pass your way.

As a window.addEventListener("scroll", this.scrollListener); will fire scrollListener a lot of time, and very fast, it's gonna do some calculations all the time. it's better explained there.

I don't have time and enery to make a pull request from your fork, sorry.

@danbovey
Copy link
Owner

danbovey commented Dec 5, 2016

@danbovey danbovey closed this as completed Dec 5, 2016
@anupvarghese
Copy link

Agree to @danbovey , it has to be done on the top level components. One idea is to use CancelTokens (in stage-1) now.
For example, axios supports this feature, see here

@jabacchetta
Copy link

Just getting back into this component and wanted to make sure I understood the reasoning for not implementing this feature. @danbovey @anupvarghese

I believe what I, and others, are referring to... is not so much the loadMore() callback being passed in, but ALL of the code being executed inside scrollListener(). Those calculations are being made hundreds of times per second without a throttle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants