-
Notifications
You must be signed in to change notification settings - Fork 5
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
Use case: Individually importable, tree-shakable methods #6
Comments
It’s true: this proposal would allow developers to use individually importable (tree-shakable) “generic” methods more ergonomically and fluently. Generic methods are already an existing and common pattern in JavaScript, of course. The pattern is even built into the language itself: The explainer currently focuses on the security use case because that use case’s benefits might be the clearest to TC39. But I have been planning on adding a section to the explainer about generic methods for a while. With regards to Hack pipes, there is a lot of history behind its relationship with bind operators. During 2015–2017, people debated a lot about how the old proposed bind operator However, parts of TC39 objected to promoting So I’ve wanted to try to avoid that old debate. We have a clear-cut security use case for a bind operator, and we’ll focus TC39 on that security use case. Meanwhile, we’ll present the bind operator as independent of the pipe operator, whose fundamental function (as the pipe champion group is presenting it) is flattening and linearizing deeply nested expressions. But we definitely can and should present individually importable generic methods as another use case: a pattern that is already common in JavaScript. I would welcome any existing examples from high-impact open-source libraries. (My understanding is that @benlesh had been originally planning for RxJS to use this pattern while waiting for the bind operator that did not come. I would welcome his expertise and insight here, too.) |
The original catalyst for RxJS moving to |
@benlesh: Thanks for your insight! Was that RxJS v5 system (its individually importable I’m trying to assess how generally common this pattern already is, given that this proposal would greatly lubricate it. |
I'm not sure how often this technique is used, considering its drawbacks. However it was important enough that TypeScript added a feature around it to support modules augmenting interfaces in maybe TS 2.1 or so (I don't remember the exact version). |
The explainer now deemphasizes the security use case. Based on feedback from some TC39 representatives (see #8, some discussion on Matrix, and pushback that the similar Extensions proposal has gotten), I’ve become reluctant to emphasize individually importable, tree-shakable quasi-extension methods. I’m afraid that emphasizing them as a use case would make several representatives colder toward this proposal. Instead, the explainer now simply emphasizes the high frequency and the high clunkiness of // graceful-fs-4.1.15.tgz/polyfills.js
return fs$read.call(fs, fd, buffer, offset, length, position, callback)
return fs->fs$read(fd, buffer, offset, length, position, callback) Hopefully, this makes sense and, hopefully, the explainer is more compelling than it had been before. |
Please correct me if I am wrong, but my understanding of this proposal has me thinking that the real power of it is the extension function capability, as it would allow for libraries like rxjs and other functional libraries to provide free functions (that are tree shakeable) that operate on
this
. Additionally, it works well as a local builder pattern for a foreign object.RxJS example:
Before
After
where a function like
map
has the signatureBuilder example:
then we can use the proposed bind syntax to augment the existing library with our new function in a fluent chaining way
I feel like this addresses a number of the concerned use cases around the Hack style pipeline operator
The text was updated successfully, but these errors were encountered: