Skip to content

Commit

Permalink
Lodash: Refactor away from _.without() (#44980)
Browse files Browse the repository at this point in the history
* Lodash: Refactor away from _.without()

* Add @wordpress/components changelog
  • Loading branch information
tyxla authored Oct 20, 2022
1 parent 1c5a80f commit 1b73e8b
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 19 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,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
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- `Sandbox`: Use `toString` to create observe and resize script string ([#42872](https://github.com/WordPress/gutenberg/pull/42872)).
- `Navigator`: refactor unit tests to TypeScript and to `user-event` ([#44970](https://github.com/WordPress/gutenberg/pull/44970)).
- `Navigator`: Refactor Storybook code to TypeScript and controls ([#44979](https://github.com/WordPress/gutenberg/pull/44979)).
- `withFilters`: Refactor away from `_.without()` ([#44980](https://github.com/WordPress/gutenberg/pull/44980/)).
- `withFocusReturn`: Refactor tests to `@testing-library/react` ([#45012](https://github.com/WordPress/gutenberg/pull/45012)).
- `ToolsPanel`: updated to satisfy `react/exhaustive-deps` eslint rule ([#45028](https://github.com/WordPress/gutenberg/pull/45028))
- `Tooltip`: updated to ignore `react/exhaustive-deps` eslint rule ([#45043](https://github.com/WordPress/gutenberg/pull/45043))
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 1b73e8b

Please sign in to comment.