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 does not throttle on first call #55

Closed
yanickrochon opened this issue Apr 14, 2022 · 4 comments
Closed

Throttle does not throttle on first call #55

yanickrochon opened this issue Apr 14, 2022 · 4 comments

Comments

@yanickrochon
Copy link

The following declearation does not do anything if the function is called only once :

const t = throttle(100, () => {
  console.log("OK");
}, { noLeading:true });

t();   // will never output anything

Essentially, I am expecting throttle to call the function at least once every 100 ms (in this case), but the function never gets called.

Using debounce won't work because, if the function is called many times, I want the function to throttle, not be debounced, but I don't want the function to be executed immediately; the first call should be debounced.

The current implementation is in error to me.

@niksy
Copy link
Owner

niksy commented Apr 14, 2022

@seiyab do you have some input here?

@seiyab
Copy link
Contributor

seiyab commented Apr 14, 2022

I reproduced it here.
https://codesandbox.io/s/muddy-monad-k7hx36?file=/src/index.js

Calling throttled-function just single time just skips leading call and doesn't schedule first call.
This behavior is confusing and we can call it bug.
I fix it.

seiyab added a commit to seiyab/throttle-debounce that referenced this issue Apr 14, 2022
@seiyab
Copy link
Contributor

seiyab commented Apr 14, 2022

I'm sorry for the inconvenience 🙏 #56

@niksy niksy closed this as completed in 8dc4909 Apr 15, 2022
@niksy
Copy link
Owner

niksy commented Apr 15, 2022

This has been released in https://github.com/niksy/throttle-debounce/releases/tag/v4.0.1

Thanks @seiyab for fixing!

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

3 participants