Skip to content

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

Closed
felipedc09 wants to merge 8 commits into
nodejs:masterfrom
felipedc09:doc/emitter
Closed

doc: add example about emitter.emit in events documentation#28374
felipedc09 wants to merge 8 commits into
nodejs:masterfrom
felipedc09:doc/emitter

Conversation

@felipedc09

Copy link
Copy Markdown
Contributor
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

@nodejs-github-botnodejs-github-bot added doc Issues and PRs related to the documentations. events Issues and PRs related to the events subsystem / EventEmitter. labels Jun 21, 2019
Comment threaddoc/api/events.md Outdated
@jasnelljasnell added the code-and-learn Issues related to the Code-and-Learn events and PRs submitted during the events. label Jun 23, 2019

@jasnelljasnell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM with @vsemozhetbyt's nit fixed

Trott
Trott previously requested changes Jun 25, 2019

@TrottTrott left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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');constemitter=newEventEmitter();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 reviewJune 25, 2019 13:55

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

@felipedc09

Copy link
Copy Markdown
ContributorAuthor

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.

Comment threaddoc/api/events.md Outdated

@BridgeARBridgeAR left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM % comments.

Comment threaddoc/api/events.md Outdated
args.forEach((arg) => {
parameters += `${arg}, `;
}
);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

It could also be simplified by using join:

constparameters=args.join(', ');

Comment threaddoc/api/events.md Outdated
// [
// [Function: firstListener],
// [Function: secondListener],
// [Function: thirdListener]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

@Trott

Copy link
Copy Markdown
Member

@TrottTrott added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Jul 30, 2019
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@Trott

Copy link
Copy Markdown
Member

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/.)

@TrottTrott closed this Jul 31, 2019
Trott pushed a commit to Trott/io.js that referenced this pull request Jul 31, 2019
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 pushed a commit that referenced this pull request Aug 2, 2019
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>
@BridgeARBridgeAR mentioned this pull request Aug 6, 2019
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author readyPRs that have at least one approval, no pending requests for changes, and a CI started.code-and-learnIssues related to the Code-and-Learn events and PRs submitted during the events.docIssues and PRs related to the documentations.eventsIssues and PRs related to the events subsystem / EventEmitter.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@felipedc09@Trott@nodejs-github-bot@jasnell@BridgeAR@vsemozhetbyt@ZYSzys