-
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
Styles hook: swap out lodash methods with their JS equivalents #40918
Conversation
Size Change: +933 B (0%) Total Size: 1.24 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.
Thanks for looking into this, left couple of comments!
Thanks for the quick and helpful review @tomasztunik! I've updated to include your suggestions 🙇 |
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.
Thanks for this code quality PR @ramonjd! I agree, I think it's a really good idea to reduce our dependency on lodash where there are now straightforward vanilla JS approaches. A big one for me is that things like Object.entries( skipPaths ).forEach( ( [ indicator, path ] ) => {
feels much clearer even if it's slightly more verbose, and I like that the vanilla JS forEach
on the entries here gives us key, value
versus lodash's value, key
which always felt unintuitive to me.
✅ Tests are passing
✅ Existing styles appear to be working well in both the post and site editors
✅ No errors or warnings in the console as I hacked around adding and removing properties
LGTM!
Thanks for the reviews @tomasztunik and @andrewserong |
What?
Just removing a couple of lodash methods that we arguably don't require.
Why?
Just coz.
How?
Replacing:
_.map( Object, fn() )
withObject.entries( object ).map( fn() )
_.startsWith( String, arg )
with'somestring'.startsWith( arg )
_.forEach( Object, fn() )
withObject.keys( Object ).forEach( fn() )
_.first( Array )
witharray[ 0 ]
Testing Instructions
Ensure that blocks styles work on the post/site editors.
Here is some test block code:
Test HTML
Run
npm run test-unit packages/block-editor/src/hooks/test/style.js