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 block editor away from _.some() #45335

Merged
merged 1 commit into from
Oct 27, 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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { find, pickBy, reduce, some } from 'lodash';
import { find, pickBy, reduce } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -152,8 +152,7 @@ export default ( ...fontSizeNames ) => {
};

if (
! some(
fontSizeAttributeNames,
! Object.values( fontSizeAttributeNames ).some(
didAttributesChange
)
) {
Expand Down
22 changes: 9 additions & 13 deletions packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { map, reduce, some, find, filter, orderBy } from 'lodash';
import { map, reduce, find, filter, orderBy } from 'lodash';
import createSelector from 'rememo';

/**
Expand Down Expand Up @@ -1184,8 +1184,7 @@ export function isBlockSelected( state, clientId ) {
* @return {boolean} Whether the block as an inner block selected
*/
export function hasSelectedInnerBlock( state, clientId, deep = false ) {
return some(
getBlockOrder( state, clientId ),
return getBlockOrder( state, clientId ).some(
( innerClientId ) =>
isBlockSelected( state, innerClientId ) ||
isBlockMultiSelected( state, innerClientId ) ||
Expand Down Expand Up @@ -1333,7 +1332,7 @@ export function isAncestorBeingDragged( state, clientId ) {
}

const parents = getBlockParents( state, clientId );
return some( parents, ( parentClientId ) =>
return parents.some( ( parentClientId ) =>
isBlockBeingDragged( state, parentClientId )
);
}
Expand Down Expand Up @@ -1532,7 +1531,7 @@ const canInsertBlockTypeUnmemoized = (
...getBlockParents( state, rootClientId ),
];

hasBlockAllowedAncestor = some( ancestors, ( ancestorClientId ) =>
hasBlockAllowedAncestor = ancestors.some( ( ancestorClientId ) =>
checkAllowList(
blockAllowedAncestorBlocks,
getBlockName( state, ancestorClientId )
Expand Down Expand Up @@ -1846,13 +1845,10 @@ const buildBlockTypeItem =

let isDisabled = false;
if ( ! hasBlockSupport( blockType.name, 'multiple', true ) ) {
isDisabled = some(
getBlocksByClientId(
state,
getClientIdsWithDescendants( state )
),
{ name: blockType.name }
);
isDisabled = getBlocksByClientId(
state,
getClientIdsWithDescendants( state )
).some( ( { name } ) => name === blockType.name );
}

const { time, count = 0 } = getInsertUsage( state, id ) || {};
Expand Down Expand Up @@ -2130,7 +2126,7 @@ export const getBlockTransformItems = createSelector(
*/
export const hasInserterItems = createSelector(
( state, rootClientId = null ) => {
const hasBlockType = some( getBlockTypes(), ( blockType ) =>
const hasBlockType = getBlockTypes().some( ( blockType ) =>
canIncludeBlockTypeInInserter( state, blockType, rootClientId )
);
if ( hasBlockType ) {
Expand Down