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

doc: add example about emitter.emit in events documentation #28374

Closed
wants to merge 8 commits into from

Conversation

@felipedc09
Copy link
Contributor

commented Jun 21, 2019

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
doc/api/events.md Outdated Show resolved Hide resolved
@jasnell
Copy link
Member

left a comment

LGTM with @vsemozhetbyt's nit fixed

@Trott
Copy link
Member

left a comment

Welcome @felipedc09 and thanks for the pull request. If the purpose is to provide a straightforward and understandable example using emitter.event(), can we simplify this? I'm not sure we need three different events and a class too. Might it not be better to keep it simple along these lines?

const  { EventEmitter } = require('events');
const emitter = new EventEmitter();
emitter.on('event', (arg1, arg) => { console.log('args', arg1, arg2); });
emitter.emit('event', 'arg 1', 'arg 2');
// Prints: args arg 1 arg 2

@Trott Trott dismissed their stale review Jun 25, 2019

not blocking, it's a comment, it can always happen after this lands

@felipedc09

This comment has been minimized.

Copy link
Contributor Author

commented Jun 26, 2019

Sure @Trott i like your comments, I will change the class but the emitter.emit is using to run synchronously the listeners associated to event, so I want explain the execution of these listeners respect their creation. thanks.

doc/api/events.md Outdated Show resolved Hide resolved
felipedc09 added 3 commits Jun 30, 2019
@Trott
Trott approved these changes Jul 1, 2019
@ZYSzys
ZYSzys approved these changes Jul 4, 2019
@BridgeAR
Copy link
Member

left a comment

LGTM % comments.

args.forEach((arg) => {
parameters += `${arg}, `;
}
);

This comment has been minimized.

Copy link
@BridgeAR

BridgeAR Jul 4, 2019

Member

Please move this closing bracket to the line above. It's otherwise a bit confusing.

It could also be simplified by using join:

  const parameters = args.join(', ');
// [
// [Function: firstListener],
// [Function: secondListener],
// [Function: thirdListener]

This comment has been minimized.

Copy link
@BridgeAR

BridgeAR Jul 4, 2019

Member

Super tiny nit: the indentation seems off. To keep it aligned with the starting bracket, it needs another whitespace.

Trott added 3 commits Jul 30, 2019
@Trott

This comment has been minimized.

@Trott Trott added the author ready label Jul 30, 2019

@nodejs-github-bot

This comment has been minimized.

@Trott

This comment has been minimized.

Copy link
Member

commented Jul 31, 2019

Landed in 698d479.

Thanks for the contribution! 🎉

(If you're interested in other possible contributions to Node.js but don't have a good idea of where to start looking, some ideas are posted at https://www.nodetodo.org/next-steps/.)

@Trott Trott closed this Jul 31, 2019

Trott added a commit to Trott/io.js that referenced this pull request Jul 31, 2019
doc: add example about emitter.emit in events documentation
PR-URL: nodejs#28374
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
targos added a commit that referenced this pull request Aug 2, 2019
doc: add example about emitter.emit in events documentation
PR-URL: #28374
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
@BridgeAR BridgeAR referenced this pull request Aug 6, 2019
JeniaBR added a commit to JeniaBR/node that referenced this pull request Sep 11, 2019
doc: add example about emitter.emit in events documentation
PR-URL: nodejs#28374
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
JeniaBR added a commit to JeniaBR/node that referenced this pull request Sep 11, 2019
doc: add example about emitter.emit in events documentation
PR-URL: nodejs#28374
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants
You can’t perform that action at this time.