Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
replace lodash keyby
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejolley committed Apr 21, 2023
1 parent 8a645a4 commit 12e5ab6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* External dependencies
*/
import { keyBy } from 'lodash';
import { decodeEntities } from '@wordpress/html-entities';
import {
Dictionary,
Expand All @@ -10,6 +9,7 @@ import {
ProductResponseTermItem,
ProductResponseVariationsItem,
} from '@woocommerce/types';
import { keyBy } from '@woocommerce/base-utils';

/**
* Internal dependencies
Expand Down
1 change: 1 addition & 0 deletions assets/js/base/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ export * from './create-notice';
export * from './get-navigation-type';
export * from './camel-case-keys';
export * from './debounce';
export * from './keyby';
7 changes: 7 additions & 0 deletions assets/js/base/utils/keyby.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const keyBy = < T >( array: T[], key: keyof T ) => {
return array.reduce( ( acc, value ) => {
const computedKey = key ? String( value[ key ] ) : String( value );
acc[ computedKey ] = value;
return acc;
}, {} as Record< string, T > );
};
3 changes: 2 additions & 1 deletion assets/js/editor-components/search-list-control/utils.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/**
* External dependencies
*/
import { groupBy, keyBy } from 'lodash';
import { groupBy } from 'lodash';
import { Fragment } from '@wordpress/element';
import { __, _n, sprintf } from '@wordpress/i18n';
import { keyBy } from '@woocommerce/base-utils';

/**
* Internal dependencies
Expand Down

0 comments on commit 12e5ab6

Please sign in to comment.