@vlsergey/react-promise
Version:
React wrappers for Promises
18 lines (17 loc) • 756 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
/* Based on https://stackoverflow.com/a/52323412/7813776 with additional checks
and small optimizations */
/* eslint @typescript-eslint/no-explicit-any: 0 */
function shallowCompare(obj1, obj2) {
if (obj1 === undefined || obj2 === undefined)
return obj1 === undefined && obj2 === undefined;
if (obj1 === null || obj2 === null)
return obj1 === null && obj2 === null;
if (Object.keys(obj1).length !== Object.keys(obj2).length)
return false;
return Object.keys(obj1).every(function (key) {
return Object.prototype.hasOwnProperty.call(obj2, key) && obj1[key] === obj2[key];
});
}
exports.default = shallowCompare;