-
Notifications
You must be signed in to change notification settings - Fork 173
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
Cancel debouce #87
Comments
Hey @hlspablo thanks for bringing this up. I don't think I understand the use case. Can you maybe provide some pseudo code for what you're looking for? Just to help me understand :) |
const req = debounce({ delay: 100 }, makeSearchRequest) where req.cancel() cancel the makeSearchRequest execution if called before the delay. It can be very handy in a lot of scenarios. |
I see how this could be helpful, happy to build it (or merge a PR if someone else wants to build it) to support it. One question, since I've never needed it personally, to make sure I understand the behavior: Should |
in a simpler implementation, should cancel all future invocations, maybe in the future it could evolve to cancel n invocations passed to cancel, but I think that cancelling all should help 99% of use cases. |
@hlspablo I'm developing a beta version that solves this problem and I managed to solve it for both future and past debounces, but with that I have a doubt. I'm looking at lodash and it has flush and pending methods. If you find it interesting, I can add it too. |
@MarlonPassos-git I don't think that this complexity is necessary, make it work again is almost the same of calling the debounced func with new parameters. I like the ideia of implementing flush too, could be very useful to fire the debounced functions immediately. @rayepps what do you think? |
I like the idea of making it as simple as create and cancel. In a way, the debounce can be immutable. If you need to pause you can cancel then create a new function when you want to resume. |
A simple immutable debounce, with cancel and flush methods looks perfect to me. |
This is out and available in v10.1.0 🚀 |
there is some way to cancel debounced function's execution?, this is a very useful use case and since this lib wants to replace lodash, a think this is a must have
The text was updated successfully, but these errors were encountered: