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

Commit

Permalink
Replace lodash isEqual with fastDeepEqual
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejolley committed Apr 20, 2023
1 parent afad1d6 commit be07aee
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 12 deletions.
10 changes: 6 additions & 4 deletions assets/js/base/components/product-list/product-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* External dependencies
*/
import { __, _n, sprintf } from '@wordpress/i18n';
import { isEqual } from 'lodash';
import fastDeepEqual from 'fast-deep-equal/es6';
import classnames from 'classnames';
import Pagination from '@woocommerce/base-components/pagination';
import { useEffect } from '@wordpress/element';
Expand Down Expand Up @@ -113,7 +113,9 @@ const announceLoadingCompletion = ( totalProducts: number ): void => {
const areQueryTotalsDifferent: AreQueryTotalsDifferent = (
{ totalQuery: nextQuery, totalProducts: nextProducts },
{ totalQuery: currentQuery } = {}
) => ! isEqual( nextQuery, currentQuery ) && Number.isFinite( nextProducts );
) =>
! fastDeepEqual( nextQuery, currentQuery ) &&
Number.isFinite( nextProducts );

const ProductList = ( {
attributes,
Expand Down Expand Up @@ -169,7 +171,7 @@ const ProductList = ( {

// If query state (excluding pagination/sorting attributes) changed, reset pagination to the first page.
useEffect( () => {
if ( isEqual( totalQuery, previousQueryTotals?.totalQuery ) ) {
if ( fastDeepEqual( totalQuery, previousQueryTotals?.totalQuery ) ) {
return;
}
onPageChange( 1 );
Expand Down Expand Up @@ -210,7 +212,7 @@ const ProductList = ( {
const totalPages =
! Number.isFinite( totalProducts ) &&
Number.isFinite( previousQueryTotals?.totalProducts ) &&
isEqual( totalQuery, previousQueryTotals?.totalQuery )
fastDeepEqual( totalQuery, previousQueryTotals?.totalQuery )
? Math.ceil( ( previousQueryTotals?.totalProducts || 0 ) / perPage )
: Math.ceil( totalProducts / perPage );
const listProducts = products.length
Expand Down
4 changes: 2 additions & 2 deletions assets/js/base/context/hooks/cart/use-store-cart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* External dependencies
*/
import { isEqual } from 'lodash';
import fastDeepEqual from 'fast-deep-equal/es6';
import { useRef } from '@wordpress/element';
import {
CART_STORE_KEY as storeKey,
Expand Down Expand Up @@ -247,7 +247,7 @@ export const useStoreCart = (

if (
! currentResults.current ||
! isEqual( currentResults.current, results )
! fastDeepEqual( currentResults.current, results )
) {
currentResults.current = results;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { UniqueIdentifier } from '@dnd-kit/core';
import apiFetch from '@wordpress/api-fetch';
import { dispatch } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { isEqual } from 'lodash';
import fastDeepEqual from 'fast-deep-equal/es6';

/**
* Internal dependencies
Expand Down Expand Up @@ -139,11 +139,14 @@ export const SettingsProvider = ( {
} ).then( ( response ) => {
setIsSaving( false );
if (
isEqual(
fastDeepEqual(
response.pickup_location_settings,
data.pickup_location_settings
) &&
isEqual( response.pickup_locations, data.pickup_locations )
fastDeepEqual(
response.pickup_locations,
data.pickup_locations
)
) {
dispatch( 'core/notices' ).createSuccessNotice(
__(
Expand Down
8 changes: 5 additions & 3 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 @@ -257,6 +257,7 @@
"dinero.js": "1.9.1",
"dompurify": "^2.4.0",
"downshift": "6.1.7",
"fast-deep-equal": "^3.1.3",
"html-react-parser": "3.0.4",
"postcode-validator": "3.7.0",
"preact": "^10.11.3",
Expand Down

0 comments on commit be07aee

Please sign in to comment.