From 66fe90adb585f541478a5b4e7d56e0ac77f2b86e Mon Sep 17 00:00:00 2001 From: Marin Atanasov Date: Wed, 12 Oct 2022 11:15:37 +0300 Subject: [PATCH 1/2] Lodash: Refactor away from _.every() in block editor --- .../src/components/colors-gradients/control.js | 4 ++-- .../colors-gradients/panel-color-gradient-settings.js | 7 +++---- packages/block-editor/src/hooks/utils.js | 4 ++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/block-editor/src/components/colors-gradients/control.js b/packages/block-editor/src/components/colors-gradients/control.js index 34e4f334e3c588..685adea3a664d6 100644 --- a/packages/block-editor/src/components/colors-gradients/control.js +++ b/packages/block-editor/src/components/colors-gradients/control.js @@ -2,7 +2,7 @@ * External dependencies */ import classnames from 'classnames'; -import { every, isEmpty } from 'lodash'; +import { isEmpty } from 'lodash'; /** * WordPress dependencies @@ -180,7 +180,7 @@ function ColorGradientControlSelect( props ) { function ColorGradientControl( props ) { if ( - every( colorsAndGradientKeys, ( key ) => props.hasOwnProperty( key ) ) + colorsAndGradientKeys.every( ( key ) => props.hasOwnProperty( key ) ) ) { return ; } diff --git a/packages/block-editor/src/components/colors-gradients/panel-color-gradient-settings.js b/packages/block-editor/src/components/colors-gradients/panel-color-gradient-settings.js index 797a6c9463697d..a69a53e549902a 100644 --- a/packages/block-editor/src/components/colors-gradients/panel-color-gradient-settings.js +++ b/packages/block-editor/src/components/colors-gradients/panel-color-gradient-settings.js @@ -2,7 +2,7 @@ * External dependencies */ import classnames from 'classnames'; -import { every, isEmpty } from 'lodash'; +import { isEmpty } from 'lodash'; /** * WordPress dependencies @@ -50,8 +50,7 @@ export const PanelColorGradientSettingsInner = ( { isEmpty( gradients ) && disableCustomColors && disableCustomGradients && - every( - settings, + settings?.every( ( setting ) => isEmpty( setting.colors ) && isEmpty( setting.gradients ) && @@ -137,7 +136,7 @@ const PanelColorGradientSettingsMultipleSelect = ( props ) => { const PanelColorGradientSettings = ( props ) => { if ( - every( colorsAndGradientKeys, ( key ) => props.hasOwnProperty( key ) ) + colorsAndGradientKeys.every( ( key ) => props.hasOwnProperty( key ) ) ) { return ; } diff --git a/packages/block-editor/src/hooks/utils.js b/packages/block-editor/src/hooks/utils.js index 8d638e997d828a..b3e09e4598e5fd 100644 --- a/packages/block-editor/src/hooks/utils.js +++ b/packages/block-editor/src/hooks/utils.js @@ -1,7 +1,7 @@ /** * External dependencies */ -import { pickBy, isEmpty, mapValues, get, setWith, clone, every } from 'lodash'; +import { pickBy, isEmpty, mapValues, get, setWith, clone } from 'lodash'; /** * WordPress dependencies @@ -44,7 +44,7 @@ export function transformStyles( results ) { // If there are no active supports return early. - if ( every( activeSupports, ( isActive ) => ! isActive ) ) { + if ( Object.values( activeSupports ).every( ( isActive ) => ! isActive ) ) { return result; } // If the condition verifies we are probably in the presence of a wrapping transform From 2f0b910e4991a133107cf559d7a197af5e1985ae Mon Sep 17 00:00:00 2001 From: Marin Atanasov Date: Wed, 12 Oct 2022 14:46:19 +0300 Subject: [PATCH 2/2] Tighten up activeSupports --- packages/block-editor/src/hooks/utils.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/block-editor/src/hooks/utils.js b/packages/block-editor/src/hooks/utils.js index b3e09e4598e5fd..24cb2fa851bc40 100644 --- a/packages/block-editor/src/hooks/utils.js +++ b/packages/block-editor/src/hooks/utils.js @@ -44,7 +44,11 @@ export function transformStyles( results ) { // If there are no active supports return early. - if ( Object.values( activeSupports ).every( ( isActive ) => ! isActive ) ) { + if ( + Object.values( activeSupports ?? {} ).every( + ( isActive ) => ! isActive + ) + ) { return result; } // If the condition verifies we are probably in the presence of a wrapping transform