Bug 1114957: cleanup LoopRooms event listeners when the conversation window is closed. r=Niko

This commit is contained in:
Mike de Boer 2015-01-08 18:52:10 +01:00
Родитель e9f2d67e3c
Коммит 1cafd19d79
1 изменённых файлов: 18 добавлений и 6 удалений

Просмотреть файл

@ -203,6 +203,11 @@ loop.store.ActiveRoomStore = (function() {
* @param {sharedActions.SetupRoomInfo} actionData
*/
setupRoomInfo: function(actionData) {
if (this._onUpdateListener) {
console.error("Room info already set up!");
return;
}
this.setStoreState({
roomName: actionData.roomName,
roomOwner: actionData.roomOwner,
@ -211,10 +216,11 @@ loop.store.ActiveRoomStore = (function() {
roomUrl: actionData.roomUrl
});
this._mozLoop.rooms.on("update:" + actionData.roomToken,
this._handleRoomUpdate.bind(this));
this._mozLoop.rooms.on("delete:" + actionData.roomToken,
this._handleRoomDelete.bind(this));
this._onUpdateListener = this._handleRoomUpdate.bind(this);
this._onDeleteListener = this._handleRoomDelete.bind(this);
this._mozLoop.rooms.on("update:" + actionData.roomToken, this._onUpdateListener);
this._mozLoop.rooms.on("delete:" + actionData.roomToken, this._onDeleteListener);
},
/**
@ -390,10 +396,16 @@ loop.store.ActiveRoomStore = (function() {
windowUnload: function() {
this._leaveRoom(ROOM_STATES.CLOSING);
if (!this._onUpdateListener) {
return;
}
// If we're closing the window, we can stop listening to updates.
var roomToken = this.getStoreState().roomToken;
this._mozLoop.rooms.off("update:" + roomToken);
this._mozLoop.rooms.off("delete:" + roomToken);
this._mozLoop.rooms.off("update:" + roomToken, this._onUpdateListener);
this._mozLoop.rooms.off("delete:" + roomToken, this._onDeleteListener);
delete this._onUpdateListener;
delete this._onDeleteListener;
},
/**