From 2f8c5729fd01b3f166452d130e19c614e1d4989f Mon Sep 17 00:00:00 2001 From: Marin Atanasov <8436925+tyxla@users.noreply.github.com> Date: Tue, 17 Jan 2023 11:17:54 +0200 Subject: [PATCH] Lodash: Refactor blocks away from _.map() (#47188) --- packages/blocks/src/store/reducer.js | 4 ++-- packages/blocks/src/store/selectors.js | 11 +++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/blocks/src/store/reducer.js b/packages/blocks/src/store/reducer.js index 16f95127137a5..64b65121c4ab0 100644 --- a/packages/blocks/src/store/reducer.js +++ b/packages/blocks/src/store/reducer.js @@ -1,7 +1,7 @@ /** * External dependencies */ -import { get, isEmpty, map, mapValues } from 'lodash'; +import { get, isEmpty, mapValues } from 'lodash'; /** * WordPress dependencies @@ -269,7 +269,7 @@ export function categories( state = DEFAULT_CATEGORIES, action ) { ( { slug } ) => slug === action.slug ); if ( categoryToChange ) { - return map( state, ( category ) => { + return state.map( ( category ) => { if ( category.slug === action.slug ) { return { ...category, diff --git a/packages/blocks/src/store/selectors.js b/packages/blocks/src/store/selectors.js index 27cacef408582..bf70dbc0c261c 100644 --- a/packages/blocks/src/store/selectors.js +++ b/packages/blocks/src/store/selectors.js @@ -3,7 +3,7 @@ */ import createSelector from 'rememo'; import removeAccents from 'remove-accents'; -import { get, map } from 'lodash'; +import { get } from 'lodash'; /** * WordPress dependencies @@ -553,12 +553,11 @@ export function getGroupingBlockName( state ) { */ export const getChildBlockNames = createSelector( ( state, blockName ) => { - return map( - getBlockTypes( state ).filter( ( blockType ) => { + return getBlockTypes( state ) + .filter( ( blockType ) => { return blockType.parent?.includes( blockName ); - } ), - ( { name } ) => name - ); + } ) + .map( ( { name } ) => name ); }, ( state ) => [ state.blockTypes ] );