Add shouldComponentUpdate() methods to RoomView and TimelinePanel

This will avoid re-rendering the whole RoomView every time we get a scroll
event, and might even help with https://github.com/vector-im/vector-web/issues/1056.
This commit is contained in:
Richard van der Hoff 2016-03-04 14:51:55 +00:00
parent 05a3dab528
commit bc5ae6a6ad
3 changed files with 43 additions and 0 deletions

View file

@ -77,3 +77,34 @@ module.exports.getKeyValueArrayDiffs = function(before, after) {
return results;
};
/**
* Shallow-compare two objects for equality: each key and value must be
* identical
*/
module.exports.shallowEqual = function(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;
}
for (var i = 0; i < keysA.length; i++) {
var key = keysA[i];
if (!objB.hasOwnProperty(key) || objA[key] !== objB[key]) {
return false;
}
}
return true;
};