MCPcopy
hub / github.com/final-form/final-form / shallowEqual

Function shallowEqual

src/shallowEqual.ts:3–23  ·  view source on GitHub ↗
(a: any, b: any)

Source from the content-addressed store, hash-verified

1import type { IsEqual } from "./types";
2
3const shallowEqual: IsEqual = (a: any, b: any): boolean => {
4 if (a === b) {
5 return true;
6 }
7 if (typeof a !== "object" || !a || typeof b !== "object" || !b) {
8 return false;
9 }
10 const keysA = Object.keys(a);
11 const keysB = Object.keys(b);
12 if (keysA.length !== keysB.length) {
13 return false;
14 }
15 const bHasOwnProperty = Object.prototype.hasOwnProperty.bind(b);
16 for (let idx = 0; idx < keysA.length; idx++) {
17 const key = keysA[idx];
18 if (!bHasOwnProperty(key) || a[key] !== b[key]) {
19 return false;
20 }
21 }
22 return true;
23};
24
25export default shallowEqual;

Callers 5

memoizeFunction · 0.85
subscriptionFilterFunction · 0.85
processErrorsFunction · 0.85
calculateNextFormStateFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…