Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cfware/debouncer
Debouncer class
https://github.com/cfware/debouncer
Last synced: about 2 months ago
JSON representation
Debouncer class
- Host: GitHub
- URL: https://github.com/cfware/debouncer
- Owner: cfware
- License: mit
- Created: 2019-01-21T02:37:52.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-10-15T15:59:51.000Z (about 1 year ago)
- Last Synced: 2024-11-18T11:16:26.209Z (about 2 months ago)
- Language: JavaScript
- Size: 44.9 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# @cfware/debouncer [![NPM Version][npm-image]][npm-url]
Debouncer class
## Usage
```js
import Debouncer from '@cfware/debouncer';const debouncer = new Debouncer(() => {
console.log('debounced callback');
});// Only run the callback once.
debouncer.run();
setTimeout(() => debouncer.run(), 50);
```## debouncer = new Debouncer(callback, delay, maxDelays)
* `callback` is the callback which is to be rate controlled. Required, must be a function.
* `delay` is the number of milliseconds to wait before running the callback. Optional, default `100`.
* `maxDelays` maximum number of full delays before `callback` is run. Optional, default `2`.### debouncer.run(immediately = false)
This schedules a call to the callback.
If `immediately` is enabled the callback is run immediately.
### debouncer.flush()
This forces the callback to run immediately.
### debouncer.clear()
Cancel any scheduled runs of the callback.
[npm-image]: https://img.shields.io/npm/v/@cfware/debouncer.svg
[npm-url]: https://npmjs.org/package/@cfware/debouncer