From 7cb2a7e72f61812b5309d3dbcd9e9acfb258b6cc Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Mon, 29 Jul 2019 13:20:46 +0100 Subject: [PATCH] Checks callbacks are functions prior to calling --- .../src/components/dimension-control/index.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/block-editor/src/components/dimension-control/index.js b/packages/block-editor/src/components/dimension-control/index.js index 2fab6515ab18d..29de7ed6b75a0 100644 --- a/packages/block-editor/src/components/dimension-control/index.js +++ b/packages/block-editor/src/components/dimension-control/index.js @@ -2,7 +2,7 @@ * External dependencies */ import classnames from 'classnames'; -import { noop } from 'lodash'; +import { isFunction } from 'lodash'; /** * WordPress dependencies @@ -25,7 +25,7 @@ import { import sizesTable, { findSizeBySlug } from './sizes'; export function DimensionControl( props ) { - const { label, icon, iconLabel = 'all', currentSize, onSpacingChange = noop, onReset = noop, className = '' } = props; + const { label, icon, iconLabel = 'all', currentSize, onSpacingChange, onReset, className = '' } = props; /** * Determines the size from the size slug (eg: `medium`) @@ -39,7 +39,7 @@ export function DimensionControl( props ) { if ( ! theSize || currentSize === theSize.slug ) { resetSpacing(); - } else { + } else if ( isFunction( onSpacingChange ) ) { onSpacingChange( theSize.slug ); } }; @@ -49,7 +49,11 @@ export function DimensionControl( props ) { * a dimension spacing values * @return {void} */ - const resetSpacing = () => onReset(); + const resetSpacing = () => { + if ( isFunction( onReset ) ) { + onReset(); + } + }; /** * Converts the sizes lookup tablet