Bug 1114957: cleanup LoopRooms event listeners when the conversation window is closed. r=Niko
authorMike de Boer <mdeboer@mozilla.com>
Thu, 08 Jan 2015 18:52:10 +0100
changeset 248547 9097517c27dbbb6fbdf8eaa3a54aaa9a27538378
parent 248546 f8cdb129a54e0345b17428a4c5e71e28d20318fb
child 248548 1b59426310d4e912d714ecf96c608c8b43092fd2
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersNiko
bugs1114957
milestone37.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1114957: cleanup LoopRooms event listeners when the conversation window is closed. r=Niko
browser/components/loop/content/shared/js/activeRoomStore.js
--- a/browser/components/loop/content/shared/js/activeRoomStore.js
+++ b/browser/components/loop/content/shared/js/activeRoomStore.js
@@ -198,28 +198,34 @@ loop.store.ActiveRoomStore = (function()
 
     /**
      * Handles the setupRoomInfo action. Sets up the initial room data and
      * sets the state to `READY`.
      *
      * @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,
         roomState: ROOM_STATES.READY,
         roomToken: actionData.roomToken,
         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);
     },
 
     /**
      * Handles the updateRoomInfo action. Updates the room data.
      *
      * @param {sharedActions.UpdateRoomInfo} actionData
      */
     updateRoomInfo: function(actionData) {
@@ -385,20 +391,26 @@ loop.store.ActiveRoomStore = (function()
     },
 
     /**
      * Handles the window being unloaded. Ensures the room is left.
      */
     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;
     },
 
     /**
      * Handles a room being left.
      */
     leaveRoom: function() {
       this._leaveRoom();
     },