Fix removeAllListeners
This commit is contained in:
@@ -133,8 +133,8 @@ export class EventEmitter<T extends EventMap> {
|
||||
listeners.delete(entry);
|
||||
});
|
||||
|
||||
// If no listener was provided, remove the listeners set from the listeners map.
|
||||
if (!listener) {
|
||||
// If no listener was provided and no listeners are left for the event type, remove the listeners set from the listeners map.
|
||||
if (!listener || this.#listeners.get(type)?.size === 0) {
|
||||
this.#listeners.delete(type);
|
||||
}
|
||||
}
|
||||
@@ -169,7 +169,11 @@ export class EventEmitter<T extends EventMap> {
|
||||
* Remove all listeners.
|
||||
*/
|
||||
removeAllListeners(): void {
|
||||
this.#listeners.clear();
|
||||
for (const [ type, listeners ] of this.#listeners.entries()) {
|
||||
listeners.forEach((entry) => {
|
||||
this.off(type, entry.listener);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user