Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81152 views
1
/**
2
* Copyright 2013-2014, Facebook, Inc.
3
* All rights reserved.
4
*
5
* This source code is licensed under the BSD-style license found in the
6
* LICENSE file in the root directory of this source tree. An additional grant
7
* of patent rights can be found in the PATENTS file in the same directory.
8
*
9
* @providesModule shallowEqual
10
*/
11
12
"use strict";
13
14
/**
15
* Performs equality by iterating through keys on an object and returning
16
* false when any key has values which are not strictly equal between
17
* objA and objB. Returns true when the values of all keys are strictly equal.
18
*
19
* @return {boolean}
20
*/
21
function shallowEqual(objA, objB) {
22
if (objA === objB) {
23
return true;
24
}
25
var key;
26
// Test for A's keys different from B.
27
for (key in objA) {
28
if (objA.hasOwnProperty(key) &&
29
(!objB.hasOwnProperty(key) || objA[key] !== objB[key])) {
30
return false;
31
}
32
}
33
// Test for B's keys missing from A.
34
for (key in objB) {
35
if (objB.hasOwnProperty(key) && !objA.hasOwnProperty(key)) {
36
return false;
37
}
38
}
39
return true;
40
}
41
42
module.exports = shallowEqual;
43
44