mirror of
https://github.com/EDCD/coriolis.git
synced 2025-12-09 14:45:35 +00:00
35 lines
825 B
JavaScript
35 lines
825 B
JavaScript
|
|
/**
|
|
* Compares A and B and return true using strict comparison (===)
|
|
* @param {any} objA A
|
|
* @param {any} objB B
|
|
* @return {boolean} true if A === B OR A properties === B properties
|
|
*/
|
|
export default function shallowEqual(objA, objB) {
|
|
if (objA === objB) {
|
|
return true;
|
|
}
|
|
|
|
if (typeof objA !== 'object' || objA === null ||
|
|
typeof objB !== 'object' || objB === null) {
|
|
return false;
|
|
}
|
|
|
|
let keysA = Object.keys(objA);
|
|
let keysB = Object.keys(objB);
|
|
|
|
if (keysA.length !== keysB.length) {
|
|
return false;
|
|
}
|
|
|
|
// Test for A's keys different from B.
|
|
let bHasOwnProperty = Object.prototype.hasOwnProperty.bind(objB);
|
|
for (let i = 0; i < keysA.length; i++) {
|
|
if (!bHasOwnProperty(keysA[i]) || objA[keysA[i]] !== objB[keysA[i]]) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|