-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
events: Alias EventEmitter.protoype.removeListener as EventEmitter.prototype.off #540
events: Alias EventEmitter.protoype.removeListener as EventEmitter.prototype.off #540
Conversation
I like this -- it feels like a more natural antonym to the |
+1 for a less verbose name |
-1 I don't really thinks it makes sense to 'off' an event. |
+1 for API symmetry/consistency. Several libs implement the |
it's not really symmetry though is it? the "on" is meant to red like: "for this object, on this event, do this", and "off" doesn't quite fit. |
Some famous libraries have jQuery has other front-end libraries also have Some So I feel EventEmitter need to have |
|
I also have seen |
|
-1. on is a nice alias for addListener, and it gets called a lot. removeListener... not so often. increasing the number of aliases confuses the API. node picked a name, lets stick with it. And off is weird. event listeners aren't light switches. "on" has a number of meanings, "off" is the opposite of only some of those meanings. "under" is also an antonym of "on"... but neither "under" nor "off" are antonyms of the meaning of "on" used by EE. |
+0, but i would say this is |
-1. I think it should be |
@cjihrig I believe there's enough -1's to just close this |
hm, no problem. Thank you for your comments. |
This came up again in a very large codebase where we're migrating to an EventEmitter - everything already uses "on" and "off", like most event libs, and we were shocked to find that "on" exists but "off" doesn't. The fact that it's an alias is irrelevant to discoverability or usability imo - if we don't like aliases, great - let's remove "on". If we can't or don't want to remove it (which is fine), then why would it be hard to add a (semver-minor, not major) alias that makes the API more consistent? |
+0 from me. |
I'm going to re-quote @sam-github from above:
If we are going to add something else I think it should be (Even then I'm still -1 though.) |
If we have "forget" we'd need the corresponding english antonym "remember" - which wouldn't make any sense, so I don't think that would work. |
@Fishrock123 Refs:
Edit: updated, added eventemitter3 to the list. |
I'd be surprised if anyone, lacking knowledge of this particular core module quirk, would expect there not to be an |
Again, see the quote, whether or not there's an |
@Fishrock123 it doesn't make sense to you, or to @sam-github. It makes perfect sense to many developers. For example, I might see an event emitter, while not as a light switch, as a switch on a walkie talkie - where when "on", i hear things that come in on the channel, but when i want to stop listening, i turn it "off". There's many kinds of on/off switches so I'm sure we can anecdotally come up with a bunch that do, and a bunch that don't, make sense as metaphors for event emitters, but I don't see how that's convincing or valuable in either direction. |
Ah, I get it, that makes sense I suppose. |
@Fishrock123 The fact how exactly the method opposite to
Almost everyone out there is using The only reason for adding an |
|
Everyone clearly has lots of (valid) colliding subjective opinions on whether "on" or "off" makes sense or not, and on what metaphor makes the most sense for events, et cetera. I don't think we're going to resolve anything to anyone's satisfaction by throwing personal aesthetic preferences back and forth :-) Personally I think all of the above is irrelevant. Unless we're talking about removing "on" - which would be a conceptually major, semver-major breaking change - we're stuck with it for the forseeable future. Therefore, the real question is, what should the API look like? Currently there's a nice pairing of |
fwiw, I retract my |
Any hope of revisiting this, or at least re-gathering -1/0/+1s from folks? |
@ljharb Actually, I'm leaning towards a +1 on this. It will improve interoperability with all the other event emitter libraries on npm, and |
Just a note: this
is not correct anymore. |
I'd still love to see this added. |
Updated stats at #540 (comment), also added |
Adding this alias would also be handy in Socket.io which inherits from EventEmitter. |
Any chance this could get reopened/reconsidered? |
Update: #17156 will theoretically land this in node v10 |
EventEmitter should have
off
alias for io.js beginners, preventing event leaks, API symmetry etc....I understand the historical reason why events does not have
off
alias.nodejs/node-v0.x-archive#3338
nodejs/node-v0.x-archive#5352
Of course, I understand the API of events is frozen in io.js. However io.js have already added the new API
getMaxListeners
.And this change does not break backward compatibility. I really would like to add this alias in io.js.
I know io.js follows semantic versioning. If this changes is not patch version (v1.0.x), I can wait for io.js to merge this change until minor version up (v1.1.x).