https://github.com/fabiospampinato/dettle-batch
A batched debouncing and throttling solution, for performance.
https://github.com/fabiospampinato/dettle-batch
batch debounce dettle performance throttle
Last synced: 11 months ago
JSON representation
A batched debouncing and throttling solution, for performance.
- Host: GitHub
- URL: https://github.com/fabiospampinato/dettle-batch
- Owner: fabiospampinato
- License: mit
- Created: 2023-04-24T15:56:33.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2024-04-04T22:36:37.000Z (about 2 years ago)
- Last Synced: 2024-10-06T05:27:40.718Z (over 1 year ago)
- Topics: batch, debounce, dettle, performance, throttle
- Language: JavaScript
- Homepage:
- Size: 5.86 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# Dettle Batch
A batched debouncing and throttling solution, for performance.
This allows you to construct debounce and throttle functions based on [`dettle`](https://github.com/fabiospampinato/dettle) where multiple callbacks using the same options are scheduled together, so a single timeout is used to schedule all of them, rather than one for each.
## Install
```sh
npm install dettle-batch
```
## Usage
```ts
import {createDebounce, createThrottle} from 'dettle-batch';
// Let's debounce multiple handlers for the same DOM event together, for performance
const debounce = createDebounce ();
document.addEventListener ( 'focusin', debounce ( onFocusChange1, 50 ) );
document.addEventListener ( 'focusout', debounce ( onFocusChange1, 50 ) );
document.addEventListener ( 'focusin', debounce ( onFocusChange2, 50 ) );
document.addEventListener ( 'focusout', debounce ( onFocusChange2, 50 ) );
// Let's throttle multiple handlers for the DOM event together, for performance
const throttle = createThrottle ();
document.addEventListener ( 'focusin', throttle ( onFocusChange1, 50 ) );
document.addEventListener ( 'focusout', throttle ( onFocusChange1, 50 ) );
document.addEventListener ( 'focusin', throttle ( onFocusChange2, 50 ) );
document.addEventListener ( 'focusout', throttle ( onFocusChange2, 50 ) );
```
## License
MIT © Fabio Spampinato