Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34.3k
events: pass the original listener added by EventEmitter#once to the removeListener handler#6394
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
DavidCai1111 commented Apr 26, 2016 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
bnoordhuis commented Apr 26, 2016
Why would we go through the trouble of trying to prevent that? Using the |
addaleax commented Apr 26, 2016
I’d say by explicitly invoking the listener in the |
DavidCai1111 commented Apr 26, 2016 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
@addaleax But as the output showed in the first code example, no matter invoking the |
addaleax commented Apr 26, 2016
I have to admit, I find the PR title here a bit confusing then. I think a much cleaner solution (and more aligned with user expectations?) would be to pass the original listener which has been passed to |
DavidCai1111 commented Apr 26, 2016
@addaleax It's a better solution, i will change the code. |
cffb713 to b12c2acCompareDavidCai1111 commented Apr 26, 2016
@addaleax Hey bro, I've changed the code and the content of this PR. Now the user will get the original listener which added by |
addaleax commented Apr 26, 2016
I like the change, but would like to head other’s opinions on this. I think this could be considered a bugfix, because this is how I’d understand the documentation (if I didn’t know how
Appreciate you not wanting to be formal, but I’m definitely not a bro, for more than one reason. :) |
DavidCai1111 commented Apr 26, 2016
I think so, too : = ) |
cjihrig commented Apr 26, 2016
This makes sense, but could you add tests. |
DavidCai1111 commented Apr 26, 2016
@cjihrig 👌 |
b12c2ac to fa40a5aCompareDavidCai1111 commented Apr 26, 2016
@cjihrig Already added : = ) |
sam-github commented Apr 26, 2016
I had no idea the original function wasn't passed, I'd expect the listener passed to once to be the listener passed in the removeListener event! |
DavidCai1111 commented Apr 26, 2016
@sam-github It will be, if this PR merged. |
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.
Both assertions can be assert.strictEqual().
cjihrig commented Apr 26, 2016
LGTM pending comments and CI. Are we classifying this as semver major or patch? I'd lean toward patch, but this could potentially break things. |
fa40a5a to d26733dCompareaddaleax commented Apr 26, 2016
Yeah, I think this breaks only code that is already broken. So, leaning towards patch, too. |
sam-github commented Apr 26, 2016
I lean towards patch, too. |
jasnell commented Apr 27, 2016
Related (covers the same ground): #5564 |
DavidCai1111 commented Apr 27, 2016 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Seems that the solution code in this PR is more lightweight and harmless ? |
simonkcleung commented Apr 28, 2016
Look into #5564 line 338: change to seems more readable. |
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.
might be clearer to just inline listener6 with the removeListener line below instead of creating a separate decl for it
jasnell commented Apr 28, 2016
LGTM with a nit. Pending CI of course. |
jasnell commented Apr 29, 2016
Looks good, landing |
When removing a `once` listener, the listener being passed to the `removeListener` callback is the wrapper. This unwraps the listener so that `removeListener` is passed the actual listener. PR-URL: #6394 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
jasnell commented Apr 29, 2016
Landed in 706778a |
mscdex commented Apr 29, 2016
Shouldn't this be tagged as |
cjihrig commented Apr 29, 2016
Yes. Done. |
cjihrig commented Apr 29, 2016
Wait, I take that back. We talked about this the other day. Most people (myself included) were leaning toward patch. I can see how it would be a major though. |
addaleax commented Apr 29, 2016
That was brought up a few comments up: #6394 (comment) |
jasnell commented Apr 29, 2016
@mscdex ... it could be see discussion here #6394 (comment) ... the existing behavior can be rightfully considered to be a bug and this is just a fix. I'm -1 on it being semver-major. |
jasnell commented Apr 29, 2016
@mscdex ... to be on the safe side we can hold off on pulling this back to v5 or v4 for a while in case there are any regressions caused. |
When removing a `once` listener, the listener being passed to the `removeListener` callback is the wrapper. This unwraps the listener so that `removeListener` is passed the actual listener. PR-URL: #6394 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
When removing a `once` listener, the listener being passed to the `removeListener` callback is the wrapper. This unwraps the listener so that `removeListener` is passed the actual listener. PR-URL: nodejs#6394 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
MylesBorins commented Aug 30, 2016
do you think it is about time ot backport @nodejs/lts? |
MylesBorins commented Oct 10, 2016
@nodejs/lts @nodejs/ctc thoughts on this being backported? |
sam-github commented Oct 12, 2016
I think its reasonable to backport |
When removing a `once` listener, the listener being passed to the `removeListener` callback is the wrapper. This unwraps the listener so that `removeListener` is passed the actual listener. PR-URL: #6394 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
Checklist
Description of change
We use the
_onceWrapfunction to wrap the listener added byEventEmitter#once, and use the flagfiredinside to make sure the listener will only be called once, including the calling in theremoveListenerevent:But by explicitly invoking the listener in the removeListener handler the user expresses a pretty strong intent that the listener should be called. By now we can use a
listener.listenertrick to archive this:But those who have not read the the code of
lib/events.jsshould not know this trick at all, and using tricks is alway not a good way. so this PR is to pass the original listener added byEventEmitter#onceto theremoveListenerhandler: