-
-
Notifications
You must be signed in to change notification settings - Fork 75
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
Allow setting up emitter #59
Comments
Do you actually need this for something? If so, what? |
This is useful for emitters that require network access for polling or have to subscribe to other event emitters. Here's my use case: const Emittery = require("emittery")
const emitter = new Emittery()
emitter.setup("mouse", () => {
terminal.grabInput({
mouse: "button"
})
terminal.on("mouse", (name, data) => {
// Handle data...
emitter.emit("mouse", data)
})
})
module.exports = emitter |
Alright. I think it needs a "unsetup" hook too then. And a better name than "setup". What naming do other similar packages use? |
@sindresorhus How about |
That's not better. I guess |
👍 |
Just like how Cold Observables set up their emitter when they are first subscribed to, something similar should be done here. Using
Emittery.listenerAdded
, it is possible to detect when events are first listened to so it should be easy to invoke a callback from there.For example:
// @sindresorhus
The text was updated successfully, but these errors were encountered: