From 92a40bdbe6ecbdd4cca2f956423e64acd2a666dd Mon Sep 17 00:00:00 2001 From: Marin Atanasov <8436925+tyxla@users.noreply.github.com> Date: Tue, 10 Jan 2023 12:14:11 +0200 Subject: [PATCH] Lodash: Remove _.pickBy() from block editor and deprecate (#46999) --- .eslintrc.js | 1 + .../components/font-sizes/with-font-sizes.js | 66 +++++++++---------- 2 files changed, 34 insertions(+), 33 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 46c930ee0fb732..341c9d0a7dd856 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -115,6 +115,7 @@ const restrictedImports = [ 'partial', 'partialRight', 'pick', + 'pickBy', 'random', 'reduce', 'reject', diff --git a/packages/block-editor/src/components/font-sizes/with-font-sizes.js b/packages/block-editor/src/components/font-sizes/with-font-sizes.js index 380ea5a3dc0c5c..50f3ea77828170 100644 --- a/packages/block-editor/src/components/font-sizes/with-font-sizes.js +++ b/packages/block-editor/src/components/font-sizes/with-font-sizes.js @@ -1,8 +1,3 @@ -/** - * External dependencies - */ -import { pickBy } from 'lodash'; - /** * WordPress dependencies */ @@ -160,35 +155,40 @@ export default ( ...fontSizeNames ) => { } const newState = Object.entries( - pickBy( - fontSizeAttributeNames, - didAttributesChange + fontSizeAttributeNames + ) + .filter( ( [ key, value ] ) => + didAttributesChange( value, key ) ) - ).reduce( - ( - newStateAccumulator, - [ - fontSizeAttributeName, - customFontSizeAttributeName, - ] - ) => { - const fontSizeAttributeValue = - attributes[ fontSizeAttributeName ]; - const fontSizeObject = getFontSize( - fontSizes, - fontSizeAttributeValue, - attributes[ customFontSizeAttributeName ] - ); - newStateAccumulator[ fontSizeAttributeName ] = { - ...fontSizeObject, - class: getFontSizeClass( - fontSizeAttributeValue - ), - }; - return newStateAccumulator; - }, - {} - ); + .reduce( + ( + newStateAccumulator, + [ + fontSizeAttributeName, + customFontSizeAttributeName, + ] + ) => { + const fontSizeAttributeValue = + attributes[ fontSizeAttributeName ]; + const fontSizeObject = getFontSize( + fontSizes, + fontSizeAttributeValue, + attributes[ + customFontSizeAttributeName + ] + ); + newStateAccumulator[ + fontSizeAttributeName + ] = { + ...fontSizeObject, + class: getFontSizeClass( + fontSizeAttributeValue + ), + }; + return newStateAccumulator; + }, + {} + ); return { ...previousState,