Skip to content

Conversation

@himself65
Copy link
Member

@himself65 himself65 commented Apr 26, 2019

Further modifications from #27325

bind some functions on EventEmitter so that we no need to change two functions at the same time.

for example:

before

Socket.prototype.on = function(){};
Socket.prototype.addListener = Socket.prototype.on;

now only need to code one line

Socket.prototype.on = function(){};
// or
Socket.prototype.addListener = function(){};
Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added the events Issues and PRs related to the events subsystem / EventEmitter. label Apr 26, 2019
@himself65 himself65 force-pushed the fix2 branch 3 times, most recently from 0672e7a to 88cfac6 Compare April 26, 2019 16:55
@mscdex
Copy link
Contributor

mscdex commented Apr 26, 2019

Copy link
Contributor

@Fishrock123 Fishrock123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A comparative benchmark run for the events benchmarks would probably be desirable.

assert.strictEqual(E.off, E.removeListener);

E.on = function() {};
assert.strictEqual(E.on, E.addListener);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would this ever be the desired behavior? It breaks the principle of least surprise.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.on is just an alias to .addListener. This does prevent some issues where someone wants to change the functionality but forgets to update all functions involved. I guess in this specific case it's fine therefore?

@himself65
Copy link
Member Author

close this pull request, because I think this may break the coding style of some people

@himself65 himself65 closed this May 18, 2019
@himself65 himself65 deleted the fix2 branch May 18, 2019 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

events Issues and PRs related to the events subsystem / EventEmitter.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants