[polari] cleanup: Use object destructuring



commit a2a3b7d1295a007dbb6a55d9d5b184f80c8b4066
Author: Florian Müllner <fmuellner gnome org>
Date:   Sun Aug 11 02:18:41 2019 +0200

    cleanup: Use object destructuring
    
    ES6's destructuring is a nice way of assigning a variable in a concise way,
    without duplicating the name of the object property. Use it consistently
    where possible.
    
    https://gitlab.gnome.org/GNOME/polari/merge_requests/133

 src/application.js       |  4 +---
 src/chatView.js          | 13 ++++++-------
 src/connections.js       |  4 ++--
 src/ircParser.js         |  8 ++++----
 src/main.js              |  2 +-
 src/mainWindow.js        |  2 +-
 src/roomList.js          |  6 ++----
 src/serverRoomManager.js |  2 +-
 src/userList.js          |  2 +-
 9 files changed, 19 insertions(+), 24 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index b1fcc9a..f54e03a 100644
--- a/src/application.js
+++ b/src/application.js
@@ -633,9 +633,7 @@ var Application = GObject.registerClass({
             return data;
 
         let params = account.getConnectionParams();
-        let server = params['server'];
-        let accountName = params['account'];
-        let port = params['port'];
+        let { server, account: accountName, port } = params;
         debug(`Failed to connect to ${server} with username ${accountName}`);
 
         let accountServers = [];
diff --git a/src/chatView.js b/src/chatView.js
index 1b1f7ec..711dae7 100644
--- a/src/chatView.js
+++ b/src/chatView.js
@@ -587,8 +587,7 @@ var ChatView = GObject.registerClass({
         if (this._logWalker.is_end())
             return this._pendingLogs.splice(0);
 
-        let nick = this._pendingLogs[0].nick;
-        let type = this._pendingLogs[0].messageType;
+        let { nick, messageType: type } = this._pendingLogs[0];
         let maxNum = this._pendingLogs.length - this._initialPending.length;
         for (let i = 0; i < maxNum; i++) {
             if (this._pendingLogs[i].nick != nick ||
@@ -837,7 +836,7 @@ var ChatView = GObject.registerClass({
         });
         indicator.get_style_context().add_class('dim-label');
 
-        let buffer = this._view.buffer;
+        let { buffer } = this._view;
         let iter = buffer.get_start_iter();
         let anchor = buffer.create_child_anchor(iter);
         this._view.add_child_at_anchor(indicator, anchor);
@@ -849,7 +848,7 @@ var ChatView = GObject.registerClass({
     }
 
     _hideLoadingIndicator() {
-        let buffer = this._view.buffer;
+        let { buffer } = this._view;
         let iter = buffer.get_start_iter();
 
         if (!iter.get_child_anchor())
@@ -863,7 +862,7 @@ var ChatView = GObject.registerClass({
         let lineStart = iter.copy();
         lineStart.set_line_offset(0);
 
-        let buffer = this._view.buffer;
+        let { buffer } = this._view;
         let mark = buffer.get_mark('indicator-line');
         if (mark) {
             let [start, end] = this._getLineIters(buffer.get_iter_at_mark(mark));
@@ -1038,7 +1037,7 @@ var ChatView = GObject.registerClass({
     }
 
     _updateStatusHeader() {
-        let buffer = this._view.buffer;
+        let { buffer } = this._view;
         let headerMark = buffer.get_mark('idle-status-start');
 
         let headerTagName = `status-compressed${this._state.lastStatusGroup}`;
@@ -1308,7 +1307,7 @@ var ChatView = GObject.registerClass({
         let params = this._room.account.dup_parameters_vardict().deep_unpack();
         let server = params.server.deep_unpack();
 
-        let text = message.text;
+        let { text } = message;
 
         // mask identify passwords in private chats
         if (this._room.type == Tp.HandleType.CONTACT) {
diff --git a/src/connections.js b/src/connections.js
index cdcb81d..4da8ac6 100644
--- a/src/connections.js
+++ b/src/connections.js
@@ -179,7 +179,7 @@ var ConnectionsList = GObject.registerClass({
     _networksChanged() {
         this._list.foreach(w => w.destroy());
 
-        let accounts = this._accountsMonitor.accounts;
+        let { accounts } = this._accountsMonitor;
         let usedNetworks = accounts.filter(a => a.predefined).map(a => a.service);
 
         this._networksManager.networks.forEach(network => {
@@ -370,10 +370,10 @@ var ConnectionDetails = GObject.registerClass({
     _populateFromAccount(account) {
         let params = account.getConnectionParams();
 
+        let { port } = params;
         this._savedSSL = params['use-ssl'];
         let defaultPort = this._savedSSL ? DEFAULT_SSL_PORT : DEFAULT_PORT;
         this._savedServer = params.server || '';
-        let port = params.port;
         this._savedNick = params.account || '';
         this._savedRealname = params.fullname || '';
 
diff --git a/src/ircParser.js b/src/ircParser.js
index 7887390..a1b6224 100644
--- a/src/ircParser.js
+++ b/src/ircParser.js
@@ -120,7 +120,7 @@ var IrcParser = class {
             if (argv.length)
                 log(`Excess arguments to JOIN command: ${argv}`);
 
-            let account = this._room.account;
+            let { account } = this._room;
             let app = Gio.Application.get_default();
             let action = app.lookup_action('join-room');
             action.activate(GLib.Variant.new('(ssu)', [
@@ -171,7 +171,7 @@ var IrcParser = class {
                 break;
             }
 
-            let account = this._room.account;
+            let { account } = this._room;
 
             let app = Gio.Application.get_default();
             let action = app.lookup_action('message-user');
@@ -184,7 +184,7 @@ var IrcParser = class {
             break;
         }
         case 'NAMES': {
-            let channel = this._room.channel;
+            let { channel } = this._room;
             let members = channel.group_dup_members_contacts().map(m => m.alias);
             output = this._createFeedbackGrid(
                 _('Users on %s:').format(channel.identifier), members);
@@ -228,7 +228,7 @@ var IrcParser = class {
                 break;
             }
 
-            let account = this._room.account;
+            let { account } = this._room;
 
             let app = Gio.Application.get_default();
             let action = app.lookup_action('message-user');
diff --git a/src/main.js b/src/main.js
index 8f0e032..7f53072 100755
--- a/src/main.js
+++ b/src/main.js
@@ -27,7 +27,7 @@ var LOG_DOMAIN = 'Polari';
 
 function _makeLogFunction(level) {
     return message => {
-        let stack = (new Error()).stack;
+        let { stack } = new Error();
         let [, caller] = stack.split('\n');
 
         // Map from resource- to source location
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 4e1708d..4be6532 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -153,7 +153,7 @@ var MainWindow = GObject.registerClass({
 
         // Make sure user-list button is at least as wide as icon buttons
         this._joinButton.connect('size-allocate', (w, rect) => {
-            let width = rect.width;
+            let { width } = rect;
             GLib.idle_add(GLib.PRIORITY_DEFAULT_IDLE, () => {
                 this._showUserListButton.width_request = width;
                 return GLib.SOURCE_REMOVE;
diff --git a/src/roomList.js b/src/roomList.js
index 999bced..9f53e77 100644
--- a/src/roomList.js
+++ b/src/roomList.js
@@ -675,10 +675,8 @@ class RoomList extends Gtk.ListBox {
     }
 
     _updateHeader(row, before) {
-        let getAccount = row => row ? row.account : null;
-
-        let beforeAccount = getAccount(before);
-        let account = getAccount(row);
+        let { account: beforeAccount } = before || {};
+        let { account } = row;
 
         let oldHeader = row.get_header();
 
diff --git a/src/serverRoomManager.js b/src/serverRoomManager.js
index 99f6d5d..18c5970 100644
--- a/src/serverRoomManager.js
+++ b/src/serverRoomManager.js
@@ -261,7 +261,7 @@ var ServerRoomList = GObject.registerClass({
         if (this._filterEntry.text.trim().length == 0)
             return;
 
-        let model = this._list.model;
+        let { model } = this._list;
         let [valid, iter] = model.get_iter_first();
         if (!valid)
             return;
diff --git a/src/userList.js b/src/userList.js
index 07f1846..9a53aaa 100644
--- a/src/userList.js
+++ b/src/userList.js
@@ -136,7 +136,7 @@ var UserDetails = GObject.registerClass({
     }
 }, class UserDetails extends Gtk.Frame {
     _init(params = {}) {
-        let user = params.user;
+        let { user } = params;
         delete params.user;
 
         this._expanded = false;


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