Skip to content

Commit

Permalink
Revise object equality check to account for identical arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
artemiomorales committed Jul 4, 2024
1 parent 4da3ae8 commit 4b01694
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion packages/is-shallow-equal/src/objects.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
/**
* Internal dependencies
*/
import isShallowEqualArrays from './arrays';

/**
* Checks for shallow array equality and returns true if the two values are equal, or false otherwise.
*
* @param {any} a
* @param {any} b
*
* @return {boolean} Whether the two values are equal.
*/
function isEqual( a, b ) {
if ( Array.isArray( a ) && Array.isArray( b ) ) {
return isShallowEqualArrays( a, b );
}

if ( a === b ) {
return true;
}

return false;
}

/**
* Returns true if the two objects are shallow equal, or false otherwise.
*
Expand Down Expand Up @@ -31,7 +56,7 @@ export default function isShallowEqualObjects( a, b ) {
//
// Example: isShallowEqualObjects( { a: undefined }, { b: 5 } )
( aValue === undefined && ! b.hasOwnProperty( key ) ) ||
aValue !== b[ key ]
! isEqual( aValue, b[ key ] )
) {
return false;
}
Expand Down

0 comments on commit 4b01694

Please sign in to comment.