From 907a65e1289bcdf15d954c92ddbdc3031c6824c4 Mon Sep 17 00:00:00 2001 From: Marin Atanasov <8436925+tyxla@users.noreply.github.com> Date: Mon, 5 Sep 2022 17:10:34 +0300 Subject: [PATCH] Lodash: Remove _.first() and _.last() from block editor store (#43854) --- packages/block-editor/src/store/reducer.js | 18 ++++++++---------- packages/block-editor/src/store/selectors.js | 19 +++++-------------- 2 files changed, 13 insertions(+), 24 deletions(-) diff --git a/packages/block-editor/src/store/reducer.js b/packages/block-editor/src/store/reducer.js index 73055bdef71996..706b3b41893d3d 100644 --- a/packages/block-editor/src/store/reducer.js +++ b/packages/block-editor/src/store/reducer.js @@ -4,8 +4,6 @@ import { flow, reduce, - first, - last, omit, without, mapValues, @@ -1004,13 +1002,10 @@ export const blocks = flow( case 'MOVE_BLOCKS_UP': { const { clientIds, rootClientId = '' } = action; - const firstClientId = first( clientIds ); + const firstClientId = clientIds[ 0 ]; const subState = state[ rootClientId ]; - if ( - ! subState.length || - firstClientId === first( subState ) - ) { + if ( ! subState.length || firstClientId === subState[ 0 ] ) { return state; } @@ -1029,11 +1024,14 @@ export const blocks = flow( case 'MOVE_BLOCKS_DOWN': { const { clientIds, rootClientId = '' } = action; - const firstClientId = first( clientIds ); - const lastClientId = last( clientIds ); + const firstClientId = clientIds[ 0 ]; + const lastClientId = clientIds[ clientIds.length - 1 ]; const subState = state[ rootClientId ]; - if ( ! subState.length || lastClientId === last( subState ) ) { + if ( + ! subState.length || + lastClientId === subState[ subState.length - 1 ] + ) { return state; } diff --git a/packages/block-editor/src/store/selectors.js b/packages/block-editor/src/store/selectors.js index 13ab5eb264cad5..5c3ca61ead71fe 100644 --- a/packages/block-editor/src/store/selectors.js +++ b/packages/block-editor/src/store/selectors.js @@ -1,17 +1,7 @@ /** * External dependencies */ -import { - castArray, - first, - last, - map, - reduce, - some, - find, - filter, - orderBy, -} from 'lodash'; +import { castArray, map, reduce, some, find, filter, orderBy } from 'lodash'; import createSelector from 'rememo'; /** @@ -798,7 +788,7 @@ export const getMultiSelectedBlocks = createSelector( * @return {?string} First block client ID in the multi-selection set. */ export function getFirstMultiSelectedBlockClientId( state ) { - return first( getMultiSelectedBlockClientIds( state ) ) || null; + return getMultiSelectedBlockClientIds( state )[ 0 ] || null; } /** @@ -810,7 +800,8 @@ export function getFirstMultiSelectedBlockClientId( state ) { * @return {?string} Last block client ID in the multi-selection set. */ export function getLastMultiSelectedBlockClientId( state ) { - return last( getMultiSelectedBlockClientIds( state ) ) || null; + const selectedClientIds = getMultiSelectedBlockClientIds( state ); + return selectedClientIds[ selectedClientIds.length - 1 ] || null; } /** @@ -2633,7 +2624,7 @@ export const __experimentalGetActiveBlockIdByBlockNames = createSelector( ); if ( entityAreaParents ) { // Last parent closest/most interior. - return last( entityAreaParents ); + return entityAreaParents[ entityAreaParents.length - 1 ]; } return null; },