-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Lodash: Refactor away from _.kebabCase()
in block editor
#51687
Conversation
Size Change: -429 B (0%) Total Size: 1.4 MB
ℹ️ View Unchanged
|
The PHP version of this method It's essential that both methods generate exact strings. |
Great point - thanks @Mamaduka! We were definitely missing to cover some of those scenarios, but I've updated the PR to cover them and borrowed all the tests you linked to in 2deb924. Let me know what you think! |
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! The listed features work as before.
…#51687) * Block Editor: Introduce kebabCase util * Block Editor: Introduce unit tests for kebabCase() * Block Editor: Replace _.kebabCase() with our custom util * Block Editor: Update kebabCase() to handle other types * Cover all _wp_to_kebab_case() scenarios * Minor formatting fixes
What?
This PR removes Lodash's
_.kebabCase()
from the block editor package. This basically gets rid of half of the remainingkebabCase()
usages in the entire codebase.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 #39495We're pretty close with the migration away from Lodash, only 3 methods are used and we're close to reaping the benefits of not relying on it at all.
How?
We're introducing a custom
kebabCase()
utility that basically customizes the existingparamCase()
function from thechange-case
package that we've already been utilizing throughout Gutenberg.The custom utility is necessary in order to keep backward compatibility with the Lodash function within the block editor context (it's mostly about properly handling class names the same way as Lodash's
kebabCase()
did).We're adding unit tests to ensure we're covering all scenarios as Lodash did.
We're finally replacing all usages within the block editor package with the new utility function.
Testing Instructions