| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
Why would we go through the trouble of trying to prevent that? Using the delete operator like that isn't exactly free, either. |
Sorry, something went wrong.
|
I’d say by explicitly invoking the listener in the removeListener handler the user expresses a pretty strong intent that the listener should be called. |
Sorry, something went wrong.
|
@addaleax But as the output showed in the first code example, no matter invoking the listener in the removeListener handler how many times, it will only be called once eventually, unless we do the listener.listener trick. |
Sorry, something went wrong.
|
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 .once() to the removeListener handler, though. That has the additional benifit of no extra work in the case that there is no removeListener handler. |
Sorry, something went wrong.
|
@addaleax It's a better solution, i will change the code. |
Sorry, something went wrong.
|
@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 EventEmitter#once in removeListener handler 👍 |
Sorry, something went wrong.
|
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 .once() was implemented under the hood) and it aligns removeListener with newListener.
Appreciate you not wanting to be formal, but I’m definitely not a bro, for more than one reason. :) |
Sorry, something went wrong.
|
I think so, too : = ) |
Sorry, something went wrong.
|
This makes sense, but could you add tests. |
Sorry, something went wrong.
|
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! |
Sorry, something went wrong.
|
@sam-github It will be, if this PR merged. |
Sorry, something went wrong.
There was a problem hiding this comment.
Both assertions can be assert.strictEqual().
Sorry, something went wrong.
|
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. |
Sorry, something went wrong.
|
Yeah, I think this breaks only code that is already broken. So, leaning towards patch, too. |
Sorry, something went wrong.
|
I lean towards patch, too. |
Sorry, something went wrong.
|
Seems that the solution code in this PR is more lightweight and harmless ? |
Sorry, something went wrong.
|
Look into #5564 line 338: originalListener = list[i].listener; change to originalListener = list[i].listener||listener;
this.emit('removeListener', type, originalListener);
seems more readable. |
Sorry, something went wrong.
There was a problem hiding this comment.
might be clearer to just inline listener6 with the removeListener line below instead of creating a separate decl for it
Sorry, something went wrong.
|
LGTM with a nit. Pending CI of course. |
Sorry, something went wrong.
|
Looks good, landing |
Sorry, something went wrong.
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 <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
|
Shouldn't this be tagged as semver-major? |
Sorry, something went wrong.
|
Yes. Done. |
Sorry, something went wrong.
|
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. |
Sorry, something went wrong.
|
That was brought up a few comments up: #6394 (comment) |
Sorry, something went wrong.
|
@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. |
Sorry, something went wrong.
|
@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. |
Sorry, something went wrong.
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 <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
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 <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
|
do you think it is about time ot backport @nodejs/lts? |
Sorry, something went wrong.
|
@nodejs/lts @nodejs/ctc thoughts on this being backported? |
Sorry, something went wrong.
|
I think its reasonable to backport |
Sorry, something went wrong.
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 <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
| Back | FazBrowse Home | New Git URL |
Checklist
Description of change
We use the _onceWrap function to wrap the listener added by EventEmitter#once, and use the flag fired inside to make sure the listener will only be called once, including the calling in the removeListener event:
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.listener trick to archive this:
But those who have not read the the code of lib/events.js should 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 by EventEmitter#once to the removeListener handler: