You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-11-07 10:46:24 +03:00
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:
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user