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 trigger method to ThrottleFunction #135

Merged
merged 4 commits into from
Jul 23, 2024

Conversation

aleclarson
Copy link
Member

@aleclarson aleclarson commented Jul 23, 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

The trigger method lets you skip the throttle queue and invoke the function immediately. This will reset the throttle timeout too.

const logMessage = (message: string) => {
  console.log(`Message: ${message}`)
}
const throttledLog = throttle({ interval: 1000 }, logMessage)

throttledLog('First call')  // Logs immediately
throttledLog('Throttled')   // Doesn't log (throttled)

// Force a log, bypassing the throttle
throttledLog.trigger('Forced log')  // Logs immediately

// Check if it's still throttled
throttledLog.isThrottled()  // => true

For any code change,

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

Does this PR introduce a breaking change?

No

Bundle impact

Status File Size Difference (%)
M src/curry/throttle.ts 262 1 +26 (+11%)

Footnotes

  1. Function size includes the import dependencies of the function.

@aleclarson aleclarson marked this pull request as ready for review July 23, 2024 18:52
@aleclarson aleclarson merged commit ac3f6d9 into main Jul 23, 2024
1 of 4 checks passed
@aleclarson aleclarson deleted the feat/throttle-trigger-fn branch July 23, 2024 19:02
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
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant