Only maintain one GroupStore in the GroupStoreCache
So that the group store data is up-to-date and to prevent group stores hanging around in memory
This commit is contained in:
parent
b16eb1713e
commit
c1318e9102
2 changed files with 15 additions and 13 deletions
|
@ -18,18 +18,20 @@ import GroupStore from './GroupStore';
|
|||
|
||||
class GroupStoreCache {
|
||||
constructor() {
|
||||
this.groupStores = {};
|
||||
this.groupStore = null;
|
||||
}
|
||||
|
||||
getGroupStore(matrixClient, groupId) {
|
||||
if (!this.groupStores[groupId]) {
|
||||
this.groupStores[groupId] = new GroupStore(matrixClient, groupId);
|
||||
if (!this.groupStore || this.groupStore._groupId !== groupId) {
|
||||
// This effectively throws away the reference to any previous GroupStore,
|
||||
// allowing it to be GCd once the components referencing it have stopped
|
||||
// referencing it.
|
||||
this.groupStore = new GroupStore(matrixClient, groupId);
|
||||
}
|
||||
return this.groupStores[groupId];
|
||||
return this.groupStore;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let singletonGroupStoreCache = null;
|
||||
if (!singletonGroupStoreCache) {
|
||||
singletonGroupStoreCache = new GroupStoreCache();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue