-
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
Lodash: Refactor post editor away from _.map()
#47193
Conversation
@@ -50,7 +45,7 @@ function BlockManagerCategory( { title, blockTypes } ) { | |||
}, [] ); | |||
const toggleAllVisible = useCallback( | |||
( nextIsChecked ) => { | |||
const blockNames = map( blockTypes, 'name' ); | |||
const blockNames = blockTypes.map( ( { name } ) => name ); |
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.
Always an array (here and in the next usage a few lines below):
blockTypes={ blockTypes.filter( |
const checkedBlockNames = map( filteredBlockTypes, 'name' ).filter( | ||
( type ) => ! hiddenBlockTypes.includes( type ) | ||
); | ||
const checkedBlockNames = filteredBlockTypes |
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.
Already an array since it's passing through .filter()
already.
@@ -50,7 +45,7 @@ export default function MetaBoxes( { location } ) { | |||
|
|||
return ( | |||
<> | |||
{ map( metaBoxes, ( { id } ) => ( | |||
{ ( metaBoxes ?? [] ).map( ( { id } ) => ( |
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.
@@ -36,7 +31,7 @@ export function MetaBoxesSection( { | |||
{ areCustomFieldsRegistered && ( | |||
<EnableCustomFieldsOption label={ __( 'Custom fields' ) } /> | |||
) } | |||
{ map( thirdPartyMetaBoxes, ( { id, title } ) => ( | |||
{ thirdPartyMetaBoxes.map( ( { id, title } ) => ( |
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.
Already used as an array above in this component.
@@ -136,7 +131,7 @@ function Editor( { | |||
// all block types). | |||
const defaultAllowedBlockTypes = | |||
true === settings.allowedBlockTypes | |||
? map( blockTypes, 'name' ) | |||
? blockTypes.map( ( { name } ) => name ) |
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.
Will always be an array:
( state ) => Object.values( state.blockTypes ), |
@@ -74,7 +73,7 @@ class Editor extends Component { | |||
// all block types). | |||
const defaultAllowedBlockTypes = | |||
true === settings.allowedBlockTypes | |||
? map( blockTypes, 'name' ) | |||
? blockTypes.map( ( { name } ) => name ) |
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.
Always an array:
( state ) => Object.values( state.blockTypes ), |
1cbecb4
to
f707800
Compare
Size Change: -3 B (0%) Total Size: 1.33 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 👍
What?
This PR removes Lodash's
_.map()
from the post editor package. There are just a couple of usages and conversion is pretty straightforward.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 using
Array.prototype.map()
instead. We're also adding nullish coalescing where necessary.Testing Instructions