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

Http: Improve finish() callback and code legibility (Fixes #7295) #7378

Closed
wants to merge 4 commits into from

Conversation

originalfoo
Copy link
Contributor

Checklist
  • make -j4 test (UNIX) or vcbuild test nosign (Windows) passes
  • the commit message follows commit guidelines
Affected core subsystem(s)

http

( Specifically _http_outgoing.js: OutgoingMessage.prototype.end method )

Description of change
  1. Converted callback function to arrow function to take advantage of lexical this.
  2. Gathered code relating to finish event together to improve code clarity.
  3. See http: use arrow function to take advantage of lexical this? #7295 for further details.

Take advantage of arrow function lexical `this` to avoid defining a
`self = this` var which was only used once.
Code relating to the `finish` event was split in to two areas of the
parent function. Gathered it together to clarify association within the
script.

Fixes nodejs#7295
per jshint's request!
@nodejs-github-bot nodejs-github-bot added the http Issues or PRs related to the http subsystem. label Jun 23, 2016
if (typeof callback === 'function')
this.once('finish', callback);

var finish = () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think if better if in places like this you use const instead var

Copy link
Contributor Author

@originalfoo originalfoo Jun 23, 2016

Choose a reason for hiding this comment

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

Agreed, will update PR shortly.

EDIT: Done.

@mscdex
Copy link
Contributor

mscdex commented Jun 23, 2016

@Qard
Copy link
Member

Qard commented Jun 23, 2016

LGTM. Nothing else in _http_* emits 'finish' in the other code paths of that function, so it should be all good. 👍

@mscdex
Copy link
Contributor

mscdex commented Jun 23, 2016

LGTM

@mscdex
Copy link
Contributor

mscdex commented Jun 23, 2016

/cc @nodejs/http

@indutny
Copy link
Member

indutny commented Jun 23, 2016

LGTM

1 similar comment
@cjihrig
Copy link
Contributor

cjihrig commented Jun 23, 2016

LGTM

@jasnell
Copy link
Member

jasnell commented Jun 27, 2016

LGTM

jasnell pushed a commit that referenced this pull request Jun 27, 2016
Take advantage of arrow function lexical `this` to avoid defining a
`self = this` var which was only used once.

Code relating to the `finish` event was split in to two areas of the
parent function. Gathered it together to clarify association within the
script.

Fixes: #7295
PR-URL: #7378
Reviewed-By: Stephen Belanger <[email protected]>
Reviewed-By: Brian White <[email protected]>
Reviewed-By: Fedor Indutny <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@jasnell
Copy link
Member

jasnell commented Jun 27, 2016

Landed in 3c09d1b

@jasnell jasnell closed this Jun 27, 2016
Fishrock123 pushed a commit that referenced this pull request Jul 5, 2016
Take advantage of arrow function lexical `this` to avoid defining a
`self = this` var which was only used once.

Code relating to the `finish` event was split in to two areas of the
parent function. Gathered it together to clarify association within the
script.

Fixes: #7295
PR-URL: #7378
Reviewed-By: Stephen Belanger <[email protected]>
Reviewed-By: Brian White <[email protected]>
Reviewed-By: Fedor Indutny <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@Fishrock123 Fishrock123 mentioned this pull request Jul 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
http Issues or PRs related to the http subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants