@mui/x-charts
Version:
The community edition of MUI X Charts components.
31 lines (30 loc) • 1.01 kB
JavaScript
/**
* Performs equality by iterating through keys on an object and returning false
* when any key has values which are not strictly equal between the arguments.
* Returns true when the values of all keys are strictly equal.
*
* Source: https://github.com/facebook/react/blob/c2a196174763e0b4f16ed1c512ed4442b062395e/packages/shared/shallowEqual.js#L18
*/
export function shallowEqual(objA, objB) {
if (Object.is(objA, objB)) {
return true;
}
if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
return false;
}
const keysA = Object.keys(objA);
const keysB = Object.keys(objB);
if (keysA.length !== keysB.length) {
return false;
}
// Test for A's keys different from B.
for (let i = 0; i < keysA.length; i += 1) {
const currentKey = keysA[i];
if (!Object.prototype.hasOwnProperty.call(objB, currentKey) ||
// @ts-ignore
!Object.is(objA[currentKey], objB[currentKey])) {
return false;
}
}
return true;
}