sodiray / radash

Functional utility library - modern, simple, typed, powerful
https://radash-docs.vercel.app
MIT License
4.1k stars 160 forks source link

allow debounce to trigger on leading (and trailing) edge #408

Open mkresse opened 3 months ago

mkresse commented 3 months ago

Hello,

I would like to propose a feature enhancement for the debounce() function. Currently, debounce() only triggers on the trailing edge. However, in certain use cases, it would be beneficial to have the option to also trigger on the leading edge. This enhancement could significantly improve the perceived performance of an application using this function, as on the start of a series of user actions, an immediate feedback can be given.

The expected behavior would be similar to the debounce implementation in lodash, where both the leading and trailing options are set to true (see "Note" on documentation). This would provide more flexibility and control over the function's behavior, allowing developers to better tailor the function to their specific needs.

Thank you for considering this feature request. I believe this enhancement would be a valuable addition to the radash library.

Best regards.

aleclarson commented 1 month ago

Looks like @LynnSha1ng has implemented this in #387. We'd appreciate this improvement over at radashi-org/radashi if anyone wants to transfer it over. :)

crishoj commented 1 month ago

@aleclarson I took a stab at this, although with falling edge option for throttle instead:

lake2 commented 3 weeks ago

same issue +1