MCPcopy
hub / github.com/bvaughn/react-window / shallowCompare

Function shallowCompare

lib/utils/shallowCompare.ts:3–29  ·  view source on GitHub ↗
(
  a: Type | undefined,
  b: Type | undefined
)

Source from the content-addressed store, hash-verified

1import { assert } from "./assert";
2
3export function shallowCompare<Type extends object>(
4 a: Type | undefined,
5 b: Type | undefined
6) {
7 if (a === b) {
8 return true;
9 }
10
11 if (!!a !== !!b) {
12 return false;
13 }
14
15 assert(a !== undefined);
16 assert(b !== undefined);
17
18 if (Object.keys(a).length !== Object.keys(b).length) {
19 return false;
20 }
21
22 for (const key in a) {
23 if (!Object.is(b[key], a[key])) {
24 return false;
25 }
26 }
27
28 return true;
29}

Callers 4

arePropsEqualFunction · 0.90
onScrollFunction · 0.90
useVirtualizerFunction · 0.90

Calls 1

assertFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…