[gnome-maps/wip/mlundblad/es6: 4/4] WIP: Use ES6 arrow notation



commit f9c3994aff976856ad5d520c63b70302fecf9fd0
Author: Marcus Lundblad <ml update uu se>
Date:   Fri Nov 10 23:45:20 2017 +0100

    WIP: Use ES6 arrow notation

 src/accountListBox.js   |   11 ++++-------
 src/application.js      |   34 ++++++++++++++++------------------
 src/checkIn.js          |    4 ++--
 src/checkInDialog.js    |   24 +++++++++++-------------
 src/contextMenu.js      |   26 +++++++++++---------------
 src/exportViewDialog.js |   23 ++++++++---------------
 src/favoritesPopover.js |   18 ++++++++----------
 src/geoclue.js          |   10 +++++-----
 8 files changed, 65 insertions(+), 85 deletions(-)
---
diff --git a/src/accountListBox.js b/src/accountListBox.js
index df5eb4c..e45a21e 100644
--- a/src/accountListBox.js
+++ b/src/accountListBox.js
@@ -61,11 +61,10 @@ var AccountListBox = new Lang.Class({
         params.activate_on_single_click = true;
         this.parent(params);
 
-        Application.checkInManager.connect('accounts-refreshed', this.refresh.bind(this));
+        Application.checkInManager.connect('accounts-refreshed', () => { this.refresh(); });
 
-        this.connect('row-activated', (function(list, row) {
-            this.emit('account-selected', row.account);
-        }).bind(this));
+        this.connect('row-activated',
+                     (list, row) => { this.emit('account-selected', row.account); });
 
         this.refresh();
     },
@@ -77,8 +76,6 @@ var AccountListBox = new Lang.Class({
             row.destroy();
         });
 
-        accounts.forEach((function(account) {
-            this.add(new AccountRow({ account: account }));
-        }).bind(this));
+        accounts.forEach((account) => { this.add(new AccountRow({ account: account })); });
     }
 });
