Skip to content

Commit

Permalink
Block editor: use vanilla JS [].includes. (#21063)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZebulanStanphill authored Jul 2, 2020
1 parent d41c9d4 commit 97affa3
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 30 deletions.
8 changes: 1 addition & 7 deletions packages/block-editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { includes } from 'lodash';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -60,8 +55,7 @@ function InserterMenu( {
const showPatterns = ! destinationRootClientId && hasPatterns;
const onKeyDown = ( event ) => {
if (
includes(
[ LEFT, DOWN, RIGHT, UP, BACKSPACE, ENTER ],
[ LEFT, DOWN, RIGHT, UP, BACKSPACE, ENTER ].includes(
event.keyCode
)
) {
Expand Down
4 changes: 2 additions & 2 deletions packages/block-editor/src/components/observe-typing/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { over, includes } from 'lodash';
import { over } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -39,7 +39,7 @@ const KEY_DOWN_ELIGIBLE_KEY_CODES = [ UP, RIGHT, DOWN, LEFT, ENTER, BACKSPACE ];
*/
function isKeyDownEligibleForStartTyping( event ) {
const { keyCode, shiftKey } = event;
return ! shiftKey && includes( KEY_DOWN_ELIGIBLE_KEY_CODES, keyCode );
return ! shiftKey && KEY_DOWN_ELIGIBLE_KEY_CODES.includes( keyCode );
}

function ObserveTyping( { children, setTimeout: setSafeTimeout } ) {
Expand Down
19 changes: 10 additions & 9 deletions packages/block-editor/src/hooks/align.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* External dependencies
*/
import classnames from 'classnames';
import { get, has, includes, without } from 'lodash';
import { get, has, without } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -189,7 +189,7 @@ export const withDataAlign = createHigherOrderComponent(
);

let wrapperProps = props.wrapperProps;
if ( includes( validAlignments, align ) ) {
if ( validAlignments.includes( align ) ) {
wrapperProps = { ...wrapperProps, 'data-align': align };
}

Expand All @@ -210,13 +210,14 @@ export function addAssignedAlign( props, blockType, attributes ) {
const { align } = attributes;
const blockAlign = getBlockSupport( blockType, 'align' );
const hasWideBlockSupport = hasBlockSupport( blockType, 'alignWide', true );
const isAlignValid = includes(
// Compute valid alignments without taking into account,
// if the theme supports wide alignments or not.
// This way changing themes does not impacts the block save.
getValidAlignments( blockAlign, hasWideBlockSupport ),
align
);

// Compute valid alignments without taking into account if
// the theme supports wide alignments or not.
// This way changing themes does not impact the block save.
const isAlignValid = getValidAlignments(
blockAlign,
hasWideBlockSupport
).includes( align );
if ( isAlignValid ) {
props.className = classnames( `align${ align }`, props.className );
}
Expand Down
5 changes: 3 additions & 2 deletions packages/block-editor/src/store/actions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/**
* External dependencies
*/
import { castArray, first, get, includes, last, some } from 'lodash';
import { castArray, first, get, last, some } from 'lodash';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -265,7 +266,7 @@ function getBlocksWithDefaultStylesApplied( blocks, blockEditorSettings ) {
return block;
}
const className = get( block, [ 'attributes', 'className' ] );
if ( includes( className, 'is-style-' ) ) {
if ( className?.includes( 'is-style-' ) ) {
return block;
}
const { attributes = {} } = block;
Expand Down
7 changes: 3 additions & 4 deletions packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
flatMap,
first,
get,
includes,
isArray,
isBoolean,
last,
Expand Down Expand Up @@ -1126,11 +1125,11 @@ const canInsertBlockTypeUnmemoized = (
if ( isArray( list ) ) {
// TODO: when there is a canonical way to detect that we are editing a post
// the following check should be changed to something like:
// if ( includes( list, 'core/post-content' ) && getEditorMode() === 'post-content' && item === null )
if ( includes( list, 'core/post-content' ) && item === null ) {
// if ( list.includes( 'core/post-content' ) && getEditorMode() === 'post-content' && item === null )
if ( list.includes( 'core/post-content' ) && item === null ) {
return true;
}
return includes( list, item );
return list.includes( item );
}
return defaultResult;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
/**
* External dependencies
*/
import { includes } from 'lodash';

/**
* @constant string IS_ROOT_TAG Regex to check if the selector is a root tag selector.
*/
const IS_ROOT_TAG = /^(body|html|:root).*$/;

const wrap = ( namespace, ignore = [] ) => ( node ) => {
const updateSelector = ( selector ) => {
if ( includes( ignore, selector.trim() ) ) {
if ( ignore.includes( selector.trim() ) ) {
return selector;
}

Expand Down

0 comments on commit 97affa3

Please sign in to comment.