All files / utils shallowEqual.js

82.35% Statements 14/17
80.95% Branches 17/21
100% Functions 2/2
92.86% Lines 13/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38      8x     3236x 2110x     1126x       952x 952x                 952x 952x   952x   952x 2284x 174x       778x    
// Credit to React-Redux for this util function
// https://github.com/reactjs/react-redux/blob/573db0bfc8d1d50fdb6e2a98bd8a7d4675fecf11/src/utils/shallowEqual.js
 
const hasOwn = Object.prototype.hasOwnProperty;
 
function is(x, y) {
	if (x === y) {
		return x !== 0 || y !== 0 || 1 / x === 1 / y;
	}
	// eslint-disable-next-line
	return x !== x && y !== y;
}
 
export default function shallowEqual(objA, objB) {
	Iif (is(objA, objB)) return true;
	Iif (
		typeof objA !== 'object'
		|| objA === null
		|| typeof objB !== 'object'
		|| objB === null
	) {
		return false;
	}
 
	const keysA = Object.keys(objA);
	const keysB = Object.keys(objB);
 
	Iif (keysA.length !== keysB.length) return false;
 
	for (let i = 0; i < keysA.length; i += 1) {
		if (!hasOwn.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) {
			return false;
		}
	}
 
	return true;
}