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

Throttle rather than debounce? #15

Closed
DanielHeath opened this issue Jan 23, 2020 · 4 comments
Closed

Throttle rather than debounce? #15

DanielHeath opened this issue Jan 23, 2020 · 4 comments

Comments

@DanielHeath
Copy link

With debounce, you can get 'starvation' where new events keep arriving, preventing you from ever re-rendering.

lodash.throttle allows one re-render per 'wait' period, which I think would still achieve the performance aims of this library without allowing the UI to get stuck.

@podefr
Copy link
Owner

podefr commented Jan 30, 2020

Hi Daniel,

Thanks for the suggestion. Does the maxWait option of _.debounce address your issue? Doing something like this should ensure that your component gets rendered at least 4 times per second:

const debouncedMyReactComponent = debounceRender(MyReactComponent, 100, { 
    maxWait: 250 
});

ref: https://lodash.com/docs/#debounce

@DanielHeath
Copy link
Author

That would do it, yeah.

Bit of a thing to trip over newcomers, though. Maybe a note in the sample usage section of the readme?

podefr added a commit that referenced this issue Feb 5, 2020
- Update documentation, addressing issue #15
- Add Thomas0c to list of contributors
- Update to most recent @babel
@podefr
Copy link
Owner

podefr commented Feb 5, 2020

Hi Daniel,

I've updated the documentation to add the maxWait example. It also mentions that lodash debounce is used under the hood and that it can be configured. I hope this addresses the issue you raised?

Let me know if I can close this ticket and thanks for use this lib!

@DanielHeath
Copy link
Author

Looking good!

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

2 participants