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
|
@ -23,14 +23,14 @@ import EventEmitter from 'events';
|
||||||
export default class GroupStore extends EventEmitter {
|
export default class GroupStore extends EventEmitter {
|
||||||
constructor(matrixClient, groupId) {
|
constructor(matrixClient, groupId) {
|
||||||
super();
|
super();
|
||||||
this._groupId = groupId;
|
this.groupId = groupId;
|
||||||
this._matrixClient = matrixClient;
|
this._matrixClient = matrixClient;
|
||||||
this._summary = {};
|
this._summary = {};
|
||||||
this._fetchSummary();
|
this._fetchSummary();
|
||||||
}
|
}
|
||||||
|
|
||||||
_fetchSummary() {
|
_fetchSummary() {
|
||||||
this._matrixClient.getGroupSummary(this._groupId).then((resp) => {
|
this._matrixClient.getGroupSummary(this.groupId).then((resp) => {
|
||||||
this._summary = resp;
|
this._summary = resp;
|
||||||
this._notifyListeners();
|
this._notifyListeners();
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
|
@ -48,36 +48,36 @@ export default class GroupStore extends EventEmitter {
|
||||||
|
|
||||||
addRoomToGroup(roomId) {
|
addRoomToGroup(roomId) {
|
||||||
return this._matrixClient
|
return this._matrixClient
|
||||||
.addRoomToGroup(this._groupId, roomId);
|
.addRoomToGroup(this.groupId, roomId);
|
||||||
}
|
}
|
||||||
|
|
||||||
addRoomToGroupSummary(roomId, categoryId) {
|
addRoomToGroupSummary(roomId, categoryId) {
|
||||||
return this._matrixClient
|
return this._matrixClient
|
||||||
.addRoomToGroupSummary(this._groupId, roomId, categoryId)
|
.addRoomToGroupSummary(this.groupId, roomId, categoryId)
|
||||||
.then(this._fetchSummary.bind(this));
|
.then(this._fetchSummary.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
addUserToGroupSummary(userId, roleId) {
|
addUserToGroupSummary(userId, roleId) {
|
||||||
return this._matrixClient
|
return this._matrixClient
|
||||||
.addUserToGroupSummary(this._groupId, userId, roleId)
|
.addUserToGroupSummary(this.groupId, userId, roleId)
|
||||||
.then(this._fetchSummary.bind(this));
|
.then(this._fetchSummary.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
removeRoomFromGroupSummary(roomId) {
|
removeRoomFromGroupSummary(roomId) {
|
||||||
return this._matrixClient
|
return this._matrixClient
|
||||||
.removeRoomFromGroupSummary(this._groupId, roomId)
|
.removeRoomFromGroupSummary(this.groupId, roomId)
|
||||||
.then(this._fetchSummary.bind(this));
|
.then(this._fetchSummary.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
removeUserFromGroupSummary(userId) {
|
removeUserFromGroupSummary(userId) {
|
||||||
return this._matrixClient
|
return this._matrixClient
|
||||||
.removeUserFromGroupSummary(this._groupId, userId)
|
.removeUserFromGroupSummary(this.groupId, userId)
|
||||||
.then(this._fetchSummary.bind(this));
|
.then(this._fetchSummary.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
setGroupPublicity(isPublished) {
|
setGroupPublicity(isPublished) {
|
||||||
return this._matrixClient
|
return this._matrixClient
|
||||||
.setGroupPublicity(this._groupId, isPublished)
|
.setGroupPublicity(this.groupId, isPublished)
|
||||||
.then(this._fetchSummary.bind(this));
|
.then(this._fetchSummary.bind(this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,18 +18,20 @@ import GroupStore from './GroupStore';
|
||||||
|
|
||||||
class GroupStoreCache {
|
class GroupStoreCache {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.groupStores = {};
|
this.groupStore = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
getGroupStore(matrixClient, groupId) {
|
getGroupStore(matrixClient, groupId) {
|
||||||
if (!this.groupStores[groupId]) {
|
if (!this.groupStore || this.groupStore._groupId !== groupId) {
|
||||||
this.groupStores[groupId] = new GroupStore(matrixClient, 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;
|
let singletonGroupStoreCache = null;
|
||||||
if (!singletonGroupStoreCache) {
|
if (!singletonGroupStoreCache) {
|
||||||
singletonGroupStoreCache = new GroupStoreCache();
|
singletonGroupStoreCache = new GroupStoreCache();
|
||||||
|
|
Loading…
Reference in a new issue