Add general off handling
This commit is contained in:
@@ -117,11 +117,17 @@ export class EventEmitter<T extends EventMap> {
|
||||
* @param type - The event type.
|
||||
* @param listener - The listener function.
|
||||
*/
|
||||
off<K extends keyof T>(type: K, listener: Listener<T[K]>): void {
|
||||
off<K extends keyof T>(type: K, listener?: Listener<T[K]>): void {
|
||||
// Get the listeners for the event type.
|
||||
const listeners = this.#listeners.get(type);
|
||||
if (!listeners) return;
|
||||
|
||||
// If no listener is provided, remove all listeners for the event type.
|
||||
if (!listener) {
|
||||
this.#listeners.delete(type);
|
||||
return;
|
||||
}
|
||||
|
||||
// Find the listener entry.
|
||||
const listenerEntry = Array.from(listeners).find((entry) => entry.listener === listener || entry.wrappedListener === listener);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user