[polari/wip/fmuellner/misc-cleanups] app: Store pending requests in a Map



commit 4b658b916f2d40f982d6f089e87bc9bc8a0a9678
Author: Florian Müllner <fmuellner gnome org>
Date:   Mon Aug 1 19:47:28 2016 +0200

    app: Store pending requests in a Map
    
    With the availability of the ECMA6 Map class in gjs, it's time to
    phase out the old pattern of using objects as hash tables ...
    
    https://bugzilla.gnome.org/show_bug.cgi?id=769582

 src/application.js |   14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index f8d6ce3..21a3377 100644
--- a/src/application.js
+++ b/src/application.js
@@ -38,7 +38,7 @@ const Application = new Lang.Class({
 
         GLib.set_application_name('Polari');
         this._window = null;
-        this._pendingRequests = {};
+        this._pendingRequests = new Map();
     },
 
     vfunc_startup: function() {
@@ -147,8 +147,8 @@ const Application = new Lang.Class({
             this._window = new MainWindow.MainWindow({ application: this });
             this._window.connect('destroy', Lang.bind(this,
                 function() {
-                    for (let id in this._pendingRequests)
-                        this._pendingRequests[id].cancellable.cancel();
+                    for (let request of this._pendingRequests.values())
+                        request.cancel();
                     this.emit('prepare-shutdown');
             }));
             this._window.show_all();
@@ -384,7 +384,7 @@ const Application = new Lang.Class({
           alternateServers: accountServers.filter(s => s.address != server)
         };
 
-        this._pendingRequests[roomId] = requestData;
+        this._pendingRequests.set(roomId, requestData.cancellable);
 
         this._ensureChannel(requestData);
     },
@@ -472,7 +472,7 @@ const Application = new Lang.Class({
 
         if (requestData.retry > 0)
             this._updateAccountName(account, requestData.originalNick, null);
-        delete this._pendingRequests[requestData.roomId];
+        this._pendingRequests.delete(requestData.roomId);
     },
 
     _onJoinRoom: function(action, parameter) {
@@ -515,8 +515,8 @@ const Application = new Lang.Class({
         let room = this._chatroomManager.getRoomById(roomId);
         if (!room)
             return;
-        if (this._pendingRequests[roomId]) {
-            this._pendingRequests[roomId].cancellable.cancel();
+        if (this._pendingRequests.has(roomId)) {
+            this._pendingRequests.get(roomId).cancel();
         } else if (room.channel) {
             if (!message.length)
                 message = _("Good Bye"); // TODO - our first setting?


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]