MCPcopy Create free account
hub / github.com/BetaSu/big-react / shallowEqual

Function shallowEqual

packages/shared/shallowEquals.ts:1–30  ·  view source on GitHub ↗
(a: any, b: any)

Source from the content-addressed store, hash-verified

1export function shallowEqual(a: any, b: any): boolean {
2 if (Object.is(a, b)) {
3 return true;
4 }
5
6 if (
7 typeof a !== 'object' ||
8 a === null ||
9 typeof b !== 'object' ||
10 b === null
11 ) {
12 return false;
13 }
14
15 const keysA = Object.keys(a);
16 const keysB = Object.keys(b);
17
18 if (keysA.length !== keysB.length) {
19 return false;
20 }
21
22 for (let i = 0; i < keysA.length; i++) {
23 const key = keysA[i];
24 // b没有key、 key不想等
25 if (!{}.hasOwnProperty.call(b, key) || !Object.is(a[key], b[key])) {
26 return false;
27 }
28 }
29 return true;
30}

Callers 1

updateMemoComponentFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected