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

feat(throttle): add trailing option #127

Merged
merged 10 commits into from
Jul 23, 2024

Conversation

crishoj
Copy link
Contributor

@crishoj crishoj commented Jul 21, 2024

Tip

The owner of this PR can publish a preview release by commenting /publish in this PR. Afterwards, anyone can try it out by running pnpm add radashi@pr<PR_NUMBER>.

Summary

This adds a trailing option for throttle, which results in the source function being invoked again after interval in case any calls were ignored during the throttled period.

This is useful for situations where an observable is frequently changing, and we wish to throttle an observer without missing any updates.

Related issue, if any:

sodiray/radash#387

For any code change,

  • Related documentation has been updated, if needed
  • Related tests have been added or updated, if needed
  • Related benchmarks have been added or updated, if needed

Does this PR introduce a breaking change?

No

@crishoj crishoj requested a review from aleclarson as a code owner July 21, 2024 11:50
@crishoj crishoj changed the title add falling option for throttle feat: add falling option for throttle Jul 21, 2024
@crishoj crishoj changed the title feat: add falling option for throttle feat: add trailing option for throttle Jul 21, 2024
@crishoj
Copy link
Contributor Author

crishoj commented Jul 21, 2024

Corrected a few defects:

  1. The option is now called trailing.
  2. Throttling after a trailing call wasn't effective.

@aleclarson aleclarson added the new feature This PR adds a new function or extends an existing one label Jul 23, 2024
when invoked. When the returned function is invoked it will only call the source
function if the `interval` milliseconds of time has passed. Otherwise, it will ignore
the invocation.
The `throttle` function creates a new function that, when called, will only execute the original function at most once per specified time interval. This is useful for limiting the rate at which a function can fire, especially for performance-intensive operations like handling scroll or resize events.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better!

@aleclarson aleclarson changed the title feat: add trailing option for throttle feat(throttle): add trailing option Jul 23, 2024
@aleclarson aleclarson merged commit 0480a16 into radashi-org:main Jul 23, 2024
1 of 4 checks passed
@aleclarson
Copy link
Member

Merging this with a failed test, which will be fixed in another PR.

@crishoj
Copy link
Contributor Author

crishoj commented Jul 23, 2024

Merging this with a failed test, which will be fixed in another PR.

Thanks for the cleanup and refactoring!

@aleclarson
Copy link
Member

Thanks for contributing @crishoj. 👍 👍 Please keep up the great work :)

I'll get to your other PR soon, but have some stuff to finish for the documentation site.

Copy link

A new beta version 12.2.0-beta.83909af has been published to NPM. 🚀

To install:

pnpm add radashi@12.2.0-beta.83909af

The radashi@beta tag also includes this PR.

See the changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature This PR adds a new function or extends an existing one
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants