Skip to content
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 away from _.first() and _.last() #43894

Merged
merged 1 commit into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ module.exports = {
'findIndex',
'findKey',
'findLast',
'first',
'flatMap',
'flatten',
'flattenDeep',
Expand All @@ -122,6 +123,7 @@ module.exports = {
'isUndefined',
'keyBy',
'keys',
'last',
'lowerCase',
'mapKeys',
'maxBy',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { last } from 'lodash';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -36,7 +31,9 @@ function BlockListAppender( {
return (
<DefaultBlockAppender
rootClientId={ rootClientId }
lastBlockClientId={ last( blockClientIds ) }
lastBlockClientId={
blockClientIds[ blockClientIds.length - 1 ]
}
containerStyle={ styles.blockListAppender }
placeholder={ blockClientIds.length > 0 ? '' : null }
showSeparator={ showSeparator }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { last } from 'lodash';

/**
* WordPress dependencies
*/
Expand All @@ -28,7 +23,7 @@ export default compose( [
const blockClientIds = getBlockOrder( clientId );

return {
lastBlockClientId: last( blockClientIds ),
lastBlockClientId: blockClientIds[ blockClientIds.length - 1 ],
};
} ),
] )( DefaultBlockAppender );
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { last } from 'lodash';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -152,7 +147,9 @@ export default function useBlockSync( {
// to allow that the consumer may apply modifications to reflect
// back on the editor.
if (
last( pendingChanges.current.outgoing ) === controlledBlocks
pendingChanges.current.outgoing[
pendingChanges.current.outgoing.length - 1
] === controlledBlocks
) {
pendingChanges.current.outgoing = [];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { first, last, castArray } from 'lodash';
import { castArray } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -61,7 +61,7 @@ export default function useOutdentListItem( clientId ) {

if ( ! clientIds.length ) return;

const firstClientId = first( clientIds );
const firstClientId = clientIds[ 0 ];

// Can't outdent if it's not a list item.
if ( getBlockName( firstClientId ) !== listItemName ) return;
Expand All @@ -72,15 +72,15 @@ export default function useOutdentListItem( clientId ) {
if ( ! parentListItemId ) return;

const parentListId = getBlockRootClientId( firstClientId );
const lastClientId = last( clientIds );
const lastClientId = clientIds[ clientIds.length - 1 ];
const order = getBlockOrder( parentListId );
const followingListItems = order.slice(
getBlockIndex( lastClientId ) + 1
);

registry.batch( () => {
if ( followingListItems.length ) {
let nestedListId = first( getBlockOrder( firstClientId ) );
let nestedListId = getBlockOrder( firstClientId )[ 0 ];

if ( ! nestedListId ) {
const nestedListBlock = cloneBlock(
Expand Down
7 changes: 1 addition & 6 deletions packages/block-library/src/list/edit.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { last } from 'lodash';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -108,7 +103,7 @@ function useOutdentList( clientId ) {
[ newParentBlock, ...innerBlocks ]
);
// Select the last child of the list being outdent.
selectionChange( last( innerBlocks ).clientId );
selectionChange( innerBlocks[ innerBlocks.length - 1 ].clientId );
}, [ clientId ] ),
];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { first, get, isEmpty, kebabCase, pickBy, reduce, set } from 'lodash';
import { get, isEmpty, kebabCase, pickBy, reduce, set } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -199,7 +199,7 @@ export function getStylesDeclarations(
return declarations;
}
const pathToValue = value;
if ( first( pathToValue ) === 'elements' || useEngine ) {
if ( pathToValue[ 0 ] === 'elements' || useEngine ) {
return declarations;
}

Expand Down