source: node_modules/react-redux/src/utils/shallowEqual.ts

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 717 bytes
Line 
1function is(x: unknown, y: unknown) {
2 if (x === y) {
3 return x !== 0 || y !== 0 || 1 / x === 1 / y
4 } else {
5 return x !== x && y !== y
6 }
7}
8
9export default function shallowEqual(objA: any, objB: any) {
10 if (is(objA, objB)) return true
11
12 if (
13 typeof objA !== 'object' ||
14 objA === null ||
15 typeof objB !== 'object' ||
16 objB === null
17 ) {
18 return false
19 }
20
21 const keysA = Object.keys(objA)
22 const keysB = Object.keys(objB)
23
24 if (keysA.length !== keysB.length) return false
25
26 for (let i = 0; i < keysA.length; i++) {
27 if (
28 !Object.prototype.hasOwnProperty.call(objB, keysA[i]) ||
29 !is(objA[keysA[i]], objB[keysA[i]])
30 ) {
31 return false
32 }
33 }
34
35 return true
36}
Note: See TracBrowser for help on using the repository browser.