diff --git a/source/event-emitter.ts b/source/event-emitter.ts index 857f9c4..5ea4070 100644 --- a/source/event-emitter.ts +++ b/source/event-emitter.ts @@ -57,9 +57,13 @@ export class EventEmitter { const listenerEntry: ListenerEntry = { listener, wrappedListener, - ...(debounceMilliseconds !== undefined ? { debounceTime: debounceMilliseconds } : {}), }; + // Set the debounce time if specified. + if (debounceMilliseconds && debounceMilliseconds > 0) { + listenerEntry.debounceTime = debounceMilliseconds; + } + // Add the listener entry to the listeners map. this.#listeners.get(type)?.add(listenerEntry); @@ -94,9 +98,13 @@ export class EventEmitter { listener, wrappedListener: debouncedListener, once: true, - ...(debounceMilliseconds !== undefined ? { debounceTime: debounceMilliseconds } : {}), }; + // Set the debounce time if specified. + if (debounceMilliseconds && debounceMilliseconds > 0) { + listenerEntry.debounceTime = debounceMilliseconds; + } + // Add the listener entry to the listeners map. this.#listeners.get(type)?.add(listenerEntry);