-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Compose: Introduce in-house compose
and pipe
utils
#44112
Conversation
Size Change: +112 B (0%) Total Size: 1.25 MB
ℹ️ View Unchanged
|
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.
Changes look good to me, and test fine. I'll defer to more experienced eyes for an approval though 👍
I am curious about the naming. These are inspired by lodash
's flow
and flowRight
, but we're calling them flow
and compose
, which kind of hides that they do the same thing in opposite directions.
Is that just because compose()
was named and used all over the place already, and renaming all of those implementations to flowRight()
would be more trouble than it's worth?
The naming in |
* Composes multiple higher-order components into a single higher-order component. Performs left-to-right function | ||
* composition, where each successive invocation is supplied the return value of the previous. | ||
* | ||
* This is inspired by `lodash`'s `flow` function. |
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.
It would be better to include the license from lodash
like here:
gutenberg/packages/element/src/serialize.js
Lines 1 to 26 in a3c753d
/** | |
* Parts of this source were derived and modified from fast-react-render, | |
* released under the MIT license. | |
* | |
* https://github.com/alt-j/fast-react-render | |
* | |
* Copyright (c) 2016 Andrey Morozov | |
* | |
* Permission is hereby granted, free of charge, to any person obtaining a copy | |
* of this software and associated documentation files (the "Software"), to deal | |
* in the Software without restriction, including without limitation the rights | |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
* copies of the Software, and to permit persons to whom the Software is | |
* furnished to do so, subject to the following conditions: | |
* | |
* The above copyright notice and this permission notice shall be included in | |
* all copies or substantial portions of the Software. | |
* | |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
* THE SOFTWARE. | |
*/ |
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.
Done in 26a9304
From my perspective the refactor for As for |
The original goal behind naming here was to:
Essentially, yes. |
Thanks for the feedback, both 🙌 As suggested by @gziolo I've renamed As for the native JS pipeline operator proposal - I was also considering using it (and making sure Babel supports it), but I saw there's still no consensus on the syntax. Maybe one day we can update to it, when it finally lands in the ES world. That being said, this PR is ready for another final look. |
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.
Looks great. I'm happy to see that included in @wordpress/compose
. Excellent work @tyxla 💯
compose
and flow
utilscompose
and pipe
utils
26a9304
to
9aa5a36
Compare
I realized I needed to add a CHANGELOG entry. Added in 9aa5a36 |
What?
Currently, we expose our own
compose()
high-order composition utility, which is a re-export of_.flowRight()
. This PR implements our simple in-house version ofcompose()
, and uses the opportunity to also introduce an in-house version offlow()
, which is the inverted version offlowRight()
. That allows us to get rid of the corresponding Lodash functions in the following PRs.Why?
Lodash is known to unnecessarily inflate the bundle size of packages, and in most cases, it can be replaced with native language functionality. See these for more information and rationale:
@wordpress/api-fetch
package haslodash
as a dependency #39495How?
We're implementing a custom base
baseFlow()
function and using that to generate bothcompose()
andflow()
so they work the same way as the Lodash versions. We're adding a few tests to ensure things work as expected.I've chosen to migrate away from the existing
_.flowRight()
and_.flow()
in a separate PR, to keep this one more contained.Testing Instructions
compose()
is used all over the place.