-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
stream: name anonymous functions #9130
Conversation
@@ -50,7 +50,7 @@ util.inherits(Transform, Duplex); | |||
|
|||
|
|||
function TransformState(stream) { | |||
this.afterTransform = function(er, data) { | |||
this.afterTransform = function _afterTransform(er, data) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why add the _
prefix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to avoid conflict with afterTransform
that is called on next line.
lib/_stream_wrap.js
Outdated
@@ -16,26 +16,26 @@ function StreamWrap(stream) { | |||
this._list = null; | |||
|
|||
const self = this; | |||
handle.close = function(cb) { | |||
handle.close = (cb) => { | |||
debug('close'); | |||
self.doClose(cb); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since these are being changed to arrow functions, the self
can be switched to this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oups, you're right, thanks
lib/_stream_readable.js
Outdated
@@ -714,7 +714,7 @@ function nReadingNextTick(self) { | |||
|
|||
// pause() and resume() are remnants of the legacy readable stream API | |||
// If the user uses them, then switch into old mode. | |||
Readable.prototype.resume = function() { | |||
Readable.prototype.resume = function Readable_resume() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use a camel case name like readableResume
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking to change it to _resume
, in order to be consistent
@@ -50,7 +50,7 @@ util.inherits(Transform, Duplex); | |||
|
|||
|
|||
function TransformState(stream) { | |||
this.afterTransform = function(er, data) { | |||
this.afterTransform = function _afterTransform(er, data) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to avoid conflict with afterTransform
that is called on next line.
I wonder if some of these changes, like |
@lpinca I just look at those and we both change _stream_wrap.js but in different lines, so it shouldn't conflict, but thank for pointing it out, I didn't review other PRs |
@maasencioh my bad, I thought #9113 was proposing an eslint rule to check if names matched. Ignore me. |
2d4565b
to
5a04861
Compare
@jasnell not all the |
c133999
to
83c7a88
Compare
lib/_stream_readable.js
Outdated
@@ -714,7 +714,7 @@ function nReadingNextTick(self) { | |||
|
|||
// pause() and resume() are remnants of the legacy readable stream API | |||
// If the user uses them, then switch into old mode. | |||
Readable.prototype.resume = function() { | |||
Readable.prototype.resume = function _resume() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe call this one resume
and rename the local function to resumeReadable
?
5a04861
to
3914124
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM if CI is green
I'm not sure that the CI failures are related to the changes |
@jasnell sorry it's anything else needed in this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some nits.
lib/_stream_wrap.js
Outdated
handle.onwrite = function(req, bufs) { | ||
return self.doWrite(req, bufs); | ||
handle.onwrite = (req, bufs) => { | ||
return this.doWrite(req, bufs); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please revert all of those to function
and name them?
lib/_stream_wrap.js
Outdated
// Ensure that write was dispatched | ||
setImmediate(function() { | ||
setImmediate(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please name this one?
lib/_stream_wrap.js
Outdated
self.stream.write(buf, done); | ||
this.stream.cork(); | ||
bufs.forEach((buf) => { | ||
this.stream.write(buf, done); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please convert this forEach
in a for loop, it can probably save us a couple of ticks.
lib/_stream_wrap.js
Outdated
@@ -131,7 +131,7 @@ StreamWrap.prototype.doWrite = function doWrite(req, bufs) { | |||
pending = 0; | |||
|
|||
// Ensure that write was dispatched | |||
setImmediate(function() { | |||
setImmediate(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please name this?
lib/_stream_wrap.js
Outdated
setImmediate(function() { | ||
while (self._list !== null) { | ||
const item = self._list; | ||
setImmediate(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be named as well, also can you make this function top level, so that the for loop under can be optimized.
@maasencioh would you mind addressing the comments above? We can land this! |
Hello @mcollina, I thought that this was forgotten, but here I just added the new nits |
lib/_stream_readable.js
Outdated
@@ -613,7 +613,7 @@ Readable.prototype.pipe = function(dest, pipeOpts) { | |||
}; | |||
|
|||
function pipeOnDrain(src) { | |||
return function() { | |||
return () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not name this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry I miss that one, I'll check on the other ones
lib/_stream_readable.js
Outdated
var state = this._readableState; | ||
var paused = false; | ||
|
||
var self = this; | ||
stream.on('end', function() { | ||
stream.on('end', function end() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to ignore, but I prefer naming handlers like onEnd
, onData
, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure which name could be more useful, so this comments are great, thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of nits and we are good to go.
Can you squash the commits as well?
lib/_stream_writable.js
Outdated
if (realHasInstance.call(this, object)) | ||
return true; | ||
|
||
return object && object._writableState instanceof WritableState; | ||
} | ||
}); | ||
} else { | ||
realHasInstance = function(object) { | ||
realHasInstance = function realHasInstance(object) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this have a different name? Like _hasInstancePolyfill
?
lib/_stream_writable.js
Outdated
@@ -134,15 +134,15 @@ var realHasInstance; | |||
if (typeof Symbol === 'function' && Symbol.hasInstance) { | |||
realHasInstance = Function.prototype[Symbol.hasInstance]; | |||
Object.defineProperty(Writable, Symbol.hasInstance, { | |||
value: function(object) { | |||
value: function value(object) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we name this writableHasInstance
?
1372b18
to
3b05cc4
Compare
how does it looks now @mcollina? |
lib/_stream_wrap.js
Outdated
while (self._list !== null) { | ||
const item = self._list; | ||
const req = item.req; | ||
self._dequeue(item); | ||
this._dequeue(item); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are you sure you can use this
here?
lib/_stream_wrap.js
Outdated
|
||
setImmediate(function() { | ||
function setImmediateDoClose () { | ||
while (self._list !== null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self is not defined anymore in this function.
lib/_stream_wrap.js
Outdated
// Do not invoke callback twice | ||
if (!self._dequeue(item)) | ||
if (!this._dequeue(item)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this
?
lib/_stream_wrap.js
Outdated
debug('close'); | ||
self.doClose(cb); | ||
this.doClose(cb); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please revert this to self
?
@maasencioh can you swash all the streams commit into one? I think it'd be easier to move around. |
3b05cc4
to
ca69508
Compare
@mcollina I took my time to make it completely like it should be, I changed everything, but I hope that all it's correct now |
lib/_stream_readable.js
Outdated
@@ -120,7 +120,7 @@ function Readable(options) { | |||
// This returns true if the highWaterMark has not been hit yet, | |||
// similar to how Writable.write() returns true if you should | |||
// write() some more. | |||
Readable.prototype.push = function(chunk, encoding) { | |||
Readable.prototype.push = function readablePush (chunk, encoding) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the norm is to omit the space after the function name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TimothyGu any tip to run the linter and test only on this files? thanks
lib/_stream_readable.js
Outdated
state.length === 0); | ||
(state.needReadable || | ||
state.length < state.highWaterMark || | ||
state.length === 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you restore these spaces?
b930d7b
to
c9d14dd
Compare
a4307a1
to
b7dc912
Compare
@mcollina what do you think now? any tip to run the linter and test only on this files? thanks |
@maasencioh run |
LGTM if ci is green. |
@jasnell @mcollina @targos could you please help me whith this doubt? I renamed a function as proposed like this: Object.defineProperty(Writable, Symbol.hasInstance, {
value: function writableHasInstance(object) {
if (realHasInstance.call(this, object))
return true;
return object && object._writableState instanceof WritableState;
}
}); But currently this throws a jslint error
Should I follow the |
@maasencioh I think you can go ahead and leave that function anonymous. |
@maasencioh, alternatively, you can use an ESLint annotation to suppress that error. See this example in |
There hasn't been any activity here. I'm closing this. Feel free to reopen (or ping a collaborator) if I closed this in error. |
Checklist
make -j8 test
Description of change
Ref: #8913
For some callbacks I made a change to arrow funtions and for _stream_readable there was a change in
Readable.prototype.wrap
that I would like some opinions because I'm not sure if it's going to work as spected