diff --git a/src/application.js b/src/application.js
index 9cc5888..c155ba3 100644
--- a/src/application.js
+++ b/src/application.js
@@ -87,9 +87,7 @@ var Application = new Lang.Class({
         GLib.set_application_name(_("Maps"));
 
         /* Needed to be able to use in UI files */
-        _ensuredTypes.forEach(function(type) {
-            GObject.type_ensure(type);
-        });
+        _ensuredTypes.forEach((type) => { GObject.type_ensure(type); });
 
         this.parent({ application_id: 'org.gnome.Maps',
                       flags: Gio.ApplicationFlags.HANDLES_OPEN });
@@ -105,7 +103,7 @@ var Application = new Lang.Class({
         this.add_main_option('version', 'v'.charCodeAt(0), GLib.OptionFlags.NONE, GLib.OptionArg.NONE,
                              _("Show the version of the program"), null);
 
-        this.connect('handle-local-options', (function(app, options) {
+        this.connect('handle-local-options', (app, options) => {
             if (options.contains('local')) {
                 let variant = options.lookup_value('local', null);
                 this.local_tile_path = variant.deep_unpack();
@@ -119,7 +117,7 @@ var Application = new Lang.Class({
             }
 
             return -1;
-        }).bind(this));
+        });
     },
 
     _checkNetwork: function() {
@@ -127,17 +125,17 @@ var Application = new Lang.Class({
     },
 
     _showContact: function(id) {
-        contactStore.lookup(id, (function(contact) {
+        contactStore.lookup(id, (contact) => {
             this._mainWindow.markBusy();
             if (!contact) {
                 this._mainWindow.unmarkBusy();
                 return;
             }
-            contact.geocode((function() {
+            contact.geocode(() => {
                 this._mainWindow.unmarkBusy();
                 this._mainWindow.mapView.showContact(contact);
-            }).bind(this));
-        }).bind(this));
+            });
+        });
     },
 
     _onShowContactActivate: function(action, parameter) {
@@ -150,10 +148,10 @@ var Application = new Lang.Class({
         if (contactStore.state === Maps.ContactStoreState.LOADED) {
             this. _showContact(id);
         } else {
-            Utils.once(contactStore, 'notify::state', (function() {
+            Utils.once(contactStore, 'notify::state', () => {
                 if (contactStore.state === Maps.ContactStoreState.LOADED)
                     this._showContact(id);
-            }).bind(this));
+            });
         }
     },
 
@@ -165,13 +163,13 @@ var Application = new Lang.Class({
         let dialog = osmEdit.createAccountDialog(this._mainWindow, false);
 
         dialog.show();
-        dialog.connect('response', dialog.destroy.bind(dialog));
+        dialog.connect('response', () => { dialog.destroy(); });
     },
 
     _addContacts: function() {
-        contactStore.get_contacts().forEach(function(contact) {
+        contactStore.get_contacts().forEach((contact) => {
             contact.geocode(function() {
-                contact.get_places().forEach(function(p) {
+                contact.get_places().forEach((p) => {
                     if (!p.location)
                         return;
 
@@ -199,10 +197,10 @@ var Application = new Lang.Class({
         if (contactStore.state === Maps.ContactStoreState.LOADED) {
             this._addContacts();
         } else {
-            Utils.once(contactStore, 'notify::state', (function() {
+            Utils.once(contactStore, 'notify::state', () => {
                 if (contactStore.state === Maps.ContactStoreState.LOADED)
                     this._addContacts();
-            }).bind(this));
+            });
         }
     },
 
@@ -264,9 +262,9 @@ var Application = new Lang.Class({
         notificationManager = new NotificationManager.NotificationManager(overlay);
         this._mainWindow = new MainWindow.MainWindow({ application: this,
                                                        overlay: overlay });
-        this._mainWindow.connect('destroy', this._onWindowDestroy.bind(this));
+        this._mainWindow.connect('destroy', () => { this._onWindowDestroy(); });
         if (GLib.getenv('MAPS_DEBUG') === 'focus') {
-            this._mainWindow.connect('set-focus', function(window, widget) {
+            this._mainWindow.connect('set-focus', (window, widget) => {
                 log('* focus widget: %s'.format(widget));
             });
         }
diff --git a/src/checkIn.js b/src/checkIn.js
index d6849c5..d75d492 100644
--- a/src/checkIn.js
+++ b/src/checkIn.js
@@ -84,7 +84,7 @@ var CheckInManager = new Lang.Class({
         this._accountsCount = 0;
         this._authorizers = {};
 
-        accounts.forEach((function(object) {
+        accounts.forEach((object) => {
             if (!object.get_account())
                 return;
 
@@ -95,7 +95,7 @@ var CheckInManager = new Lang.Class({
             this._accounts.push(object);
 
             this._authorizers[accountId] = this._getBackend(object).createAuthorizer(object);
-        }).bind(this));
+        });
 
         this.emit('accounts-refreshed');
         this.notify('hasCheckIn');
diff --git a/src/checkInDialog.js b/src/checkInDialog.js
index 9b0b700..4761b61 100644
--- a/src/checkInDialog.js
+++ b/src/checkInDialog.js
@@ -85,20 +85,18 @@ var CheckInDialog = new Lang.Class({
             this._cancellable.cancel();
         }).bind(this));
 
-        Application.checkInManager.connect('accounts-refreshed', this._onAccountRefreshed.bind(this));
+        Application.checkInManager.connect('accounts-refreshed',
+                                           () => { this._onAccountRefreshed() });
 
         this._initHeaderBar();
         this._initWidgets();
     },
 
     _initHeaderBar: function() {
-        this._cancelButton.connect('clicked', (function() {
-            this._cancellable.cancel();
-        }).bind(this));
+        this._cancelButton.connect('clicked',
+                                   () => { this._cancellable.cancel(); });
 
-        this._okButton.connect('clicked', (function() {
-            this._startCheckInStep();
-        }).bind(this));
+        this._okButton.connect('clicked', () => { this._startCheckInStep(); });
     },
 
     _initWidgets: function() {
@@ -125,15 +123,15 @@ var CheckInDialog = new Lang.Class({
                                   this._foursquareOptionsBroadcastTwitterCheckButton,
                                   'active', Gio.SettingsBindFlags.DEFAULT);
 
-        this._accountListBox.connect('account-selected', (function(list, account) {
+        this._accountListBox.connect('account-selected', (list, account) => {
             this._account = account;
             this._startPlaceStep();
-        }).bind(this));
+        });
 
-        this._placeListBox.connect('place-selected', (function(list, place) {
+        this._placeListBox.connect('place-selected', (list, place) => {
             this._checkIn.place = place;
             this._startMessageStep();
-        }).bind(this));
+        });
     },
 
     vfunc_show: function() {
@@ -150,9 +148,9 @@ var CheckInDialog = new Lang.Class({
             this._account = Application.checkInManager.accounts[0];
             this._startPlaceStep();
         } else {
-            Mainloop.idle_add((function() {
+            Mainloop.idle_add(() => {
                 this.response(Response.FAILURE_CHECKIN_DISABLED);
-            }).bind(this));
+            });
         }
     },
 
diff --git a/src/contextMenu.js b/src/contextMenu.js
index 5306093..c80b42b 100644
--- a/src/contextMenu.js
+++ b/src/contextMenu.js
@@ -81,10 +81,8 @@ var ContextMenu = new Lang.Class({
         this._latitude = this._mapView.view.y_to_latitude(y);
 
         if (button === Gdk.BUTTON_SECONDARY) {
-            Mainloop.idle_add((function() {
-                // Need idle to avoid Clutter dead-lock on re-entrance
-                this.popup_at_pointer(event);
-            }).bind(this));
+            // Need idle to avoid Clutter dead-lock on re-entrance
+            Mainloop.idle_add(() => { this.popup_at_pointer(event); });
         }
     },
 
@@ -125,14 +123,14 @@ var ContextMenu = new Lang.Class({
                                                longitude: this._longitude,
                                                accuracy: 0 });
 
-        Application.geocodeService.reverse(location, null, (function(place) {
+        Application.geocodeService.reverse(location, null, (place) => {
             if (place) {
                 this._mapView.showPlace(place, false);
             } else {
                 let msg = _("Nothing found here!");
                 Application.notificationManager.showMessage(msg);
             }
-        }).bind(this));
+        });
     },
 
     _onGeoURIActivated: function() {
@@ -153,11 +151,11 @@ var ContextMenu = new Lang.Class({
             let dialog = osmEdit.createAccountDialog(this._mainWindow, true);
 
             dialog.show();
-            dialog.connect('response', (function(dialog, response) {
+            dialog.connect('response', (dialog, response) => {
                 dialog.destroy();
                 if (response === OSMAccountDialog.Response.SIGNED_IN)
                     this._addOSMLocation();
-            }).bind(this));
+            });
 
             return;
         }
@@ -182,13 +180,13 @@ var ContextMenu = new Lang.Class({
                                       this._latitude, this._longitude);
 
         dialog.show();
-        dialog.connect('response', (function(dialog, response) {
+        dialog.connect('response', (dialog, response) => {
             dialog.destroy();
             if (response === OSMEditDialog.Response.UPLOADED) {
                 Application.notificationManager.showMessage(
                     _("Location was added to the map, note that it may take a while before it shows on the 
map and in search results."));
             }
-        }).bind(this));
+        });
     },
 
     _activateExport: function() {
@@ -206,9 +204,7 @@ var ContextMenu = new Lang.Class({
             mapView: this._mapView
         });
 
-        dialog.connect('response', function() {
-            dialog.destroy();
-        });
+        dialog.connect('response', () => { dialog.destroy(); });
         dialog.show_all();
     },
 
@@ -216,12 +212,12 @@ var ContextMenu = new Lang.Class({
         if (this._mapView.view.state === Champlain.State.DONE) {
             this._activateExport();
         } else {
-            let notifyId = this._mapView.view.connect('notify::state', (function() {
+            let notifyId = this._mapView.view.connect('notify::state', () => {
                 if (this._mapView.view.state === Champlain.State.DONE) {
                     this._mapView.view.disconnect(notifyId);
                     this._activateExport();
                 }
-            }).bind(this));
+            });
         }
     }
 });
diff --git a/src/exportViewDialog.js b/src/exportViewDialog.js
index 243e48b..c946563 100644
--- a/src/exportViewDialog.js
+++ b/src/exportViewDialog.js
@@ -60,17 +60,11 @@ var ExportViewDialog = new Lang.Class({
         params.use_header_bar = true;
         this.parent(params);
 
-        this._cancelButton.connect('clicked', (function() {
-            this.response(Response.CANCEL);
-        }).bind(this));
-        this._exportButton.connect('clicked', this._exportView.bind(this));
-        this._filenameEntry.connect('changed',
-                                    this._onFileNameChanged.bind(this));
-        this._fileChooserButton.connect('file-set',
-                                        this._onFolderChanged.bind(this));
-
-        this._layersCheckButton.connect('toggled',
-                                        this._includeLayersChanged.bind(this));
+        this._cancelButton.connect('clicked', () => { this.response(Response.CANCEL); });
+        this._exportButton.connect('clicked', () => { this._exportView(); });
+        this._filenameEntry.connect('changed', () => { this._onFileNameChanged(); });
+        this._fileChooserButton.connect('file-set', () => { this._onFolderChanged(); });
+        this._layersCheckButton.connect('toggled', () => { this._includeLayersChanged() });
 
 
         this._folder = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_PICTURES);
@@ -99,7 +93,8 @@ var ExportViewDialog = new Lang.Class({
         let height = surfaceHeight * this._scaleFactor;
 
         this._previewArea.set_size_request(width, height);
-        this._previewArea.connect('draw', this._drawPreview.bind(this));
+        this._previewArea.connect('draw',
+                                  (w, cr) => { this._drawPreview(w, cr); });
     },
 
     _drawPreview: function(widget, cr) {
@@ -176,9 +171,7 @@ var ExportViewDialog = new Lang.Class({
                 secondary_text: details
             });
 
-            dialog.connect('response', function() {
-                dialog.destroy();
-            });
+            dialog.connect('response', () => { dialog.destroy(); });
             dialog.show_all();
         }
     },
diff --git a/src/favoritesPopover.js b/src/favoritesPopover.js
index b6df29a..cd1a328 100644
--- a/src/favoritesPopover.js
+++ b/src/favoritesPopover.js
@@ -80,16 +80,16 @@ var FavoritesPopover = new Lang.Class({
         }).bind(this));
 
         this._entry.connect('changed',
-                            this._list.invalidate_filter.bind(this._list));
+                            () => { this._list.invalidate_filter(this._list); });
 
-        this._list.connect('row-activated', (function(list, row) {
+        this._list.connect('row-activated', (list, row) => {
             this.hide();
             this._mapView.showPlace(row.place, true);
-        }).bind(this));
+        });
 
-        this._list.set_filter_func((function(row) {
+        this._list.set_filter_func((row) => {
             return row.place.match(this._entry.text);
-        }).bind(this));
+        });
 
         this._updateList();
     },
@@ -106,12 +106,10 @@ var FavoritesPopover = new Lang.Class({
     },
 
     _updateList: function() {
-        this._list.forall(function(row) {
-            row.destroy();
-        });
+        this._list.forall((row) => { row.destroy(); });
 
         let rows = 0;
-        this._model.foreach((function(model, path, iter) {
+        this._model.foreach((model, path, iter) => {
             let place = model.get_value(iter, PlaceStore.Columns.PLACE);
 
             let row = new PlaceListRow.PlaceListRow({ place: place,
@@ -119,7 +117,7 @@ var FavoritesPopover = new Lang.Class({
                                                       can_focus: true });
             this._list.add(row);
             rows++;
-        }).bind(this));
+        });
 
         this.rows = rows;
     }
diff --git a/src/geoclue.js b/src/geoclue.js
index 74e962b..f2f5949 100644
--- a/src/geoclue.js
+++ b/src/geoclue.js
@@ -75,7 +75,7 @@ var Geoclue = new Lang.Class({
         let id = 'org.gnome.Maps';
         let level = GClue.AccuracyLevel.EXACT;
 
-        GClue.Simple.new(id, level, null, (function(object, result) {
+        GClue.Simple.new(id, level, null, (object, result) => {
             try {
                 this._simple = GClue.Simple.new_finish(result);
             }
@@ -91,16 +91,16 @@ var Geoclue = new Lang.Class({
             }
 
             this._simple.connect('notify::location',
-                           this._onLocationNotify.bind(this));
-            this._simple.client.connect('notify::active', (function() {
+                                 () => { this._onLocationNotify() });
+            this._simple.client.connect('notify::active', () => {
                 this.state = this._simple.client.active ? State.ON : State.DENIED;
-            }).bind(this));
+            });
 
             this.state = State.ON;
             this._onLocationNotify(this._simple);
             if (callback)
                 callback(true);
-        }).bind(this));
+        });
     },
 
     _onLocationNotify: function(simple) {


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