Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/fast deep equal@2.0.1 #21

Merged
merged 2 commits into from
Jun 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 10 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ var keyList = Object.keys;
var hasProp = Object.prototype.hasOwnProperty;

function equal(a, b) {
// fast-deep-equal index.js 2.0.1
if (a === b) return true;

if (a && b && typeof a == 'object' && typeof b == 'object') {
var arrA = isArray(a)
, arrB = isArray(b)
, i
Expand All @@ -16,7 +18,7 @@ function equal(a, b) {
if (arrA && arrB) {
length = a.length;
if (length != b.length) return false;
for (i = 0; i < length; i++)
for (i = length; i-- !== 0;)
if (!equal(a[i], b[i])) return false;
return true;
}
Expand All @@ -33,17 +35,18 @@ function equal(a, b) {
if (regexpA != regexpB) return false;
if (regexpA && regexpB) return a.toString() == b.toString();

if (a instanceof Object && b instanceof Object) {
var keys = keyList(a);
length = keys.length;

if (length !== keyList(b).length)
return false;

for (i = 0; i < length; i++)
for (i = length; i-- !== 0;)
if (!hasProp.call(b, keys[i])) return false;
// end fast-deep-equal

for (i = 0; i < length; i++) {
// Custom handling for React
for (i = length; i-- !== 0;) {
key = keys[i];
if (key === '_owner' && a.$$typeof && a._store) {
// React-specific: avoid traversing React elements' _owner.
Expand All @@ -57,11 +60,13 @@ function equal(a, b) {
}
}

// fast-deep-equal index.js 2.0.1
return true;
}

return false;
return a!==a && b!==b;
}
// end fast-deep-equal

module.exports = function exportedEqual(a, b) {
try {
Expand Down