Uh oh!
There was an error while loading. Please reload this page.
events: Alias EventEmitter.protoype.removeListener as EventEmitter.prototype.off - #540
events: Alias EventEmitter.protoype.removeListener as EventEmitter.prototype.off #540yosuke-furukawa wants to merge 2 commits into
Conversation
quantizor
commented
Jan 22, 2015
I like this -- it feels like a more natural antonym to the |
tellnes
commented
Jan 22, 2015
+1 for a less verbose name |
toastynerd
commented
Jan 22, 2015
-1 I don't really thinks it makes sense to 'off' an event. |
ruimarinho
commented
Jan 23, 2015
+1 for API symmetry/consistency. Several libs implement the |
rvagg
commented
Jan 23, 2015
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. |
yosuke-furukawa
commented
Jan 23, 2015
Some famous libraries have jQuery has other front-end libraries also have Some So I feel EventEmitter need to have |
wavded
commented
Jan 23, 2015
|
yosuke-furukawa
commented
Jan 23, 2015
I also have seen |
Fishrock123
commented
Jan 23, 2015
|
sam-github
commented
Jan 23, 2015
-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. |
jonathanong
commented
Jan 28, 2015
+0, but i would say this is |
cjihrig
commented
Jan 28, 2015
-1. I think it should be |
rvagg
commented
Jan 28, 2015
@cjihrig I believe there's enough -1's to just close this |
yosuke-furukawa
commented
Jan 28, 2015
hm, no problem. Thank you for your comments. |
ljharb
commented
Nov 4, 2015
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? |
ChALkeR
commented
Nov 4, 2015
+0 from me. |
Fishrock123
commented
Nov 4, 2015
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.) |
ljharb
commented
Nov 4, 2015
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. |
ljharb
commented
Nov 5, 2015
I'd be surprised if anyone, lacking knowledge of this particular core module quirk, would expect there not to be an |
Fishrock123
commented
Nov 5, 2015
Again, see the quote, whether or not there's an |
ljharb
commented
Nov 5, 2015
@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. |
Fishrock123
commented
Nov 5, 2015
Ah, I get it, that makes sense I suppose. |
ChALkeR
commented
Nov 5, 2015
@Fishrock123 The fact how exactly the method opposite to
Almost everyone out there is using The only reason for adding an |
thefourtheye
commented
Nov 5, 2015
|
ljharb
commented
Nov 5, 2015
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 |
sam-github
commented
Nov 27, 2015
fwiw, I retract my |
ljharb
commented
Mar 15, 2016
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 |
ChALkeR
commented
Jun 17, 2016
Just a note: this
is not correct anymore. |
ljharb
commented
Jun 17, 2016
I'd still love to see this added. |
ChALkeR
commented
Jun 25, 2016
Updated stats at #540 (comment), also added |
Delapouite
commented
Jul 18, 2016
Adding this alias would also be handy in Socket.io which inherits from EventEmitter. |
ljharb
commented
Apr 22, 2017
Any chance this could get reopened/reconsidered? |
ljharb
commented
Apr 12, 2018
Update: #17156 will theoretically land this in node v10 |
EventEmitter should have
offalias for io.js beginners, preventing event leaks, API symmetry etc....I understand the historical reason why events does not have
offalias.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).