[gnome-weather/wip/christopherdavis/es6: 2/4] Use arrow functions instead of `.bind(this)`



commit 0d5c4ce343b1b5ac86d3057a4c498c61fed35e17
Author: Christopher Davis <brainblasted disroot org>
Date:   Fri Feb 22 04:19:07 2019 -0500

    Use arrow functions instead of `.bind(this)`
    
    Arrow functions are more explicit, showing what you want to
    pass through what callback.

 src/app/city.js                      | 14 +++++++++-----
 src/app/currentLocationController.js | 14 +++++++++-----
 src/app/window.js                    |  4 +++-
 src/app/world.js                     | 13 +++++++++----
 4 files changed, 30 insertions(+), 15 deletions(-)
---
diff --git a/src/app/city.js b/src/app/city.js
index 0e75cf2..b95233d 100644
--- a/src/app/city.js
+++ b/src/app/city.js
@@ -65,8 +65,8 @@ var WeatherWidget = GObject.registerClass({
             hscrollbar.set_opacity(0.0);
             hscrollbar.hide();
             let hadjustment = fsw.get_hadjustment();
-            hadjustment.connect('changed', this._syncLeftRightButtons.bind(this));
-            hadjustment.connect('value-changed', this._syncLeftRightButtons.bind(this));
+            hadjustment.connect('changed', () => this._syncLeftRightButtons());
+            hadjustment.connect('value-changed', () => this._syncLeftRightButtons());
         }
 
         this._forecastStack.connect('notify::visible-child', () => {
@@ -214,7 +214,7 @@ var WeatherView = GObject.registerClass({
         this._info = null;
         this._updateId = 0;
 
-        this.connect('destroy', this._onDestroy.bind(this));
+        this.connect('destroy', () => this._onDestroy());
 
         this._wallClock = new Gnome.WallClock();
         this._clockHandlerId = 0;
@@ -237,7 +237,9 @@ var WeatherView = GObject.registerClass({
         this._info = info;
 
         if (info) {
-            this._updateId = this._info.connect('updated', this._onUpdate.bind(this));
+            this._updateId = this._info.connect('updated', (info) => {
+                this._onUpdate(info)
+            });
             if (info.is_valid())
                 this._onUpdate(info);
         }
@@ -273,7 +275,9 @@ var WeatherView = GObject.registerClass({
         }
 
         if (!this._clockHandlerId && visible) {
-            this._clockHandlerId = this._wallClock.connect('notify::clock', this._updateTime.bind(this));
+            this._clockHandlerId = this._wallClock.connect('notify::clock',  () => {
+                this._updateTime();
+            });
         }
 
         this._infoPage.setTimeVisible(visible);
diff --git a/src/app/currentLocationController.js b/src/app/currentLocationController.js
index df6085e..67538d2 100644
--- a/src/app/currentLocationController.js
+++ b/src/app/currentLocationController.js
@@ -47,7 +47,9 @@ var CurrentLocationController = class CurrentLocationController {
         Geoclue.Simple.new(pkg.name,
                            Geoclue.AccuracyLevel.CITY,
                            null,
-                           this._onSimpleReady.bind(this));
+                           (object, result) => {
+                                this._onSimpleReady(object, result)
+                            });
     }
 
     _geoLocationFailed(e) {
@@ -75,8 +77,9 @@ var CurrentLocationController = class CurrentLocationController {
 
     _findLocation() {
         this._locationUpdatedId =
-                    this._simple.connect("notify::location",
-                                         this._onLocationUpdated.bind(this));
+                    this._simple.connect("notify::location", (simple) => {
+                        this._onLocationUpdated(simple);
+                    });
 
         this._onLocationUpdated(this._simple);
     }
@@ -113,8 +116,9 @@ var CurrentLocationController = class CurrentLocationController {
                 this._startGeolocationService();
             } else {
                 this._locationUpdatedId =
-                    this._simple.connect("notify::location",
-                                         this._onLocationUpdated.bind(this));
+                    this._simple.connect("notify::location", (simple) => {
+                                             this._onLocationUpdated(simple);
+                                         });
             }
         } else {
             this._simple.disconnect(this._locationUpdatedId);
diff --git a/src/app/window.js b/src/app/window.js
index 35c6f6c..93013c3 100644
--- a/src/app/window.js
+++ b/src/app/window.js
@@ -70,7 +70,9 @@ var MainWindow = GObject.registerClass(
         this._searchView = builder.get_object('initial-grid');
 
         this._searchEntry = builder.get_object('initial-grid-location-entry');
-        this._searchEntry.connect('notify::location', this._searchLocationChanged.bind(this));
+        this._searchEntry.connect('notify::location', (entry) => {
+            this._searchLocationChanged(entry);
+        });
 
         let placesButton = builder.get_object('places-button');
         this._pageWidgets[Page.CITY].push(placesButton);
diff --git a/src/app/world.js b/src/app/world.js
index e942b83..f0b3dae 100644
--- a/src/app/world.js
+++ b/src/app/world.js
@@ -58,7 +58,7 @@ var WorldContentView = GObject.registerClass(
         });
 
         let locationEntry = builder.get_object('location-entry');
-        locationEntry.connect('notify::location', this._locationChanged.bind(this));
+        locationEntry.connect('notify::location', (entry) => this._locationChanged(entry));
 
         this.connect('show', () => {
             locationEntry.grab_focus();
@@ -102,10 +102,15 @@ var WorldContentView = GObject.registerClass(
         });
 
         this._stackPopover = builder.get_object('popover-stack');
-        this._listbox.set_filter_func(this._filterListbox.bind(this));
+        this._listbox.set_filter_func((row) => this._filterListbox(row));
 
-        this.model.connect('location-added', this._onLocationAdded.bind(this));
-        this.model.connect('location-removed', this._onLocationRemoved.bind(this));
+        this.model.connect('location-added', (model, info, is_current) => {
+            this._onLocationAdded(model, info, is_current);
+        });
+
+        this.model.connect('location-removed', (model, info) => {
+            this._onLocationRemoved(model, info);
+        });
 
         this._currentLocationAdded = false;
         let list = this.model.getAll();


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