Skip to content

Repository files navigation

tiny-throttle 🚗

Build Status version npm downloads

A tiny throttle & debounce package.

Install

pnpm add tiny-throttle

or

npm install tiny-throttle

or

<script src="https://unpkg.com/tiny-throttle/dist/tiny-throttle.umd.js"></script>

Then you can find the library on window.tinyThrottle

Usage

import { debounce, throttle } from 'tiny-throttle'

// on click, run a function
// then wait 500 milliseconds from last click to run again on next click
document.getElementById('button').onclick = debounce(
  doSomethingWithNetwork,
  500,
  true,
)

// on click, wait 500 milliseconds after last click then run a function
document.getElementById('button').onclick = debounce(
  doSomethingToTeachUsersToWait,
  500,
)

// on click, run a function, then make sure it doesn't get run more than once
// every 500 milliseconds
document.getElementById('button').onclick = throttle(
  doSomethingWithNetwork,
  500,
)

License

MIT © Ben Williams

About

A tiny throttle and debounce utility

Topics

Resources

Stars

6 stars

Watchers

0 watching

Forks

Releases

Used by

Contributors

Languages