From 6402921038bce42ecdaece6c0ecf9fe3b403c59d Mon Sep 17 00:00:00 2001 From: Marin Atanasov <8436925+tyxla@users.noreply.github.com> Date: Mon, 13 Jun 2022 15:44:01 +0300 Subject: [PATCH] Lodash: Refactor away from _.sumBy() (#41688) --- .eslintrc.js | 1 + packages/block-library/src/columns/utils.js | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index d062c8460b038..f1680954b17f2 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -94,6 +94,7 @@ module.exports = { 'stubFalse', 'stubTrue', 'sum', + 'sumBy', ], message: 'This Lodash method is not recommended. Please use native functionality instead. If using `memoize`, please use `memize` instead.', diff --git a/packages/block-library/src/columns/utils.js b/packages/block-library/src/columns/utils.js index 1d3c0bc5238b9..b75a7ad77bba1 100644 --- a/packages/block-library/src/columns/utils.js +++ b/packages/block-library/src/columns/utils.js @@ -1,7 +1,7 @@ /** * External dependencies */ -import { sumBy, merge, mapValues } from 'lodash'; +import { merge, mapValues } from 'lodash'; /** * Returns a column width attribute value rounded to standard precision. @@ -44,8 +44,10 @@ export function getTotalColumnsWidth( blocks, totalBlockCount = blocks.length ) { - return sumBy( blocks, ( block ) => - getEffectiveColumnWidth( block, totalBlockCount ) + return blocks.reduce( + ( sum, block ) => + sum + getEffectiveColumnWidth( block, totalBlockCount ), + 0 ); }