[gnome-shell-extensions] apps-menu: Use Map to keep track of app items



commit 021037bfcddc6f6e077756d28a6a23177ff0b591
Author: Florian Müllner <fmuellner gnome org>
Date:   Wed Mar 15 05:16:49 2017 +0100

    apps-menu: Use Map to keep track of app items
    
    The use of Array to keep track of inserted items is extremely
    confusing, as no elements are ever added to the array. What
    the code actually does is monkey-patching properties into an
    empty object (that happens to be of type "Array"). While the
    direct idiomatic replacement would be {}, update the code to
    use a proper map instead.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=780371

 extensions/apps-menu/extension.js |   14 ++++++++------
 1 files changed, 8 insertions(+), 6 deletions(-)
---
diff --git a/extensions/apps-menu/extension.js b/extensions/apps-menu/extension.js
index 4792854..ced236c 100644
--- a/extensions/apps-menu/extension.js
+++ b/extensions/apps-menu/extension.js
@@ -286,6 +286,7 @@ const ApplicationsButton = new Lang.Class({
                                    Lang.bind(this, this._setKeybinding));
         this._setKeybinding();
 
+        this._applicationsButtons = new Map();
         this.reloadFlag = false;
         this._createLayout();
         this._display();
@@ -494,7 +495,7 @@ const ApplicationsButton = new Lang.Class({
     },
 
     _display: function() {
-        this._applicationsButtons = new Array();
+        this._applicationsButtons.clear();
         this.mainBox.style=('width: 35em;');
         this.mainBox.hide();
 
@@ -553,12 +554,13 @@ const ApplicationsButton = new Lang.Class({
          if (apps) {
             for (let i = 0; i < apps.length; i++) {
                let app = apps[i];
-               if (!this._applicationsButtons[app]) {
-                  let applicationMenuItem = new ApplicationMenuItem(this, app);
-                  this._applicationsButtons[app] = applicationMenuItem;
+               let item = this._applicationsButtons.get(app);
+               if (!item) {
+                  item = new ApplicationMenuItem(this, app);
+                  this._applicationsButtons.set(app, item);
                }
-               if (!this._applicationsButtons[app].actor.get_parent())
-                  this.applicationsBox.add_actor(this._applicationsButtons[app].actor);
+               if (!item.actor.get_parent())
+                  this.applicationsBox.add_actor(item.actor);
             }
          }
     },


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