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

Commit

Permalink
Replace sortBy with fast sort package
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejolley committed Apr 21, 2023
1 parent c10bb11 commit 75cb6d7
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 14 deletions.
12 changes: 6 additions & 6 deletions assets/js/base/context/hooks/collections/use-collection-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
*/
import { useState, useEffect, useMemo } from '@wordpress/element';
import { useDebounce } from 'use-debounce';
import { sortBy } from 'lodash';
import { isEmpty } from 'lodash';
import { sort } from 'fast-sort';
import { useShallowEqual } from '@woocommerce/base-hooks';
import { objectHasProp, isEmpty } from '@woocommerce/types';
import { objectHasProp } from '@woocommerce/types';

/**
* Internal dependencies
Expand All @@ -22,17 +23,16 @@ const buildCollectionDataQuery = (
if (
Array.isArray( collectionDataQueryState.calculate_attribute_counts )
) {
query.calculate_attribute_counts = sortBy(
query.calculate_attribute_counts = sort(
collectionDataQueryState.calculate_attribute_counts.map(
( { taxonomy, queryType } ) => {
return {
taxonomy,
query_type: queryType,
};
}
),
[ 'taxonomy', 'query_type' ]
);
)
).asc( [ 'taxonomy', 'query_type' ] );
}

return query;
Expand Down
9 changes: 4 additions & 5 deletions assets/js/blocks/attribute-filter/edit.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { sortBy } from 'lodash';
import { sort } from 'fast-sort';
import { __, sprintf, _n } from '@wordpress/i18n';
import { useState } from '@wordpress/element';
import {
Expand Down Expand Up @@ -158,15 +158,14 @@ const Edit = ( {
),
};

const list = sortBy(
const list = sort(
ATTRIBUTES.map( ( item ) => {
return {
id: parseInt( item.attribute_id, 10 ),
name: item.attribute_label,
};
} ),
'name'
);
} )
).asc( 'name' );

return (
<SearchListControl
Expand Down
6 changes: 3 additions & 3 deletions assets/js/utils/attributes-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
AttributeQuery,
AttributeTerm,
} from '@woocommerce/types';
import { sortBy } from 'lodash';
import { sort } from 'fast-sort';

/**
* Given a query object, removes an attribute filter by a single slug.
Expand Down Expand Up @@ -51,7 +51,7 @@ export const removeAttributeFilterBySlug = (
returnQuery.push( currentQuery );
}

setQuery( sortBy( returnQuery, 'attribute' ) );
setQuery( sort( returnQuery ).asc( 'attribute' ) );
};

/**
Expand Down Expand Up @@ -88,7 +88,7 @@ export const updateAttributeFilter = (
operator,
slug: attributeTerms.map( ( { slug } ) => slug ).sort(),
} );
setQuery( sortBy( returnQuery, 'attribute' ) );
setQuery( sort( returnQuery ).asc( 'attribute' ) );
}

return returnQuery;
Expand Down
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@
"dompurify": "^2.4.0",
"downshift": "6.1.7",
"fast-deep-equal": "^3.1.3",
"fast-sort": "^3.4.0",
"html-react-parser": "3.0.4",
"postcode-validator": "3.7.0",
"preact": "^10.11.3",
Expand Down

0 comments on commit 75cb6d7

Please sign in to comment.