tiny-throttle
v2.0.0
Published
๐ A tiny throttle & debounce package
Downloads
554
Readme
tiny-throttle ๐
A tiny throttle & debounce package.
Install
pnpm add tiny-throttleor
npm install tiny-throttleor
<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
