-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EventEmitter#eventNames() and Symbol support #7
Conversation
for (event in this.ee._events) { | ||
if (has.call(this.ee._events, event)) args.push(event); | ||
for (event in ee._events) { | ||
if (has.call(ee._events, event)) args.push(event); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is possible that we are in a browser that doesn't have Object.create
support and this is an instance of EventEmitter3
< 1.2.0.
In this case we fill the array with prefixed event names, and this will obviously fail below when we get the listeners via ee.listeners(name)
as our name will be prefixed again.
The ideal solution would be to detect if this is an instance of EventEmitter3
and in that case see if it is prefixed and slice the event name accordingly.
The problem here is that in order to do this cleanly we need to add a new method to EventEmitter3
and publish it as 1.1.2
. Another option would be something like this:
var EE3;
try {
EE3 = require('eventemitter3');
} catch(e) {};
and check if ee
is an instance of EE3
but this seems fragile.
Do you have better ideas?
This addresses #6 and add support for symbols.
While I was writing this, I found an issue (see inline comments) that should be fixed, so don't merge it yet.