Skip to content
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

lib: bind functions on EventEmitter #27427

Closed
wants to merge 1 commit into from
Closed

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.

lib/events.js Outdated Show resolved Hide resolved
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