Skip to content

Commit

Permalink
Lodash: Remove _.first() and _.last() from block editor store (#43854)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla authored Sep 5, 2022
1 parent 35a2579 commit 907a65e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 24 deletions.
18 changes: 8 additions & 10 deletions packages/block-editor/src/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import {
flow,
reduce,
first,
last,
omit,
without,
mapValues,
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down
19 changes: 5 additions & 14 deletions packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
@@ -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';

/**
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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;
},
Expand Down

0 comments on commit 907a65e

Please sign in to comment.