UNPKG

2.01 kBJavaScriptView Raw
1"use strict";
2// shallowEqual taken from Facebooks fbjs util and converted to typescript from flow
3// since this is used in react 16.x we trust FB that it works and disable code coverage here
4Object.defineProperty(exports, "__esModule", { value: true });
5exports.shallowEqual = void 0;
6/**
7 * Copyright (c) 2013-present, Facebook, Inc.
8 *
9 * This source code is licensed under the MIT license found in the
10 * LICENSE file in the root directory of this source tree.
11 */
12var hasOwnProperty = Object.prototype.hasOwnProperty;
13/**
14 * inlined Object.is polyfill to avoid requiring consumers ship their own
15 * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
16 */
17/* istanbul ignore next */
18function is(x, y) {
19 // SameValue algorithm
20 if (x === y) {
21 // Steps 1-5, 7-10
22 // Steps 6.b-6.e: +0 != -0
23 // Added the nonzero y check to make Flow happy, but it is redundant
24 return x !== 0 || y !== 0 || 1 / x === 1 / y;
25 }
26 else {
27 // Step 6.a: NaN == NaN
28 return x !== x && y !== y;
29 }
30}
31/**
32 * Performs equality by iterating through keys on an object and returning false
33 * when any key has values which are not strictly equal between the arguments.
34 * Returns true when the values of all keys are strictly equal.
35 */
36/* istanbul ignore next */
37function shallowEqual(objA, objB) {
38 if (is(objA, objB)) {
39 return true;
40 }
41 if (typeof objA !== "object" || objA === null || typeof objB !== "object" || objB === null) {
42 return false;
43 }
44 var keysA = Object.keys(objA);
45 var keysB = Object.keys(objB);
46 if (keysA.length !== keysB.length) {
47 return false;
48 }
49 // Test for A's keys different from B.
50 for (var i = 0; i < keysA.length; i++) {
51 if (!hasOwnProperty.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) {
52 return false;
53 }
54 }
55 return true;
56}
57exports.shallowEqual = shallowEqual;
58//# sourceMappingURL=shallowEqual.js.map
\No newline at end of file