atomic-state
Version:
Atomic State is a state management library for React
35 lines (34 loc) • 949 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports._isDefined = _isDefined;
exports._isFunction = _isFunction;
exports._isPromise = _isPromise;
exports.jsonEquality = jsonEquality;
function _isDefined(target) {
return typeof target !== 'undefined';
}
function _isFunction(target) {
return typeof target === 'function';
}
function _isPromise(target) {
return target instanceof Promise;
}
function jsonEquality(a, b) {
// Just parse arrays
if (Array.isArray(a)) {
return JSON.stringify(a) === JSON.stringify(b);
}
try {
const bProps = Object.keys(b);
let aMock = Object.assign({}, a);
// Making sure keys are in the same order
for (let prop of bProps) {
aMock[prop] = undefined;
aMock[prop] = a[prop];
}
return JSON.stringify(aMock) === JSON.stringify(b);
}
catch (_a) {
return false;
}
}