Skip to content

biw/tiny-throttle

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

tiny-throttle ๐Ÿš—

Build Status version bundlephobia MIT License

A throttle & debounce package with a tiny file size.

At only 326 bytes it is 83% smaller than lodash's _.debounce() & _.throttle()

Install

yarn add tiny-throttle

or

npm install --save 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 miliseconds 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 miliseconds
document.getElementById('button').onclick = throttle(
  doSomethingWithNetwork,
  500,
)

License

MIT ยฉ Ben Williams