Skip to content

Commit

Permalink
Lodash: Refactor post editor away from _.map()
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla committed Jan 16, 2023
1 parent 4e29eee commit f707800
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 29 deletions.
13 changes: 4 additions & 9 deletions packages/edit-post/src/components/block-manager/category.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { map } from 'lodash';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -50,7 +45,7 @@ function BlockManagerCategory( { title, blockTypes } ) {
}, [] );
const toggleAllVisible = useCallback(
( nextIsChecked ) => {
const blockNames = map( blockTypes, 'name' );
const blockNames = blockTypes.map( ( { name } ) => name );
if ( nextIsChecked ) {
showBlockTypes( blockNames );
} else {
Expand All @@ -64,9 +59,9 @@ function BlockManagerCategory( { title, blockTypes } ) {
return null;
}

const checkedBlockNames = map( filteredBlockTypes, 'name' ).filter(
( type ) => ! hiddenBlockTypes.includes( type )
);
const checkedBlockNames = filteredBlockTypes
.map( ( { name } ) => name )
.filter( ( type ) => ! hiddenBlockTypes.includes( type ) );

const titleId = 'edit-post-block-manager__category-title-' + instanceId;

Expand Down
7 changes: 1 addition & 6 deletions packages/edit-post/src/components/meta-boxes/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { map } from 'lodash';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -50,7 +45,7 @@ export default function MetaBoxes( { location } ) {

return (
<>
{ map( metaBoxes, ( { id } ) => (
{ ( metaBoxes ?? [] ).map( ( { id } ) => (
<MetaBoxVisibility key={ id } id={ id } />
) ) }
<MetaBoxesArea location={ location } />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { map } from 'lodash';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -36,7 +31,7 @@ export function MetaBoxesSection( {
{ areCustomFieldsRegistered && (
<EnableCustomFieldsOption label={ __( 'Custom fields' ) } />
) }
{ map( thirdPartyMetaBoxes, ( { id, title } ) => (
{ thirdPartyMetaBoxes.map( ( { id, title } ) => (
<EnablePanelOption
key={ id }
label={ title }
Expand Down
7 changes: 1 addition & 6 deletions packages/edit-post/src/editor.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { map } from 'lodash';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -136,7 +131,7 @@ function Editor( {
// all block types).
const defaultAllowedBlockTypes =
true === settings.allowedBlockTypes
? map( blockTypes, 'name' )
? blockTypes.map( ( { name } ) => name )
: settings.allowedBlockTypes || [];

result.allowedBlockTypes = defaultAllowedBlockTypes.filter(
Expand Down
3 changes: 1 addition & 2 deletions packages/edit-post/src/editor.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import memize from 'memize';
import { map } from 'lodash';
import { I18nManager } from 'react-native';
import { GestureHandlerRootView } from 'react-native-gesture-handler';

Expand Down Expand Up @@ -74,7 +73,7 @@ class Editor extends Component {
// all block types).
const defaultAllowedBlockTypes =
true === settings.allowedBlockTypes
? map( blockTypes, 'name' )
? blockTypes.map( ( { name } ) => name )
: settings.allowedBlockTypes || [];

settings.allowedBlockTypes = defaultAllowedBlockTypes.filter(
Expand Down

0 comments on commit f707800

Please sign in to comment.