https://github.com/biw/tiny-throttle
throttle & debounce package, only 326 bytes, 83% smaller than lodash
https://github.com/biw/tiny-throttle
debounce event-debounce event-throttle javascript jest lodash throttle tiny
Last synced: about 1 year ago
JSON representation
throttle & debounce package, only 326 bytes, 83% smaller than lodash
- Host: GitHub
- URL: https://github.com/biw/tiny-throttle
- Owner: biw
- License: mit
- Created: 2018-02-14T08:58:56.000Z (over 8 years ago)
- Default Branch: main
- Last Pushed: 2023-03-04T04:06:45.000Z (over 3 years ago)
- Last Synced: 2024-03-26T05:43:02.038Z (about 2 years ago)
- Topics: debounce, event-debounce, event-throttle, javascript, jest, lodash, throttle, tiny
- Language: JavaScript
- Homepage:
- Size: 424 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tiny-throttle 🚗
[![Build Status][build-badge]][build]
[![version][version-badge]][package]
[![bundlephobia][bundlephobia-badge]][bundlephobia]
[![MIT License][license-badge]][license]
A throttle & debounce package with a tiny file size.
At only **326 bytes** it is **83% smaller than lodash's `_.debounce()` & `_.throttle()`**
## Install
```bash
yarn add tiny-throttle
```
or
```bash
npm install --save tiny-throttle
```
or
```html
```
Then you can find the library on `window.tinyThrottle`
## Usage
```js
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](https://biwills.com)
[build-badge]: https://img.shields.io/circleci/build/github/biw/tiny-throttle.svg?style=flat-square
[build]: https://app.circleci.com/pipelines/github/biw/tiny-throttle
[version-badge]: https://img.shields.io/npm/v/tiny-throttle.svg?style=flat-square
[package]: https://www.npmjs.com/package/tiny-throttle
[license-badge]: https://img.shields.io/npm/l/tiny-throttle.svg?style=flat-square
[license]: https://github.com/biw/tiny-throttle/blob/main/LICENSE
[bundlephobia]: https://bundlephobia.com/result?p=tiny-throttle
[bundlephobia-badge]: https://img.shields.io/bundlephobia/minzip/tiny-throttle?style=flat-square