Skip to content

Commit

Permalink
Lodash: Remove _.omit() from block library (#43707)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla authored Aug 31, 2022
1 parent cb684d9 commit a915113
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
10 changes: 7 additions & 3 deletions packages/block-library/src/gallery/v1/gallery-image.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, omit } from 'lodash';
import { get } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -111,14 +111,18 @@ class GalleryImage extends Component {
// written by the user, make sure the text is not overwritten.
if ( isTemporaryImage( id, url ) ) {
if ( alt ) {
mediaAttributes = omit( mediaAttributes, [ 'alt' ] );
const { alt: omittedAlt, ...restMediaAttributes } =
mediaAttributes;
mediaAttributes = restMediaAttributes;
}
}

// If a caption text was meanwhile written by the user,
// make sure the text is not overwritten by empty captions.
if ( caption && ! get( mediaAttributes, [ 'caption' ] ) ) {
mediaAttributes = omit( mediaAttributes, [ 'caption' ] );
const { caption: omittedCaption, ...restMediaAttributes } =
mediaAttributes;
mediaAttributes = restMediaAttributes;
}

setAttributes( mediaAttributes );
Expand Down
6 changes: 4 additions & 2 deletions packages/block-library/src/image/edit.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, isEmpty, omit, pick } from 'lodash';
import { get, isEmpty, pick } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -179,7 +179,9 @@ export function ImageEdit( {
// If a caption text was meanwhile written by the user,
// make sure the text is not overwritten by empty captions.
if ( captionRef.current && ! get( mediaAttributes, [ 'caption' ] ) ) {
mediaAttributes = omit( mediaAttributes, [ 'caption' ] );
const { caption: omittedCaption, ...restMediaAttributes } =
mediaAttributes;
mediaAttributes = restMediaAttributes;
}

let additionalAttributes;
Expand Down
9 changes: 3 additions & 6 deletions packages/block-library/src/list/utils.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { omit } from 'lodash';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -77,9 +72,11 @@ export function migrateToListV2( attributes ) {

const listBlock = createListBlockFromDOMElement( list );

const { values: omittedValues, ...restAttributes } = attributes;

return [
{
...omit( attributes, [ 'values' ] ),
...restAttributes,
...listBlock.attributes,
},
listBlock.innerBlocks,
Expand Down

0 comments on commit a915113

Please sign in to comment.