Skip to content

Commit

Permalink
Lodash: Refactor away from _.without()
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla committed Oct 20, 2022
1 parent a9677c6 commit dce3347
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 19 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ module.exports = {
'uniqWith',
'upperFirst',
'values',
'without',
'xor',
'zip',
],
Expand Down
6 changes: 4 additions & 2 deletions packages/block-library/src/navigation-submenu/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 { escape, without } from 'lodash';
import { escape } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -486,7 +486,9 @@ export default function NavigationSubmenuEdit( {
const innerBlocksColors = getColors( context, true );

const allowedBlocks = isAtMaxNesting
? without( ALLOWED_BLOCKS, 'core/navigation-submenu' )
? ALLOWED_BLOCKS.filter(
( blockName ) => blockName !== 'core/navigation-submenu'
)
: ALLOWED_BLOCKS;

const innerBlocksProps = useInnerBlocksProps(
Expand Down
13 changes: 4 additions & 9 deletions packages/components/src/higher-order/with-filters/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { without } from 'lodash';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -64,10 +59,10 @@ export default function withFilters( hookName ) {
}

componentWillUnmount() {
FilteredComponentRenderer.instances = without(
FilteredComponentRenderer.instances,
this
);
FilteredComponentRenderer.instances =
FilteredComponentRenderer.instances.filter(
( instance ) => instance !== this
);

// If this was the last of the mounted components filtered on
// this hook, remove the hook handler.
Expand Down
7 changes: 1 addition & 6 deletions packages/customize-widgets/src/filters/move-to-sidebar.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { without } from 'lodash';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -63,7 +58,7 @@ const withMoveToSidebarToolbarItem = createHigherOrderComponent(
const oldSetting = activeSidebarControl.setting;
const newSetting = newSidebarControl.setting;

oldSetting( without( oldSetting(), widgetId ) );
oldSetting( oldSetting().filter( ( id ) => id !== widgetId ) );
newSetting( [ ...newSetting(), widgetId ] );
} else {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { find, get, some, unescape as unescapeString, without } from 'lodash';
import { find, get, some, unescape as unescapeString } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -258,7 +258,7 @@ export function HierarchicalTermSelector( { slug } ) {
const onChange = ( termId ) => {
const hasTerm = terms.includes( termId );
const newTerms = hasTerm
? without( terms, termId )
? terms.filter( ( id ) => id !== termId )
: [ ...terms, termId ];
onUpdateTerms( newTerms );
};
Expand Down

0 comments on commit dce3347

Please sign in to comment.