1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-09-01 21:21:58 +03:00

Add concept of 'sentinel' RoomMembers which watch state at a particular point in time.

New sentinels are only created when the RoomMember state changes, so we don't
needlessly deep copy RoomMembers f.e. MatrixEvent. Sentinels co-exist with
RoomState.members which are single instances to which listeners can be attached.
This gets the best of both worlds (don't have to keep re-attaching listeners on
member changes, don't have needless memory consumption).
This commit is contained in:
Kegan Dougal
2015-06-12 15:38:02 +01:00
parent 8a844d59ec
commit 7a02c5d167
4 changed files with 62 additions and 17 deletions

View File

@@ -159,7 +159,22 @@ module.exports.checkObjectHasNoAdditionalKeys = function(obj, allowedKeys) {
};
/**
* Deep copy the given object. The object MUST NOT have circular references.
* Assigns all the properties in src to dst. If these properties are Objects,
* then both src and dst will refer to the same thing.
* @param {Object} src The object to copy properties from.
* @param {Object} dst The object to write properties to.
*/
module.exports.shallowCopy = function(src, dst) {
for (var i in src) {
if (src.hasOwnProperty(i)) {
dst[i] = src[i];
}
}
};
/**
* Deep copy the given object. The object MUST NOT have circular references and
* MUST NOT have functions.
* @param {Object} obj The object to deep copy.
* @return {Object} A copy of the object without any references to the original.
*/