[polari/wip/fmuellner/cleanups: 1/4] cleanup: Use Array.includes() to check for element existence



commit 4975209e42989745ba42df450cb9c590f5d029da
Author: Florian Müllner <fmuellner gnome org>
Date:   Sat Nov 4 21:51:30 2017 +0100

    cleanup: Use Array.includes() to check for element existence
    
    This is a relatively recent addition to the standard we can use where we
    don't care about the actual position of an element inside the array.
    (Array.includes() and Array.indexOf() do behave differently in edge cases,
    for example in the handling of NaN, but those don't matter to us)

 src/chatView.js          | 4 ++--
 src/connections.js       | 4 ++--
 src/entryArea.js         | 2 +-
 src/serverRoomManager.js | 2 +-
 src/userList.js          | 2 +-
 5 files changed, 7 insertions(+), 7 deletions(-)
---
diff --git a/src/chatView.js b/src/chatView.js
index b9c5b91..ea89ce8 100644
--- a/src/chatView.js
+++ b/src/chatView.js
@@ -800,7 +800,7 @@ var ChatView = GObject.registerClass({
 
         hoveredButtonTags.forEach(t => { t.hover = true; });
         this._hoveredButtonTags.forEach(t => {
-            t.hover = hoveredButtonTags.indexOf(t) >= 0;
+            t.hover = hoveredButtonTags.includes(t);
         });
 
         let isHovering = hoveredButtonTags.length > 0;
@@ -1371,7 +1371,7 @@ var ChatView = GObject.registerClass({
     }
 
     _createUrlTag(url) {
-        if (url.indexOf(':') == -1)
+        if (!url.includes(':'))
             url = 'http://' + url;
 
         let tag = new ButtonTag();
diff --git a/src/connections.js b/src/connections.js
index 870b57d..1ec28ff 100644
--- a/src/connections.js
+++ b/src/connections.js
@@ -166,7 +166,7 @@ var ConnectionsList = GObject.registerClass({
     _filterRows(row) {
         let matchTerms = this._networksManager.getNetworkMatchTerms(row.id);
         return this._filterTerms.every(term => {
-            return matchTerms.some(s => s.indexOf(term) != -1);
+            return matchTerms.some(s => s.includes(term));
         });
     }
 
@@ -190,7 +190,7 @@ var ConnectionsList = GObject.registerClass({
                 !this._networksManager.getNetworkIsFavorite(network.id))
                 return;
 
-            let sensitive = usedNetworks.indexOf(network.id) < 0;
+            let sensitive = !usedNetworks.includes(network.id);
             this._rows.set(network.id,
                            new ConnectionRow({ id: network.id,
                                                sensitive: sensitive }));
diff --git a/src/entryArea.js b/src/entryArea.js
index ae91250..80b2900 100644
--- a/src/entryArea.js
+++ b/src/entryArea.js
@@ -363,7 +363,7 @@ var EntryArea = GObject.registerClass({
             Gdk.KEY_ISO_Enter,
             Gdk.KEY_space
         ];
-        if (activationKeys.indexOf(keyval) != -1)
+        if (activationKeys.includes(keyval))
             return Gdk.EVENT_PROPAGATE;
 
         this._chatEntry.grab_focus_without_selecting();
diff --git a/src/serverRoomManager.js b/src/serverRoomManager.js
index 08717fd..3bc60a3 100644
--- a/src/serverRoomManager.js
+++ b/src/serverRoomManager.js
@@ -147,7 +147,7 @@ var ServerRoomList = GObject.registerClass({
             if (this._isCustomRoomItem(iter))
                 return true;
 
-            return this._filterTerms.every((term) => name.indexOf(term) != -1);
+            return this._filterTerms.every(term => name.includes(term));
         });
 
         [, this._customRoomItem] = this._store.get_iter_first();
diff --git a/src/userList.js b/src/userList.js
index 82f7449..3dbf207 100644
--- a/src/userList.js
+++ b/src/userList.js
@@ -500,7 +500,7 @@ class UserListRow extends Gtk.ListBoxRow {
     }
 
     shouldShow() {
-        return this._user.alias.toLowerCase().indexOf(this._filter) != -1;
+        return this._user.alias.toLowerCase().includes(this._filter);
     }
 
     setFilter(filter) {


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