sodiray / radash

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

feat(curry): add `leading` option for function `debounce` and `throttle` #387

Open LynnSha1ng opened 5 months ago

LynnSha1ng commented 5 months ago

Descriptions

test(curry): add test for leading option doc(curry): modify description and examples of leading option in function debounce and throttle type(curry): extract types of the options object of function debounce and throttle as type DebounceConfig and ThrottleConfig.

Checklist

vercel[bot] commented 5 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
radash-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 21, 2024 3:05am
crishoj commented 1 month ago

@sodiray I would very much like this option.

Timing with leading = true, in my understanding:

                Time: 0ms - - - - 100ms - - - - 200ms - - - - 300ms - - - - 400ms - - - -
throttle Invocations: x x x x - - - - - - - - x x x x x x x x x x - - - - - - - - - - - -
  Source Invocations: x - - - - - x - - - - - - x - - - - - - x - - - - - - x - - - - - -
lake2 commented 1 week ago

same need + 1. When will this pr be merged?

aleclarson commented 1 week ago

Hi @LynnSha1ng and @lake2,

The Radashi fork has both a leading option for debounce and a trailing option for throttle (thanks to @crishoj).

You can use it today by installing the beta release (an official release is pending).

pnpm install radashi@beta

P.S. I wrote about the differences between Radashi and Radash here: https://radashi-org.github.io/blog/vs-radash/