From 021037bfcddc6f6e077756d28a6a23177ff0b591 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Wed, 15 Mar 2017 05:16:49 +0100 Subject: [PATCH] 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 file changed, 8 insertions(+), 6 deletions(-) diff --git a/extensions/apps-menu/extension.js b/extensions/apps-menu/extension.js index 4792854e..ced236c3 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); } } },