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: Remove _.omit() from @wordpress/blocks #43711

Merged
merged 1 commit into from
Aug 31, 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 { omit, castArray } from 'lodash';
import { castArray } from 'lodash';

/**
* Internal dependencies
Expand All @@ -10,6 +10,7 @@ import { DEPRECATED_ENTRY_KEYS } from '../constants';
import { validateBlock } from '../validation';
import { getBlockAttributes } from './get-block-attributes';
import { applyBuiltInValidationFixes } from './apply-built-in-validation-fixes';
import { omit } from '../utils';

/**
* Function that takes no arguments and always returns false.
Expand Down
10 changes: 2 additions & 8 deletions packages/blocks/src/api/parser/fix-custom-classname.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { omit } from 'lodash';

/**
* Internal dependencies
*/
Expand Down Expand Up @@ -52,9 +47,8 @@ export function fixCustomClassname( blockAttributes, blockType, innerHTML ) {
// attributes, with the exception of `className`. This will determine
// the default set of classes. From there, any difference in innerHTML
// can be considered as custom classes.
const attributesSansClassName = omit( blockAttributes, [
'className',
] );
const { className: omittedClassName, ...attributesSansClassName } =
blockAttributes;
const serialized = getSaveContent( blockType, attributesSansClassName );
const defaultClasses = getHTMLRootElementClasses( serialized );
const actualClasses = getHTMLRootElementClasses( innerHTML );
Expand Down
6 changes: 2 additions & 4 deletions packages/blocks/src/api/test/registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@ import {
unstable__bootstrapServerSideBlockDefinitions, // eslint-disable-line camelcase
} from '../registration';
import { BLOCK_ICON_DEFAULT, DEPRECATED_ENTRY_KEYS } from '../constants';
import { omit } from '../utils';
import { store as blocksStore } from '../../store';

const noop = () => {};
const omit = ( obj, keys ) =>
Object.fromEntries(
Object.entries( obj ).filter( ( [ key ] ) => ! keys.includes( key ) )
);

const pick = ( obj, keys ) =>
Object.fromEntries(
Object.entries( obj ).filter( ( [ key ] ) => keys.includes( key ) )
Expand Down
14 changes: 14 additions & 0 deletions packages/blocks/src/api/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,17 @@ export function __experimentalGetBlockAttributesNamesByRole( name, role ) {
attributes[ attributeName ]?.__experimentalRole === role
);
}

/**
* Return a new object with the specified keys omitted.
*
* @param {Object} object Original object.
* @param {Array} keys Keys to be omitted.
*
* @return {Object} Object with omitted keys.
*/
export function omit( object, keys ) {
return Object.fromEntries(
Object.entries( object ).filter( ( [ key ] ) => ! keys.includes( key ) )
);
}
4 changes: 2 additions & 2 deletions packages/blocks/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* External dependencies
*/
import { isPlainObject } from 'is-plain-object';
import { castArray, omit, pick, some } from 'lodash';
import { castArray, pick, some } from 'lodash';

/**
* WordPress dependencies
Expand All @@ -12,7 +12,7 @@ import { applyFilters } from '@wordpress/hooks';
/**
* Internal dependencies
*/
import { isValidIcon, normalizeIconObject } from '../api/utils';
import { isValidIcon, normalizeIconObject, omit } from '../api/utils';
import { DEPRECATED_ENTRY_KEYS } from '../api/constants';

/** @typedef {import('../api/registration').WPBlockVariation} WPBlockVariation */
Expand Down
7 changes: 6 additions & 1 deletion packages/blocks/src/store/reducer.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
/**
* External dependencies
*/
import { filter, find, get, isEmpty, map, mapValues, omit } from 'lodash';
import { filter, find, get, isEmpty, map, mapValues } from 'lodash';

/**
* WordPress dependencies
*/
import { combineReducers } from '@wordpress/data';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import { omit } from '../api/utils';

/**
* @typedef {Object} WPBlockCategory
*
Expand Down