Skip to content

Commit

Permalink
Checks callbacks are functions prior to calling
Browse files Browse the repository at this point in the history
  • Loading branch information
getdave committed Jul 29, 2019
1 parent a4b9155 commit 7cb2a7e
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/block-editor/src/components/dimension-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* External dependencies
*/
import classnames from 'classnames';
import { noop } from 'lodash';
import { isFunction } from 'lodash';

/**
* WordPress dependencies
Expand All @@ -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`)
Expand All @@ -39,7 +39,7 @@ export function DimensionControl( props ) {

if ( ! theSize || currentSize === theSize.slug ) {
resetSpacing();
} else {
} else if ( isFunction( onSpacingChange ) ) {
onSpacingChange( theSize.slug );
}
};
Expand All @@ -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
Expand Down

0 comments on commit 7cb2a7e

Please sign in to comment.