Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit c1318e9

Browse files
author
Luke Barnard
committed
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
1 parent b16eb17 commit c1318e9

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

src/stores/GroupStore.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ import EventEmitter from 'events';
2323
export default class GroupStore extends EventEmitter {
2424
constructor(matrixClient, groupId) {
2525
super();
26-
this._groupId = groupId;
26+
this.groupId = groupId;
2727
this._matrixClient = matrixClient;
2828
this._summary = {};
2929
this._fetchSummary();
3030
}
3131

3232
_fetchSummary() {
33-
this._matrixClient.getGroupSummary(this._groupId).then((resp) => {
33+
this._matrixClient.getGroupSummary(this.groupId).then((resp) => {
3434
this._summary = resp;
3535
this._notifyListeners();
3636
}).catch((err) => {
@@ -48,36 +48,36 @@ export default class GroupStore extends EventEmitter {
4848

4949
addRoomToGroup(roomId) {
5050
return this._matrixClient
51-
.addRoomToGroup(this._groupId, roomId);
51+
.addRoomToGroup(this.groupId, roomId);
5252
}
5353

5454
addRoomToGroupSummary(roomId, categoryId) {
5555
return this._matrixClient
56-
.addRoomToGroupSummary(this._groupId, roomId, categoryId)
56+
.addRoomToGroupSummary(this.groupId, roomId, categoryId)
5757
.then(this._fetchSummary.bind(this));
5858
}
5959

6060
addUserToGroupSummary(userId, roleId) {
6161
return this._matrixClient
62-
.addUserToGroupSummary(this._groupId, userId, roleId)
62+
.addUserToGroupSummary(this.groupId, userId, roleId)
6363
.then(this._fetchSummary.bind(this));
6464
}
6565

6666
removeRoomFromGroupSummary(roomId) {
6767
return this._matrixClient
68-
.removeRoomFromGroupSummary(this._groupId, roomId)
68+
.removeRoomFromGroupSummary(this.groupId, roomId)
6969
.then(this._fetchSummary.bind(this));
7070
}
7171

7272
removeUserFromGroupSummary(userId) {
7373
return this._matrixClient
74-
.removeUserFromGroupSummary(this._groupId, userId)
74+
.removeUserFromGroupSummary(this.groupId, userId)
7575
.then(this._fetchSummary.bind(this));
7676
}
7777

7878
setGroupPublicity(isPublished) {
7979
return this._matrixClient
80-
.setGroupPublicity(this._groupId, isPublished)
80+
.setGroupPublicity(this.groupId, isPublished)
8181
.then(this._fetchSummary.bind(this));
8282
}
8383
}

src/stores/GroupStoreCache.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,20 @@ import GroupStore from './GroupStore';
1818

1919
class GroupStoreCache {
2020
constructor() {
21-
this.groupStores = {};
21+
this.groupStore = null;
2222
}
2323

2424
getGroupStore(matrixClient, groupId) {
25-
if (!this.groupStores[groupId]) {
26-
this.groupStores[groupId] = new GroupStore(matrixClient, groupId);
25+
if (!this.groupStore || this.groupStore._groupId !== groupId) {
26+
// This effectively throws away the reference to any previous GroupStore,
27+
// allowing it to be GCd once the components referencing it have stopped
28+
// referencing it.
29+
this.groupStore = new GroupStore(matrixClient, groupId);
2730
}
28-
return this.groupStores[groupId];
31+
return this.groupStore;
2932
}
3033
}
3134

32-
3335
let singletonGroupStoreCache = null;
3436
if (!singletonGroupStoreCache) {
3537
singletonGroupStoreCache = new GroupStoreCache();

0 commit comments

Comments
 (0)