MCPcopy
hub / github.com/google-map-react/google-map-react / shallowEqual

Function shallowEqual

src/utils/shallowEqual.js:36–68  ·  view source on GitHub ↗

* Performs equality by iterating through keys on an object and returning false * when any key has values which are not strictly equal between the arguments. * Returns true when the values of all keys are strictly equal.

(objA, objB)

Source from the content-addressed store, hash-verified

34 * Returns true when the values of all keys are strictly equal.
35 */
36function shallowEqual(objA, objB) {
37 if (is(objA, objB)) {
38 return true;
39 }
40
41 if (
42 typeof objA !== 'object' ||
43 objA === null ||
44 typeof objB !== 'object' ||
45 objB === null
46 ) {
47 return false;
48 }
49
50 const keysA = Object.keys(objA);
51 const keysB = Object.keys(objB);
52
53 if (keysA.length !== keysB.length) {
54 return false;
55 }
56
57 // Test for A's keys different from B.
58 for (let i = 0; i < keysA.length; i++) {
59 if (
60 !hasOwnProperty.call(objB, keysA[i]) ||
61 !is(objA[keysA[i]], objB[keysA[i]])
62 ) {
63 return false;
64 }
65 }
66
67 return true;
68}
69
70export default shallowEqual;
71/* src: https://github.com/facebook/fbjs/blob/master/packages/fbjs/src/core/shallowEqual.js */

Callers 3

shouldComponentUpdateFunction · 0.85
shouldComponentUpdateMethod · 0.85
componentDidUpdateMethod · 0.85

Calls 1

isFunction · 0.85

Tested by

no test coverage detected