@microsoft/sp-webpart-base
Version:
SharePoint Framework support for building web parts
57 lines • 1.95 kB
JavaScript
;
// Copyright (c) Microsoft. All rights reserved.
Object.defineProperty(exports, "__esModule", { value: true });
/**
* @deprecated This was an optimization for a React-specific scenario, which
* is now solved by a newer React feature. See here:
* https://facebook.github.io/react/docs/shallow-compare.html
*
* @internal
*/
var Compare = /** @class */ (function () {
function Compare() {
}
/**
* Performs shallow comparison between two objects to determine if they are equal. This method compares
* only object types.
*
* @param objA - the first object to compare.
* @param objB - the second object to compare.
*
*/
Compare.shallowCompare = function (objA, objB) {
// Test if they are the same object or both are null/undefined.
if (objA === objB) {
return true;
}
// Test if they are the correct type. Only object types are compared.
if (typeof objA !== 'object' || !objA || typeof objB !== 'object' || !objB) {
return false;
}
var keysA = Object.keys(objA);
var keysB = Object.keys(objB);
// Test if they have the same number of keys. Else, they cannot be same.
var keyLength = keysA.length;
if (keyLength !== keysB.length) {
return false;
}
// Test for A's keys different from B.
var bHasOwnProperty = Object.prototype.hasOwnProperty.bind(objB);
for (var i = 0; i < keyLength; i++) {
var key = keysA[i];
if (!bHasOwnProperty(key)) {
return false;
}
var valueA = objA[key];
var valueB = objB[key];
// Test if the values are same.
if (valueA !== valueB) {
return false;
}
}
return true;
};
return Compare;
}());
exports.default = Compare;
//# sourceMappingURL=Compare.js.map