Fix leaking of GroupStore listeners in RoomList

pull/21833/head
Luke Barnard 2017-12-15 14:12:21 +00:00
parent df1134f092
commit 34e455c6fc
2 changed files with 18 additions and 4 deletions

View File

@ -86,6 +86,7 @@ module.exports = React.createClass({
const dmRoomMap = DMRoomMap.shared(); const dmRoomMap = DMRoomMap.shared();
this._groupStores = {}; this._groupStores = {};
this._groupStoreTokens = [];
// A map between tags which are group IDs and the room IDs of rooms that should be kept // A map between tags which are group IDs and the room IDs of rooms that should be kept
// in the room list when filtering by that tag. // in the room list when filtering by that tag.
this._selectedTagsRoomIdsForGroup = { this._selectedTagsRoomIdsForGroup = {
@ -100,10 +101,12 @@ module.exports = React.createClass({
return; return;
} }
this._groupStores[tag] = GroupStoreCache.getGroupStore(tag); this._groupStores[tag] = GroupStoreCache.getGroupStore(tag);
this._groupStores[tag].registerListener(() => { this._groupStoreTokens.push(
// This group's rooms or members may have updated, update rooms for its tag this._groupStores[tag].registerListener(() => {
this.updateSelectedTagsRooms(dmRoomMap, [tag]); // This group's rooms or members may have updated, update rooms for its tag
}); this.updateSelectedTagsRooms(dmRoomMap, [tag]);
}),
);
}); });
// Filters themselves have changed, refresh the selected tags // Filters themselves have changed, refresh the selected tags
this.updateSelectedTagsRooms(dmRoomMap, FilterStore.getSelectedTags()); this.updateSelectedTagsRooms(dmRoomMap, FilterStore.getSelectedTags());
@ -182,6 +185,11 @@ module.exports = React.createClass({
this._filterStoreToken.remove(); this._filterStoreToken.remove();
} }
if (this._groupStoreTokens.length > 0) {
// NB: GroupStore is not a Flux.Store
this._groupStoreTokens.forEach((token) => token.unregister());
}
// cancel any pending calls to the rate_limited_funcs // cancel any pending calls to the rate_limited_funcs
this._delayedRefreshRoomList.cancelPendingCall(); this._delayedRefreshRoomList.cancelPendingCall();
}, },

View File

@ -110,6 +110,12 @@ export default class GroupStore extends EventEmitter {
this._fetchSummary(); this._fetchSummary();
this._fetchRooms(); this._fetchRooms();
this._fetchMembers(); this._fetchMembers();
return {
unregister: () => {
this.unregisterListener(fn);
},
};
} }
unregisterListener(fn) { unregisterListener(fn) {