mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-04-20 12:28:08 +00:00
29 lines
691 B
TypeScript
29 lines
691 B
TypeScript
import { prototypeHasOwnProperty } from './has-own-property';
|
|
|
|
export function shallowEqual(objA: any, objB: any): boolean {
|
|
if (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.
|
|
const bHasOwnProperty = prototypeHasOwnProperty.bind(objB);
|
|
for (let i = 0; i < keysA.length; i++) {
|
|
if (!bHasOwnProperty(keysA[i]) || objA[keysA[i]] !== objB[keysA[i]]) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|