-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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: simpler stream constructon #697
Conversation
Via revealing constructor pattern. Referenced to discussion in issue nodejs/readable-stream#102 of iojs/readable-stream
@@ -1315,6 +1315,135 @@ for examples and testing, but there are occasionally use cases where | |||
it can come in handy as a building block for novel sorts of streams. | |||
|
|||
|
|||
## Simplified API Via Revealing Constructor Pattern |
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.
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.
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 get your point, I will amend the description as well.
+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. |
@domenic i have updated. |
|
||
<!--type=misc--> | ||
|
||
In simple cases there is now the added benefit of being able to construct a stream without the need of inheritance. |
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.
s/the need of//
LGTM with minor nits. Someone more familiar with testing practices in io.js should sign off on those. |
@domenic I appreciate your critique. I've never been that great at writing copy 😃 |
The |
I would remove |
new is not optional for ES6 classes so it'd be prudent to leave them in to discourage bad habits. |
@Qard I was trying to follow the style of the other stream tests... But I will amend. |
@domenic This is more for my curiosity than anything else: can you still get around that with the usual |
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 nope, constructors defined with class syntax have a throwing [[Call]] internal method. |
@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. 😕 |
@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. |
@chrisdickinson awesome cheers dude. |
👍 wanted this for a long time |
@chrisdickinson do you want me to squish this into one commit? |
This test is failing for me:
|
Looks like a typo. Fixing in the merge. |
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: #697 Fixes: nodejs/readable-stream#102 Reviewed-By: Chris Dickinson <[email protected]>
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. |
@chrisdickinson thanks for fixing the typo, I don't know how many times I ran those tests (but obviously not enough!) |
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