Skip to content

stream: simpler stream constructon - #697

Closed
sonewman wants to merge 5 commits into
nodejs:v1.xfrom
sonewman:simpler-stream-construction
Closed

stream: simpler stream constructon#697
sonewman wants to merge 5 commits into
nodejs:v1.xfrom
sonewman:simpler-stream-construction

Conversation

@sonewman

Copy link
Copy Markdown
Contributor

This allows stream implementers the advantage of being able to pass the necessary stream specific methods to the streams constructor as part of its options upon construction.

Referenced to discussion in issue nodejs/readable-stream#102 of iojs/readable-stream

Please review.

cc: @chrisdickinson @iojs/streams

Via revealing constructor pattern. Referenced to discussion in issue nodejs/readable-stream#102 of iojs/readable-stream
Comment threaddoc/api/stream.markdown Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Technically I wouldn't call this a revealing constructor pattern, since no functionality is "revealed"; you instead just use stream.push and stream.emit("error", ...) and similar.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I get your point, I will amend the description as well.

@Qard

Qard commented Feb 3, 2015

Copy link
Copy Markdown
Member

+1 I like it. It makes the public-facing part of streams somewhat more approachable. They're currently a bit of a nebulous thing to newbies, hence the existence of through/through2.

@sonewman

Copy link
Copy Markdown
ContributorAuthor

@domenic i have updated.

@Fishrock123Fishrock123 added stream Issues and PRs related to the stream subsystem. semver-minor PRs that contain new features and should be released in the next minor version. discuss Issues opened for discussions and feedbacks. labels Feb 3, 2015
Comment threaddoc/api/stream.markdown Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

s/the need of//

@domenic

Copy link
Copy Markdown
Contributor

LGTM with minor nits. Someone more familiar with testing practices in io.js should sign off on those.

@sonewman

Copy link
Copy Markdown
ContributorAuthor

@domenic I appreciate your critique. I've never been that great at writing copy 😃

@Qard

Qard commented Feb 3, 2015

Copy link
Copy Markdown
Member

The console.log('ok') bits don't need to be there, and I'd refactor the writable test to use one process.on('exit', ...) and no unnecessary one/two functions.

@mafintosh

Copy link
Copy Markdown
Member

I would remove new from the examples since that is optional. Other than that LGTM from me

@domenic

Copy link
Copy Markdown
Contributor

new is not optional for ES6 classes so it'd be prudent to leave them in to discourage bad habits.

@sonewman

Copy link
Copy Markdown
ContributorAuthor

@Qard I was trying to follow the style of the other stream tests... But I will amend.

@chrisdickinson

Copy link
Copy Markdown
Contributor

@domenic This is more for my curiosity than anything else: can you still get around that with the usual if (!(this instanceof Classname)) return new Classname(...args) in constructor(){}? If that's the case, I imagine we'll continue to take the "new is encouraged but not required" approach.

@chrisdickinson

Copy link
Copy Markdown
Contributor

Should we reframe how we're documenting this? Would it be better to integrate the existing examples with the new style of construction, and call out "old-style subclassing" as the standalone topic?

@domenic

Copy link
Copy Markdown
Contributor

@chrisdickinson nope, constructors defined with class syntax have a throwing [[Call]] internal method.

@sonewman

Copy link
Copy Markdown
ContributorAuthor

Should we reframe how we're documenting this? Would it be better to integrate the existing examples with the new style of construction, and call out "old-style subclassing" as the standalone topic?

@chrisdickinson I thought about this very thing, as I wasn't sure where the documentation should belong. If it went before the inheritance parts then the examples were referring to documentation that was to come. By putting it after solved that problem, but one would have to read the older inheritance way to understand the use of this new simpler pattern. 😕

@chrisdickinson

Copy link
Copy Markdown
Contributor

@sonewman Cool. We should definitely revisit the docs later, but that shouldn't be considered blocking for this.

I'll leave this open until tomorrow afternoon, at which point I'll merge it if no one has objected.

@sonewman

Copy link
Copy Markdown
ContributorAuthor

@chrisdickinson awesome cheers dude.

@vkurchatkin

Copy link
Copy Markdown
Contributor

👍 wanted this for a long time

@sonewman

Copy link
Copy Markdown
ContributorAuthor

@chrisdickinson do you want me to squish this into one commit?

@Fishrock123Fishrock123 removed the discuss Issues opened for discussions and feedbacks. label Feb 4, 2015
@Qard

Qard commented Feb 5, 2015

Copy link
Copy Markdown
Member

This test is failing for me:

=== release test-stream-writable-constructor-set-methods === Path: parallel/test-stream-writable-constructor-set-methods
assert.js:87
throw new assert.AssertionError({
^
AssertionError: null == [Function: _writev]
at process.<anonymous> (/home/sbelanger/Documents/io.js/test/parallel/test-stream-writable-constructor-set-methods.js:31:10)
at process.emit (events.js:119:20)
Command: out/Release/iojs /home/sbelanger/Documents/io.js/test/parallel/test-stream-writable-constructor-set-methods.js
[00:43|% 100|+ 812|- 1]: Done 

@chrisdickinson

Copy link
Copy Markdown
Contributor

Looks like a typo. Fixing in the merge.

chrisdickinson pushed a commit that referenced this pull request Feb 5, 2015
Adds simplified constructor pattern, allowing users
to provide "read", "write", "transform", "flush", and
"writev" functions as stream options in lieu of subclassing.
Semver: minor
PR-URL: #697Fixes: nodejs/readable-stream#102
Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
@chrisdickinson

Copy link
Copy Markdown
Contributor

Merged in 50daee7.

Note: This is a semver-minor level change. If we don't want the next release to be semver-minor, this should be backed out first.

@sonewman
sonewman deleted the simpler-stream-construction branch February 5, 2015 09:11
@sonewman

Copy link
Copy Markdown
ContributorAuthor

@chrisdickinson thanks for fixing the typo, I don't know how many times I ran those tests (but obviously not enough!)

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

semver-minorPRs that contain new features and should be released in the next minor version.streamIssues and PRs related to the stream subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@sonewman@Qard@domenic@mafintosh@chrisdickinson@vkurchatkin@Fishrock123