mirror of
https://github.com/zoriya/v10.git
synced 2026-08-16 02:45:09 +00:00
23 lines
562 B
TypeScript
23 lines
562 B
TypeScript
const hasOwn = Object.prototype.hasOwnProperty;
|
|
|
|
export function shallowEqual<T>(a: T, b: T): boolean {
|
|
if (Object.is(a, b)) return true;
|
|
|
|
if (typeof a !== 'object' || a === null || typeof b !== 'object' || b === null) {
|
|
return false;
|
|
}
|
|
|
|
const keysA = Object.keys(a);
|
|
const keysB = Object.keys(b);
|
|
|
|
if (keysA.length !== keysB.length) return false;
|
|
|
|
for (const key of keysA) {
|
|
if (!hasOwn.call(b, key) || !Object.is((a as Record<string, unknown>)[key], (b as Record<string, unknown>)[key])) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|