mini-throttle

A small JavaScript throttle & debounce implementation.

MIT License

Downloads
186.9K
Stars
203
Committers
9
mini-throttle - v2.1.1 Latest Release

Published by manuelpuyol over 1 year ago

What's Changed

New Contributors

Full Changelog: https://github.com/github/mini-throttle/compare/v2.1.0...v2.1.1

mini-throttle -

Published by keithamus over 3 years ago

This updates the package.json to include sideEffects: false which improves tree-shaking in bundlers like WebPack and Rollup. Thanks @stof (#11)

It also updates the TypeScript types for decorator functions.

mini-throttle -

Published by keithamus over 3 years ago

Corrects repository field in package.json

mini-throttle -

Published by keithamus over 3 years ago

This release migrates the codebase to TypeScript, dropping Babel in the process.

The throttle and debounce functions can now pass a receiver (or "this") as an argument.

This also adds new TypeScript decorator support, decorators can be used by importing @github/mini-throttle/decorators

mini-throttle -

Published by keithamus over 3 years ago

Updated some code comments

mini-throttle -

Published by keithamus over 3 years ago

Updated devdependencies.

mini-throttle -

Published by koddsson about 5 years ago

  • Merge pull request #5 from github/publish-to-gpr-as-well 9c42e29
  • Merge branch 'master' into publish-to-gpr-as-well d181bbd
  • publish to GPR as a postpublish step b56e8c4

https://github.com/github/mini-throttle/compare/v1.0.4...v1.0.5

mini-throttle - 1.0.5

Published by koddsson about 5 years ago

mini-throttle

This is a package which provides throttle and debounce functions, with both
flow and TypeScript declarations, and a minimal code footprint (less than 60
lines, less than 350 bytes minified+gzipped)

throttling, debouncing, and everything inbetween

type ThrottleOptions = {
  start?: boolean, // fire immediately on the first call
  middle?: boolean, // if true, fire as soon as `wait` has passed
  once?: boolean, // cancel after the first successful call
}
function throttle<T>(
  callback: (...args: T[]) => any,
  wait: number,
  opts?: ThrottleOptions
): (...args: T[]) => void

function debounce<T>(
  callback: (...args: T[]) => any,
  wait: number,
  opts?: ThrottleOptions
): (...args: T[]) => void

This package comes with two functions; throttle and debounce.

Both of these functions offer the exact same signature, because they're both
the same function - just with different opts defaults:

  • throttle opts default to { start: true, middle: true, once: false }.
  • debounce opts default to { start: false, middle: false, once: false }.

Each of the options changes when callback gets called. The best way to
illustrate this is with a marble diagram.

for (let i = 1; i <= 10; ++i) {
  fn(i)
  await delay(50)
}
await delay(100)
| fn()                                         | 1 2 3 4 5 6 7 8 9 10 |
| throttle(fn, 100)                            | 1 2   4   6   8   10 |
| throttle(fn, 100, {start: false})            |   2   4   6   8   10 |
| throttle(fn, 100, {middle: false})           | 1                 10 |
| throttle(fn, 100, {once: true})              | 1                    |
| throttle(fn, 100, {once: true, start: false})|   2                  |
| debounce(fn, 100)                            |                   10 |
mini-throttle -

Published by koddsson about 5 years ago

  • Merge pull request #6 from github/dependabot/npm_and_yarn/lodash-4.17.15 78c6f96
  • chore(deps): bump lodash from 4.17.11 to 4.17.15 751a312
  • Merge pull request #4 from 38elements/patch-1 d48a9fc
  • chore: fix typo 2411142

https://github.com/github/mini-throttle/compare/v1.0.3...v1.0.4

Package Rankings
Top 2.19% on Npmjs.org