-
-
Notifications
You must be signed in to change notification settings - Fork 72
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
Regresssion in PR#96 #97
Comments
Workaround for sindresorhus/emittery#97
// @lukehorvat |
Ouch. Sorry for the oversight. I have one idea. We could have a private let metaEventsAllowed = false;
function withMetaEventsAllowed(callback) {
metaEventsAllowed = true;
callback();
metaEventsAllowed = false;
} So, for example, this code: Lines 261 to 263 in f61b87d
Would become this: if (!isMetaEvent(eventName)) {
withMetaEventsAllowed(() => {
this.emit(listenerAdded, {eventName, listener});
});
} This would eliminate the need for Just a rough idea I had; could probably be improved. But if it sounds fine to you then I'll go ahead and make a PR. |
Yup. Or we can have a special function that emits the meta events on a given emitter instance. Something like this. async function emitMetaEvent(emitter, event, data) {
metaEventsAllowed = true
await emitter.emit(event, data)
metaEventsAllowed = false
} The only benefit of this function over the callback approach is, we will not end up creating too many anonymous functions. if (!isMetaEvent(eventName)) {
emitMetaEvent(this, listenerAdded, {eventName, listener})
} |
👍 Sounds good |
The #96 introduces a regression when emittery is used as a sub-class. Lemme share a code sample.
Adding a listener
foo
will raise an exception from this line https://github.com/sindresorhus/emittery/blob/main/index.js#L262, since it is callingthis.emit
with three arguments.Now, I can update the
emit
method on my class to accept the 3rd argument and pass it tosuper.emit
. However, then TypeScript complains that theemit
method takes only two arguments.The text was updated successfully, but these errors were encountered: