Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Allow to remove all EventEmitter listeners at once #889

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
5 participants

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.

Allow to remove all EventEmitter listeners at once
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 commented Apr 7, 2011

nice ! I wanted this a month or two ago

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.

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 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?

@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 commented Apr 12, 2011

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment