Skip to content

Commit

Permalink
Lodash: Remove _.omit() from block editor (#43704)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla authored Aug 31, 2022
1 parent a17a86f commit c78c105
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 37 deletions.
12 changes: 5 additions & 7 deletions packages/block-editor/src/components/block-list/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import classnames from 'classnames';
import { omit } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -185,16 +184,15 @@ function BlockListBlock( {
block = <Block { ...wrapperProps }>{ blockEdit }</Block>;
}

const { 'data-align': dataAlign, ...restWrapperProps } = wrapperProps ?? {};

const value = {
clientId,
className:
wrapperProps?.[ 'data-align' ] && themeSupportsLayout
? classnames(
className,
`align${ wrapperProps[ 'data-align' ] }`
)
dataAlign && themeSupportsLayout
? classnames( className, `align${ dataAlign }` )
: className,
wrapperProps: omit( wrapperProps, [ 'data-align' ] ),
wrapperProps: restWrapperProps,
isAligned,
};
const memoizedValue = useMemo( () => value, Object.values( value ) );
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* External dependencies
*/
import { omit } from 'lodash';
import classnames from 'classnames';
/**
* WordPress dependencies
Expand Down Expand Up @@ -112,9 +111,10 @@ const LinkControlSearchInput = forwardRef(
allowDirectEntry ||
( suggestion && Object.keys( suggestion ).length >= 1 )
) {
const { id, url, ...restLinkProps } = currentLink;
onSelect(
// Some direct entries don't have types or IDs, and we still need to clear the previous ones.
{ ...omit( currentLink, 'id', 'url' ), ...suggestion },
{ ...restLinkProps, ...suggestion },
suggestion
);
}
Expand Down
44 changes: 23 additions & 21 deletions packages/block-editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import classnames from 'classnames';
import { omit } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -61,25 +60,27 @@ export const inputEventContext = createContext();
* @return {Object} Filtered props.
*/
function removeNativeProps( props ) {
return omit( props, [
'__unstableMobileNoFocusOnMount',
'deleteEnter',
'placeholderTextColor',
'textAlign',
'selectionColor',
'tagsToEliminate',
'rootTagsToEliminate',
'disableEditingMenu',
'fontSize',
'fontFamily',
'fontWeight',
'fontStyle',
'minWidth',
'maxWidth',
'setRef',
'disableSuggestions',
'disableAutocorrection',
] );
const {
__unstableMobileNoFocusOnMount,
deleteEnter,
placeholderTextColor,
textAlign,
selectionColor,
tagsToEliminate,
rootTagsToEliminate,
disableEditingMenu,
fontSize,
fontFamily,
fontWeight,
fontStyle,
minWidth,
maxWidth,
setRef,
disableSuggestions,
disableAutocorrection,
...restProps
} = props;
return restProps;
}

function RichTextWrapper(
Expand Down Expand Up @@ -460,7 +461,8 @@ ForwardedRichTextContainer.Content = ( {
const content = <RawHTML>{ value }</RawHTML>;

if ( Tag ) {
return <Tag { ...omit( props, [ 'format' ] ) }>{ content }</Tag>;
const { format, ...restProps } = props;
return <Tag { ...restProps }>{ content }</Tag>;
}

return content;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import classnames from 'classnames';
import { omit } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -746,7 +745,8 @@ ForwardedRichTextContainer.Content = ( {
const content = <RawHTML>{ value }</RawHTML>;

if ( Tag ) {
return <Tag { ...omit( props, [ 'format' ] ) }>{ content }</Tag>;
const { format, ...restProps } = props;
return <Tag { ...restProps }>{ content }</Tag>;
}

return content;
Expand Down
13 changes: 8 additions & 5 deletions packages/block-editor/src/store/test/reducer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* External dependencies
*/
import { omit } from 'lodash';
import deepFreeze from 'deep-freeze';

/**
Expand Down Expand Up @@ -260,7 +259,8 @@ describe( 'state', () => {

const state = blocks( existingState, action );

expect( omit( state, [ 'tree' ] ) ).toEqual( {
const { tree, ...restState } = state;
expect( restState ).toEqual( {
isPersistentChange: true,
isIgnoredChange: false,
byClientId: {
Expand Down Expand Up @@ -342,7 +342,8 @@ describe( 'state', () => {

const state = blocks( existingState, action );

expect( omit( state, [ 'tree' ] ) ).toEqual( {
const { tree, ...restState } = state;
expect( restState ).toEqual( {
isPersistentChange: true,
isIgnoredChange: false,
byClientId: {
Expand Down Expand Up @@ -466,7 +467,8 @@ describe( 'state', () => {

const state = blocks( existingState, action );

expect( omit( state, [ 'tree' ] ) ).toEqual( {
const { tree, ...restState } = state;
expect( restState ).toEqual( {
isPersistentChange: true,
isIgnoredChange: false,
byClientId: {
Expand Down Expand Up @@ -603,7 +605,8 @@ describe( 'state', () => {

const state = blocks( existingState, action );

expect( omit( state, [ 'tree' ] ) ).toEqual( {
const { tree, ...restState } = state;
expect( restState ).toEqual( {
isPersistentChange: true,
isIgnoredChange: false,
byClientId: {
Expand Down

0 comments on commit c78c105

Please sign in to comment.