alm
Version:
The best IDE for TypeScript
46 lines (45 loc) • 1.4 kB
JavaScript
;
/**
* Mutablity helpers
*/
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Shallow Equal and Shallow Compare from
* https://github.com/gaearon/react-pure-render/blob/master/src/shallowEqual.js
*
*/
function shouldComponentUpdate(nextProps, nextState) {
return !shallowEqual(this.props, nextProps) ||
!shallowEqual(this.state, nextState);
}
exports.shouldComponentUpdate = shouldComponentUpdate;
/**
* Performs equality by iterating through keys on an object and returning
* false when any key has values which are not strictly equal between
* objA and objB. Returns true when the values of all keys are strictly equal.
*
* @return {boolean}
*/
function shallowEqual(objA, objB) {
if (objA === objB) {
return true;
}
if (typeof objA !== 'object' || objA === null ||
typeof objB !== 'object' || objB === null) {
return false;
}
var keysA = Object.keys(objA);
var keysB = Object.keys(objB);
if (keysA.length !== keysB.length) {
return false;
}
// Test for A's keys different from B.
var bHasOwnProperty = Object.prototype.hasOwnProperty.bind(objB);
for (var i = 0; i < keysA.length; i++) {
if (!bHasOwnProperty(keysA[i]) || objA[keysA[i]] !== objB[keysA[i]]) {
return false;
}
}
return true;
}
exports.shallowEqual = shallowEqual;