Skip to content

Commit

Permalink
Optimize parseUnit with keyBy rather than Array.find
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Q committed May 20, 2020
1 parent 8949a04 commit 8fdc6e8
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/components/src/unit-control/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { isEmpty } from 'lodash';
import { isEmpty, keyBy } from 'lodash';

export const CSS_UNITS = [
{ value: 'px', label: 'px', default: 0 },
Expand Down Expand Up @@ -61,7 +61,7 @@ export function parseUnit( initialValue, units = CSS_UNITS ) {
unit = unit.toLowerCase();

if ( hasUnits( units ) ) {
const match = units.find( ( item ) => item.value === unit );
const match = keyBy( units, 'value' )[ unit ];
unit = match?.value;
}

Expand Down

0 comments on commit 8fdc6e8

Please sign in to comment.