Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yhzion/simple-lazy-debounce
Lazy delay support debounce function
https://github.com/yhzion/simple-lazy-debounce
Last synced: about 1 month ago
JSON representation
Lazy delay support debounce function
- Host: GitHub
- URL: https://github.com/yhzion/simple-lazy-debounce
- Owner: yhzion
- License: mit
- Created: 2023-11-20T09:15:46.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-09-06T06:12:19.000Z (4 months ago)
- Last Synced: 2024-11-09T10:48:02.830Z (about 2 months ago)
- Language: HTML
- Size: 634 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Simple Lazy Debounce
Simple Lazy Debounce is a lightweight JavaScript library that provides a simple way to debounce function calls.
If a function call is made within the `defaultDelay` time, the delay is incremented by `latencyIncrement`, up to the value of `maxDelay`. For example, if there were 5 calls every 100 ms, the function would be executed once at 1001 ms.
## Installation
You can install Simple Lazy Debounce using npm:
```shell
npm install simple-lazy-debounce
```## Usage
```javascript
import { SimpleLazyDebounce } from "simple-lazy-debounce";const logMessage = (message, additionalInfo) => {
console.log(`Message: ${message}, Info: ${additionalInfo}`);
};// Create a debounced function
const debouncedLogMessage = SimpleLazyDebounce(logMessage, {
defaultDelay: 300, // ms
maxDelay: 1000, // ms
latencyIncrement: 200, // ms
});// Call the debounced function with arguments
debouncedLogMessage("Hello", "This is a test"); // First call
debouncedLogMessage("Hello again", "Another test"); // Second call// The first call will be executed after 300ms,
// and the second call will be executed 500ms after the first call
// console output after 300ms: Message: Hello, Info: This is a test
// console output after an additional 500ms: Message: Hello again, Info: Another test
```## Changelog
For detailed changelog, see the CHANGELOG.md file.