123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- 'use strict';
- const hasOwnProperty = Object.prototype.hasOwnProperty;
- function is(x: mixed, y: mixed): boolean {
-
- if (x === y) {
-
-
-
- return x !== 0 || y !== 0 || 1 / x === 1 / y;
- } else {
-
- return x !== x && y !== y;
- }
- }
- function shallowEqual(objA: mixed, objB: mixed): boolean {
- if (is(objA, objB)) {
- return true;
- }
- if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
- return false;
- }
- const keysA = Object.keys(objA);
- const keysB = Object.keys(objB);
- if (keysA.length !== keysB.length) {
- return false;
- }
-
- for (let i = 0; i < keysA.length; i++) {
- if (!hasOwnProperty.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) {
- return false;
- }
- }
- return true;
- }
- module.exports = shallowEqual;
|