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: Refactor away from _.noop() #41674

Merged
merged 2 commits into from Jun 13, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Expand Up @@ -85,6 +85,7 @@ module.exports = {
'isUndefined',
'memoize',
'negate',
'noop',
'random',
'reverse',
'stubFalse',
Expand Down
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { noop } from 'lodash';

/**
* WordPress dependencies
*/
Expand All @@ -20,6 +15,8 @@ import { useDispatch } from '@wordpress/data';
import DownloadableBlockListItem from '../downloadable-block-list-item';
import { store as blockDirectoryStore } from '../../store';

const noop = () => {};

function DownloadableBlocksList( { items, onHover = noop, onSelect } ) {
const composite = useCompositeState();
const { installBlockType } = useDispatch( blockDirectoryStore );
Expand Down
3 changes: 2 additions & 1 deletion packages/block-editor/src/autocompleters/block.js
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { noop, orderBy } from 'lodash';
import { orderBy } from 'lodash';

/**
* WordPress dependencies
Expand All @@ -21,6 +21,7 @@ import useBlockTypesState from '../components/inserter/hooks/use-block-types-sta
import BlockIcon from '../components/block-icon';
import { store as blockEditorStore } from '../store';

const noop = () => {};
const SHOWN_BLOCK_TYPES = 9;

/** @typedef {import('@wordpress/components').WPCompleter} WPCompleter */
Expand Down
@@ -1,7 +1,3 @@
/**
* External dependencies
*/
import { noop } from 'lodash';
/**
* WordPress dependencies
*/
Expand All @@ -13,6 +9,8 @@ import {
__experimentalAlignmentMatrixControl as AlignmentMatrixControl,
} from '@wordpress/components';

const noop = () => {};

function BlockAlignmentMatrixControl( props ) {
const {
label = __( 'Change matrix alignment' ),
Expand Down
Expand Up @@ -2,13 +2,14 @@
* External dependencies
*/
import { shallow } from 'enzyme';
import { noop } from 'lodash';

/**
* Internal dependencies
*/
import BlockView from '../block-view';

const noop = () => {};

describe( 'BlockView', () => {
test( 'should match snapshot', () => {
const wrapper = shallow(
Expand Down
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import { shallow, mount } from 'enzyme';
import { noop } from 'lodash';

/**
* WordPress dependencies
Expand All @@ -19,6 +18,8 @@ import {
import { Edit } from '../edit';
import { BlockContextProvider } from '../../block-context';

const noop = () => {};

describe( 'Edit', () => {
afterEach( () => {
getBlockTypes().forEach( ( block ) => {
Expand Down
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { noop } from 'lodash';

/**
* WordPress dependencies
*/
Expand All @@ -17,6 +12,8 @@ import { compose } from '@wordpress/compose';
*/
import { store as blockEditorStore } from '../../store';

const noop = () => {};

export function BlockModeToggle( {
blockType,
mode,
Expand Down
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { castArray, flow, noop } from 'lodash';
import { castArray, flow } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -33,6 +33,7 @@ import { store as blockEditorStore } from '../../store';
import useBlockDisplayTitle from '../block-title/use-block-display-title';
import { useShowMoversGestures } from '../block-toolbar/utils';

const noop = () => {};
const POPOVER_PROPS = {
className: 'block-editor-block-settings-menu__popover',
position: 'bottom right',
Expand Down
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { noop, debounce } from 'lodash';
import { debounce } from 'lodash';
import classnames from 'classnames';

/**
Expand Down Expand Up @@ -39,6 +39,8 @@ function BlockStylesPreviewPanelFill( { children, scope, ...props } ) {
// The value is the equivalent of the container's right position.
const DEFAULT_POSITION_TOP = 16;

const noop = () => {};

// Block Styles component for the Settings Sidebar.
function BlockStyles( {
clientId,
Expand Down
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { noop } from 'lodash';

/**
* WordPress dependencies
*/
Expand All @@ -14,6 +9,8 @@ import { check } from '@wordpress/icons';
*/
import useStylesForBlocks from './use-styles-for-block';

const noop = () => {};

export default function BlockStylesMenuItems( { clientId, onSwitch = noop } ) {
const { onSelect, stylesToRender, activeStyle } = useStylesForBlocks( {
clientId,
Expand Down
@@ -1,15 +1,10 @@
/**
* External dependencies
*/
import { noop } from 'lodash';

/**
* WordPress dependencies
*/
import { useState, useRef, useEffect } from '@wordpress/element';

const { clearTimeout, setTimeout } = window;

const noop = () => {};
const DEBOUNCE_TIMEOUT = 200;

/**
Expand Down
Expand Up @@ -2,13 +2,14 @@
* External dependencies
*/
import { create, act } from 'react-test-renderer';
import { noop } from 'lodash';

/**
* Internal dependencies
*/
import ColorPaletteControl from '../control';

const noop = () => {};

describe( 'ColorPaletteControl', () => {
it( 'matches the snapshot', async () => {
let root;
Expand Down
Expand Up @@ -3,13 +3,14 @@
*/
import { render, screen } from '@testing-library/react';
import { create, act } from 'react-test-renderer';
import { noop } from 'lodash';

/**
* Internal dependencies
*/
import ColorGradientControl from '../control';

const noop = () => {};

const getButtonWithAriaLabelStartPredicate = ( ariaLabelStart ) => (
element
) => {
Expand Down
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { isEmpty, noop } from 'lodash';
import { isEmpty } from 'lodash';

/**
* WordPress dependencies
Expand All @@ -20,6 +20,7 @@ import { __ } from '@wordpress/i18n';
import useDimensionHandler from './use-dimension-handler';

const IMAGE_SIZE_PRESETS = [ 25, 50, 75, 100 ];
const noop = () => {};

export default function ImageSizeControl( {
imageWidth,
Expand Down
7 changes: 2 additions & 5 deletions packages/block-editor/src/components/inserter/library.js
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { noop } from 'lodash';

/**
* WordPress dependencies
*/
Expand All @@ -15,6 +10,8 @@ import { forwardRef } from '@wordpress/element';
import InserterMenu from './menu';
import { store as blockEditorStore } from '../../store';

const noop = () => {};

function InserterLibrary(
{
rootClientId,
Expand Down
@@ -1,7 +1,6 @@
/**
* External dependencies
*/
import { noop } from 'lodash';
import classnames from 'classnames';

/**
Expand Down Expand Up @@ -97,6 +96,8 @@ import { DEFAULT_LINK_SETTINGS } from './constants';
* @property {Function} renderControlBottom Optional controls to be rendered at the bottom of the component.
*/

const noop = () => {};

/**
* Renders a link control. A link control is a controlled input which maintains
* a value associated with a link (HTML anchor element) and relevant settings
Expand Down
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { noop, omit } from 'lodash';
import { omit } from 'lodash';
import classnames from 'classnames';
/**
* WordPress dependencies
Expand All @@ -23,6 +23,8 @@ import useSearchHandler from './use-search-handler';
// which will cause an unintended http request.
const noopSearchHandler = () => Promise.resolve( [] );

const noop = () => {};

const LinkControlSearchInput = forwardRef(
(
{
Expand Down
@@ -1,14 +1,11 @@
/**
* External dependencies
*/
import { noop } from 'lodash';

/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { ToggleControl, VisuallyHidden } from '@wordpress/components';

const noop = () => {};

const LinkControlSettingsDrawer = ( { value, onChange = noop, settings } ) => {
if ( ! settings || ! settings.length ) {
return null;
Expand Down
@@ -1,7 +1,6 @@
/**
* External dependencies
*/
import { noop } from 'lodash';
import classnames from 'classnames';

/**
Expand All @@ -27,6 +26,8 @@ import MediaUploadCheck from '../media-upload/check';
import URLPopover from '../url-popover';
import { store as blockEditorStore } from '../../store';

const noop = () => {};

const InsertFromURLPopover = ( { src, onChange, onSubmit, onClose } ) => (
<URLPopover onClose={ onClose }>
<form
Expand Down
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { noop, uniqueId } from 'lodash';
import { uniqueId } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -37,6 +37,8 @@ import MediaUploadCheck from '../media-upload/check';
import LinkControl from '../link-control';
import { store as blockEditorStore } from '../../store';

const noop = () => {};

const MediaReplaceFlow = ( {
mediaURL,
mediaId,
Expand Down
Expand Up @@ -2,13 +2,14 @@
* External dependencies
*/
import { render } from '@testing-library/react';
import { noop } from 'lodash';

/**
* Internal dependencies
*/
import PanelColorSettings from '../';

const noop = () => {};

describe( 'PanelColorSettings', () => {
it( 'should not render anything if there are no colors to choose', async () => {
const { container } = render(
Expand Down
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { last, noop } from 'lodash';
import { last } from 'lodash';

/**
* WordPress dependencies
Expand All @@ -15,6 +15,8 @@ import { cloneBlock } from '@wordpress/blocks';
*/
import { store as blockEditorStore } from '../../store';

const noop = () => {};

/**
* A function to call when the block value has been updated in the block-editor
* store.
Expand Down
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { noop } from 'lodash';

/**
* WordPress dependencies
*/
Expand All @@ -16,6 +11,8 @@ import {
import { Picker } from '@wordpress/components';
import { __ } from '@wordpress/i18n';

const noop = () => {};

const DEFAULT_PICKER_OPTIONS = [
{
id: 'createEmbed',
Expand Down