Skip to content

Commit d8edb10

Browse files
authored
Lodash: Refactor away from _.values() (#41905)
* Lodash: Refactor away from _.values() * Add an initial value to the reduce call
1 parent ce461d8 commit d8edb10

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

.eslintrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ module.exports = {
115115
'toString',
116116
'trim',
117117
'uniqWith',
118+
'values',
118119
],
119120
message:
120121
'This Lodash method is not recommended. Please use native functionality instead. If using `memoize`, please use `memize` instead.',

packages/components/src/mobile/segmented-control/index.native.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
Animated,
1010
Easing,
1111
} from 'react-native';
12-
import { values, map, reduce } from 'lodash';
1312
/**
1413
* WordPress dependencies
1514
*/
@@ -101,11 +100,13 @@ const SegmentedControls = ( {
101100
const { paddingLeft: offset } = isIOS
102101
? styles.containerIOS
103102
: styles.container;
104-
const widths = map( values( segmentsDimensions ), 'width' );
103+
const widths = Object.values( segmentsDimensions ).map(
104+
( dimension ) => dimension.width
105+
);
105106
const widthsDistance = widths.slice( 0, index );
106-
const widthsDistanceSum = reduce(
107-
widthsDistance,
108-
( sum, n ) => sum + n
107+
const widthsDistanceSum = widthsDistance.reduce(
108+
( sum, n ) => sum + n,
109+
0
109110
);
110111

111112
const endValue = index === 0 ? 0 : widthsDistanceSum;

packages/edit-post/src/store/selectors.js

+5-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* External dependencies
33
*/
44
import createSelector from 'rememo';
5-
import { includes, some, values } from 'lodash';
65

76
/**
87
* WordPress dependencies
@@ -43,8 +42,7 @@ export const isEditorSidebarOpened = createRegistrySelector(
4342
select( interfaceStore ).getActiveComplementaryArea(
4443
'core/edit-post'
4544
);
46-
return includes(
47-
[ 'edit-post/document', 'edit-post/block' ],
45+
return [ 'edit-post/document', 'edit-post/block' ].includes(
4846
activeGeneralSidebar
4947
);
5048
}
@@ -65,8 +63,7 @@ export const isPluginSidebarOpened = createRegistrySelector(
6563
);
6664
return (
6765
!! activeGeneralSidebar &&
68-
! includes(
69-
[ 'edit-post/document', 'edit-post/block' ],
66+
! [ 'edit-post/document', 'edit-post/block' ].includes(
7067
activeGeneralSidebar
7168
)
7269
);
@@ -254,7 +251,7 @@ export function isPublishSidebarOpened( state ) {
254251
* @return {boolean} Whether or not the panel is removed.
255252
*/
256253
export function isEditorPanelRemoved( state, panelName ) {
257-
return includes( state.removedPanels, panelName );
254+
return state.removedPanels.includes( panelName );
258255
}
259256

260257
/**
@@ -369,7 +366,7 @@ export const getActiveMetaBoxLocations = createSelector(
369366
export function isMetaBoxLocationVisible( state, location ) {
370367
return (
371368
isMetaBoxLocationActive( state, location ) &&
372-
some( getMetaBoxesPerLocation( state, location ), ( { id } ) => {
369+
getMetaBoxesPerLocation( state, location )?.some( ( { id } ) => {
373370
return isEditorPanelEnabled( state, `meta-box-${ id }` );
374371
} )
375372
);
@@ -410,7 +407,7 @@ export function getMetaBoxesPerLocation( state, location ) {
410407
*/
411408
export const getAllMetaBoxes = createSelector(
412409
( state ) => {
413-
return values( state.metaBoxes.locations ).flat();
410+
return Object.values( state.metaBoxes.locations ).flat();
414411
},
415412
( state ) => [ state.metaBoxes.locations ]
416413
);

0 commit comments

Comments
 (0)