You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
docs,events: ee.once() event ordering differs from documentation #5566
Confirmed on v5.7.0. Either we move this to after this or update the docs. Imho, the code change makes more sense as opposed to saying that listener is removed *then* called since that might cause confusion.
It looks like the documentation was added in 179a7f6 and has always mis documented the function.
Modifying the behavior would be a semver major change. Modifying the documentation would be a semver patch change which could be backported to v4 / v5. In reality the doc change should potentially happen even if the behavior is changed on master.
Is there an advantage to the behavior change aside from accurately following what was documented?
For one, it enforces logically correct ordering. You might want to, for example, log stuff after a handler is run for the last time just before being removed.
It looks like the documentation was added in 179a7f6 and has always mis documented the function.
Modifying the behavior would be a semver major change. Modifying the documentation would be a semver patch change which could be backported to v4 / v5. In reality the doc change should potentially happen even if the behavior is changed on master.
Is there an advantage to the behavior change aside from accurately following what was documented?
—
Reply to this email directly or view it on GitHub.
I was going to submit a PR with @zeusdeux suggested change, but this ends up breaking one of the removeListener tests. Specifically, here we get 'removeListener' instead of 'hello'. This is because the function executing from the original call to once() right here has not completed and so hasn't been removed yet.
I can fix this test, but I wonder if this doesn't illustrate some potential brittleness to this change.
Update:
With the code as it is now, this.removeListener() triggers a removeListener event before the function provided to once. This ensures user-land code can call once('removeListener', ...); from within the body of the original function supplied to once(), and still not receive the 'removeListener' event that is generated by once(). By moving the call to removeListener() to here, user land code ends up receiving the removeListener event that is generated.
I tried changing the removeListener function to not issue a removeListener event here and here if type === 'removeListener', but that ends up breaking expectations here where the removeListener event is expected.
It seems to me, that unless you are willing to accept a possibly breaking change, the best course is to just change the documentation. Two node.js tests expect behavior as it is today. You can be sure user code does as well.
Activity
[-]docs,events: [/-][+]docs,events: ee.once() event ordering differs from documentation[/+]zeusdeux commentedon Mar 4, 2016
Confirmed on
v5.7.0. Either we move this to after this or update the docs. Imho, the code change makes more sense as opposed to saying thatlistener is removed *then* calledsince that might cause confusion.omsmith commentedon Mar 4, 2016
It's also worth noting this has been the behaviour since it was introduced (but I would also prefer fixing the ordering).
MylesBorins commentedon Mar 4, 2016
It looks like the documentation was added in 179a7f6 and has always mis documented the function.
Modifying the behavior would be a semver major change. Modifying the documentation would be a semver patch change which could be backported to v4 / v5. In reality the doc change should potentially happen even if the behavior is changed on master.
Is there an advantage to the behavior change aside from accurately following what was documented?
zeusdeux commentedon Mar 4, 2016
For one, it enforces logically correct ordering. You might want to, for example, log stuff after a handler is run for the last time just before being removed.
lance commentedon Mar 8, 2016
I was going to submit a PR with @zeusdeux suggested change, but this ends up breaking one of the
removeListenertests. Specifically, here we get 'removeListener' instead of 'hello'. This is because the function executing from the original call toonce()right here has not completed and so hasn't been removed yet.I can fix this test, but I wonder if this doesn't illustrate some potential brittleness to this change.
Update:
With the code as it is now,
this.removeListener()triggers aremoveListenerevent before the function provided toonce. This ensures user-land code can callonce('removeListener', ...);from within the body of the original function supplied toonce(), and still not receive the'removeListener'event that is generated byonce(). By moving the call toremoveListener()to here, user land code ends up receiving theremoveListenerevent that is generated.I tried changing the
removeListenerfunction to not issue aremoveListenerevent here and here iftype === 'removeListener', but that ends up breaking expectations here where theremoveListenerevent is expected.It seems to me, that unless you are willing to accept a possibly breaking change, the best course is to just change the documentation. Two node.js tests expect behavior as it is today. You can be sure user code does as well.
omsmith commentedon Apr 11, 2016
@lance @thealphanerd Just a doc update makes sense to me
jasnell commentedon Apr 19, 2016
+1 to doc update.
jasnell commentedon Apr 22, 2016
@nodejs/documentation
doc: correctly document the behavior of ee.once().
doc: Backport ee.once doc clarifications to 4.x.
doc: Backport ee.once doc clarifications to 4.x.
doc: correctly document the behavior of ee.once().