Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lodash: Refactor away from _.values() #41905

Merged
merged 2 commits into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ module.exports = {
'toString',
'trim',
'uniqWith',
'values',
],
message:
'This Lodash method is not recommended. Please use native functionality instead. If using `memoize`, please use `memize` instead.',
Expand Down
11 changes: 6 additions & 5 deletions packages/components/src/mobile/segmented-control/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
Animated,
Easing,
} from 'react-native';
import { values, map, reduce } from 'lodash';
/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -101,11 +100,13 @@ const SegmentedControls = ( {
const { paddingLeft: offset } = isIOS
? styles.containerIOS
: styles.container;
const widths = map( values( segmentsDimensions ), 'width' );
const widths = Object.values( segmentsDimensions ).map(
( dimension ) => dimension.width
);
const widthsDistance = widths.slice( 0, index );
const widthsDistanceSum = reduce(
widthsDistance,
( sum, n ) => sum + n
const widthsDistanceSum = widthsDistance.reduce(
( sum, n ) => sum + n,
0
);

const endValue = index === 0 ? 0 : widthsDistanceSum;
Expand Down
13 changes: 5 additions & 8 deletions packages/edit-post/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import createSelector from 'rememo';
import { includes, some, values } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -43,8 +42,7 @@ export const isEditorSidebarOpened = createRegistrySelector(
select( interfaceStore ).getActiveComplementaryArea(
'core/edit-post'
);
return includes(
[ 'edit-post/document', 'edit-post/block' ],
return [ 'edit-post/document', 'edit-post/block' ].includes(
activeGeneralSidebar
);
}
Expand All @@ -65,8 +63,7 @@ export const isPluginSidebarOpened = createRegistrySelector(
);
return (
!! activeGeneralSidebar &&
! includes(
[ 'edit-post/document', 'edit-post/block' ],
! [ 'edit-post/document', 'edit-post/block' ].includes(
activeGeneralSidebar
)
);
Expand Down Expand Up @@ -254,7 +251,7 @@ export function isPublishSidebarOpened( state ) {
* @return {boolean} Whether or not the panel is removed.
*/
export function isEditorPanelRemoved( state, panelName ) {
return includes( state.removedPanels, panelName );
return state.removedPanels.includes( panelName );
}

/**
Expand Down Expand Up @@ -369,7 +366,7 @@ export const getActiveMetaBoxLocations = createSelector(
export function isMetaBoxLocationVisible( state, location ) {
return (
isMetaBoxLocationActive( state, location ) &&
some( getMetaBoxesPerLocation( state, location ), ( { id } ) => {
getMetaBoxesPerLocation( state, location )?.some( ( { id } ) => {
return isEditorPanelEnabled( state, `meta-box-${ id }` );
} )
);
Expand Down Expand Up @@ -410,7 +407,7 @@ export function getMetaBoxesPerLocation( state, location ) {
*/
export const getAllMetaBoxes = createSelector(
( state ) => {
return values( state.metaBoxes.locations ).flat();
return Object.values( state.metaBoxes.locations ).flat();
},
( state ) => [ state.metaBoxes.locations ]
);
Expand Down