Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Allow to remove all EventEmitter listeners at once #889

Closed
wants to merge 1 commit into from

Conversation

felixge
Copy link

@felixge felixge commented Apr 7, 2011

This patch adds support for calling EventEmitter#removeAllListeners
with no parameters in order to remove all listeners as once.

See discussion: https://groups.google.com/forum/#!topic/nodejs-dev/Mcyal1ThTHY

This does not break the existing API signature, so I think it would be reasonable to consider this patch for 0.4.x.

This patch adds support for calling EventEmitter#removeAllListeners
with no parameters in order to remove all listeners as once.

See discussion: https://groups.google.com/forum/#!topic/nodejs-dev/Mcyal1ThTHY
@tj
Copy link

tj commented Apr 7, 2011

nice ! I wanted this a month or two ago

@xk
Copy link

xk commented Apr 7, 2011

Please Felix make it removeAllListeners_Of_Any_Kind_, the 'ofAnyKind' expressed as '*' :-)

You should have to say exactly what you want to delete, just as rm -R won't work unless you specify a what. You should have to say removeAllListeners( 'OF ANY KIND' ), and to say 'OF ANY KIND', the wildcard '*' is what's used universally, everywhere.

@chrisdickinson
Copy link

It would actually be cool to be able to specify a regexp instead of '*' for "Delete all listeners". This way, if you've got semi-namespaced events, you can delete entire swathes of them with a simple call:

    ee.removeListeners(/myapp.*/);
    // or to remove all:
    ee.removeListeners(/.*/);
    // or to remove a single one:
    ee.removeListeners('error');

@felixge
Copy link
Author

felixge commented Apr 12, 2011

@chrisdickinson regex seems a little too much for the node core for me. A way to get a list of all event types might be a better path?

@chrisdickinson
Copy link

Something like this, maybe:

https://gist.github.com/accd13ca4e2e7e92bc78

@chrisdickinson
Copy link

@felixge oh, sorry, didn't refresh the page before commenting again :) the general idea is that you accept a function that can operate on the event keys, and if it matches, delete those listeners. Since typeof(RegExp) is 'function', it works with regexen for free, or you can specify a callback that accepts the name of the event and the list of listeners.

@ry ry closed this in bc84895 Apr 12, 2011
@ry
Copy link

ry commented Apr 12, 2011

Thanks

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants