Skip to content

Commit

Permalink
Lodash: Refactor away from _.sumBy() (#41688)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla committed Jun 13, 2022
1 parent 2bc9f33 commit 6402921
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down
8 changes: 5 additions & 3 deletions packages/block-library/src/columns/utils.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
);
}

Expand Down

0 comments on commit 6402921

Please sign in to comment.