Registry / testing / debounce-queue

debounce-queue

JSON →
library0.4.0jsnpmunverified

Debounce function that returns an array of all unique events that occurred within the debounce window, rather than just the last event like lodash.debounce. Version 0.4.0 is the current stable release; the package is updated irregularly (last release 0.4.0 in 2019). Key differentiator: it batches events into an array, making it ideal for file watchers or event streams where you need to process all pending events, not just the most recent. Simple API with support for leading, trailing, and maxWait options.

npm install debounce-queue
INSTALL
IMPORT
SIG · DEBOUNCE-QUEUE
D
debounce-queue
testingjavascriptv0.4.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import debounce from 'debounce-queue'
const debounce = require('debounce-queue')
ESM default export; CommonJS require works but is not recommended.
debounce
import { debounce } from 'debounce-queue'
import debounce from 'debounce-queue'
Both named and default exports exist; named export is available since v0.4.0.
DebouncedFunction
import type { DebouncedFunction } from 'debounce-queue'
TypeScript type export available if using TS.

Demonstrates debouncing file system watch events, receiving an array of all events that occurred within the wait period.

import debounce from 'debounce-queue'; import { watch } from 'fs'; const debouncedHandler = debounce((events) => { for (const [eventType, filename] of events) { console.log(`Event: ${eventType}, File: ${filename}`); } }, { wait: 200 }); watch('/path/to/dir', (eventType, filename) => { debouncedHandler(eventType, filename); }); // After 200ms of no new events, the handler is called with an array of all unique events.
Debug
Known issues
gotchaThe debounced function returns an array of arrays (tuples), not a flat list. Each element corresponds to the arguments passed to the debounced call.
fix
Access events as arrays: for (const args of result) { const [arg1, arg2] = args; }
affects: >=0.0.0
breakingIn v0.4.0, the package switched to ES modules. CommonJS require() still works via dual package, but named exports differ.
fix
Use import or update require syntax.
affects: >=0.4.0
deprecatedThe default export is deprecated in favor of named export since v0.4.0.
fix
Use named import: import { debounce } from 'debounce-queue'
affects: >=0.4.0
Errors
Common errors & fixes
Cannot find module 'debounce-queue'
Package not installed or not in node_modules.
fix
Run 'npm install debounce-queue'
debounce is not a function
Incorrect import style; default import may be undefined in some bundlers.
fix
Use named import: import { debounce } from 'debounce-queue'
Expected an array of arrays, got undefined
The debounced function was called without arguments, or the handler expects a different shape.
fix
Ensure you invoke the debounced function with the same arguments as your event listener.
Upgrade
Version history
0.4.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
22 hits · last 30 days
node
20
Resources
debounce-queue — npm install debounce-queue · libregistry