-
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 an in-house debounce()
utility, deprecate Lodash version
#43943
Conversation
Size Change: +375 B (0%) Total Size: 1.26 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.
LGTM, other than the small comment issue below 👍 Love to see this moved to a @wordpress
lib 🙂 I'll leave it to more seasoned Gutenberg developers to comment on whether this is the right package for it, though.
Thank you for going to the trouble of assigning me co-authorship of the first commit, @tyxla! That was very kind of you 🙂
Thanks, that has been addressed in 737875a
I believe it should be, because
Of course! It only makes sense :) |
I've fixed a couple more issues - a missing internal dependency one and one where we weren't passing a wait time to a Looking forward to a few more reviews 🙌 |
I'm planning to land this one this week - is anyone willing to give it another look? |
965a6bf
to
bb48334
Compare
Thanks for the feedback y'all! Added a changelog entry in bb48334 as well. Ready for another last look 👀 |
All CI checks pass. There is a set of unit tests included. I don't see any negative impact on the performance metrics reported in https://github.com/WordPress/gutenberg/actions/runs/3059825067/jobs/4937649466. I don't know the internals of |
Co-authored-by: Sérgio Gomes <[email protected]>
bb48334
to
d0984f4
Compare
What?
This PR introduces an in-house version of the
_.debounce()
function, along with some tests. I've borrowed most of the prior art by @sgomes (kudos for that), as indicated by his co-authorship of the first commit. We also update alldebounce
usages in Gutenberg to use the new version. Finally, we deprecate the original_.debounce()
function so it will never be seen again in the repo.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 introducing
debounce
as another utility function in the@wordpress/compose
package. That nicely gives us the opportunity to type it, which we're essentially doing. It comes with a few tests as well. We're exposing it externally, since it will be used by other packages.Furthermore, we update all
_.debounce()
calls to use the new utility function, including theuseDebounce()
hook. IMHO, that closes the loop of having an in-house hook foruseDebounce()
but using an external function for the actual debouncing, giving us control on the types and functionality.You might ask why we're adding all the custom features (the
options
third argument) when they're not used internally. Well, becauseuseDebounce()
is exposed externally, and it was supporting all those options, so we have to continue supporting them for backwards compatibility.Testing Instructions
debounce()
that it continues to work well, for example: