[sushi/wip/cosimoc/no-clutter: 35/50] Stop using Lang.bind()



commit e46a291a21ee9e1bccc084dea3d31c6f3a421936
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Sat Jun 15 12:18:42 2019 -0700

    Stop using Lang.bind()
    
    Either use arrow functions or the bind() method instead.

 src/js/ui/fallbackRenderer.js |  4 +---
 src/js/ui/mainWindow.js       | 56 +++++++++++++++++++------------------------
 src/js/viewers/audio.js       | 45 +++++++++++++---------------------
 src/js/viewers/evince.js      | 19 +++++++--------
 src/js/viewers/image.js       | 55 +++++++++++++++++++-----------------------
 src/js/viewers/text.js        |  7 +++---
 6 files changed, 76 insertions(+), 110 deletions(-)
---
diff --git a/src/js/ui/fallbackRenderer.js b/src/js/ui/fallbackRenderer.js
index ec724ac..7cb0524 100644
--- a/src/js/ui/fallbackRenderer.js
+++ b/src/js/ui/fallbackRenderer.js
@@ -46,9 +46,7 @@ var FallbackRenderer = new Lang.Class({
 
         this._fileLoader = new Sushi.FileLoader();
         this._fileLoader.file = file;
-        this._fileLoaderId =
-            this._fileLoader.connect('notify',
-                                     Lang.bind(this, this._onFileInfoChanged));
+        this._fileLoaderId = this._fileLoader.connect('notify', this._onFileInfoChanged.bind(this));
 
         this._image = new Gtk.Image();
         this.pack_start(this._image, false, false, 0);
diff --git a/src/js/ui/mainWindow.js b/src/js/ui/mainWindow.js
index 59f7153..e4e47c8 100644
--- a/src/js/ui/mainWindow.js
+++ b/src/js/ui/mainWindow.js
@@ -98,18 +98,13 @@ var MainWindow = new Lang.Class({
                                              decoration_layout: 'menu:close' });
         this.set_titlebar(this._titlebar);
 
-        this.connect('delete-event',
-                     Lang.bind(this, this._onDeleteEvent));
-        this.connect('key-press-event',
-                     Lang.bind(this, this._onKeyPressEvent));
-        this.connect('motion-notify-event',
-                     Lang.bind(this, this._onMotionNotifyEvent));
-        this.connect('realize',
-                     Lang.bind(this, this._onRealize));
+        this.connect('delete-event', this._onDeleteEvent.bind(this));
+        this.connect('key-press-event', this._onKeyPressEvent.bind(this));
+        this.connect('motion-notify-event', this._onMotionNotifyEvent.bind(this));
+        this.connect('realize', this._onRealize.bind(this));
 
         let eventBox = new Gtk.EventBox({ visible_window: false });
-        eventBox.connect('button-press-event',
-                         Lang.bind(this, this._onButtonPressEvent));
+        eventBox.connect('button-press-event', this._onButtonPressEvent.bind(this));
         this.add(eventBox);
 
         this._embed = new Embed();
@@ -203,25 +198,24 @@ var MainWindow = new Lang.Class({
     },
 
     _createRenderer : function(file) {
-        file.query_info_async
-        (Gio.FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME + ',' +
-         Gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
-         Gio.FileQueryInfoFlags.NONE,
-         GLib.PRIORITY_DEFAULT, null,
-         Lang.bind (this, function(obj, res) {
-             try {
-                 this._fileInfo = obj.query_info_finish(res);
-                 this.setTitle(this._fileInfo.get_display_name());
-
-                 /* now prepare the real renderer */
-                 let klass = this._mimeHandler.getKlass(this._fileInfo.get_content_type());
-                 this._createView(file, klass);
-                 this._createToolbar();
-             } catch(e) {
-                 /* FIXME: report the error */
-                 logError(e, 'Error creating viewer');
-             }})
-        );
+        file.query_info_async(
+            [Gio.FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
+             Gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE].join(','),
+            Gio.FileQueryInfoFlags.NONE, GLib.PRIORITY_DEFAULT, null,
+            (obj, res) => {
+                try {
+                    this._fileInfo = obj.query_info_finish(res);
+                    this.setTitle(this._fileInfo.get_display_name());
+
+                    /* now prepare the real renderer */
+                    let klass = this._mimeHandler.getKlass(this._fileInfo.get_content_type());
+                    this._createView(file, klass);
+                    this._createToolbar();
+                } catch(e) {
+                    /* FIXME: report the error */
+                    logError(e, 'Error creating viewer');
+                }
+            });
     },
 
     _createView : function (file, klass) {
@@ -282,9 +276,7 @@ var MainWindow = new Lang.Class({
             this._toolbar.reveal_child = true;
 
         this._removeToolbarTimeout();
-        this._toolbarId = Mainloop.timeout_add(1500,
-                                               Lang.bind(this,
-                                                         this._onToolbarTimeout));
+        this._toolbarId = Mainloop.timeout_add(1500, this._onToolbarTimeout.bind(this));
     },
 
     _onToolbarTimeout : function() {
diff --git a/src/js/viewers/audio.js b/src/js/viewers/audio.js
index c98d5c5..10e490a 100644
--- a/src/js/viewers/audio.js
+++ b/src/js/viewers/audio.js
@@ -105,30 +105,21 @@ const AudioRenderer = new Lang.Class({
         this._player.playing = true;
 
         this._playerNotifies.push(
-            this._player.connect('notify::progress',
-                                 Lang.bind(this, this._onPlayerProgressChanged)));
+            this._player.connect('notify::progress', this._onPlayerProgressChanged.bind(this)));
         this._playerNotifies.push(
-            this._player.connect('notify::duration',
-                                 Lang.bind(this, this._onPlayerDurationChanged)));
+            this._player.connect('notify::duration', this._onPlayerDurationChanged.bind(this)));
         this._playerNotifies.push(
-            this._player.connect('notify::state',
-                                 Lang.bind(this, this._onPlayerStateChanged)));
+            this._player.connect('notify::state', this._onPlayerStateChanged.bind(this)));
         this._playerNotifies.push(
-            this._player.connect('notify::taglist',
-                                 Lang.bind(this, this._onTagListChanged)));
+            this._player.connect('notify::taglist', this._onTagListChanged.bind(this)));
         this._playerNotifies.push(
-            this._player.connect('notify::cover',
-                                 Lang.bind(this, this._onCoverArtChanged)));
+            this._player.connect('notify::cover', this._onCoverArtChanged.bind(this)));
     },
 
     _onDestroy : function() {
-        this._playerNotifies.forEach(Lang.bind(this,
-            function(id) {
-                this._player.disconnect(id);
-            }));
-
-        this._player.playing = false;
+        this._playerNotifies.forEach((id) => this._player.disconnect(id));
         this._playerNotifies = [];
+        this._player.playing = false;
         this._player = null;
     },
 
@@ -194,9 +185,7 @@ const AudioRenderer = new Lang.Class({
         this._mainWindow.setTitle(windowTitle);
 
         this._artFetcher = new Sushi.CoverArtFetcher();
-        this._artFetcher.connect('notify::cover',
-                                 Lang.bind(this, this._onCoverArtChanged));
-
+        this._artFetcher.connect('notify::cover', this._onCoverArtChanged.bind(this));
         this._artFetcher.taglist = tags;
 
         this._mainWindow.queue_allocate();
@@ -255,11 +244,10 @@ const AudioRenderer = new Lang.Class({
     },
 
     populateToolbar : function (toolbar) {
-        this._toolbarPlay =
-            Utils.createToolButton('media-playback-pause-symbolic', Lang.bind(this, function () {
-                let playing = !this._player.playing;
-                this._player.playing = playing;
-            }));
+        this._toolbarPlay = Utils.createToolButton('media-playback-pause-symbolic', () => {
+            let playing = !this._player.playing;
+            this._player.playing = playing;
+        });
         toolbar.add(this._toolbarPlay);
 
         this._currentLabel = new Gtk.Label({ margin_start: 6,
@@ -271,11 +259,10 @@ const AudioRenderer = new Lang.Class({
                                      0, 1000, 10);
         this._progressBar.set_value(0);
         this._progressBar.set_draw_value(false);
-        this._progressBar.connect('value-changed',
-                                  Lang.bind(this, function() {
-                                      if(!this._isSettingValue)
-                                          this._player.progress = this._progressBar.get_value() / 1000;
-                                  }));
+        this._progressBar.connect('value-changed', () => {
+            if(!this._isSettingValue)
+                this._player.progress = this._progressBar.get_value() / 1000;
+        });
         this._progressBar.set_size_request(200, -1);
         toolbar.add(this._progressBar);
 
diff --git a/src/js/viewers/evince.js b/src/js/viewers/evince.js
index 1cb4380..8ecedaa 100644
--- a/src/js/viewers/evince.js
+++ b/src/js/viewers/evince.js
@@ -53,8 +53,7 @@ const EvinceRenderer = new Lang.Class({
         this._file = file;
 
         this._pdfLoader = new Sushi.PdfLoader();
-        this._pdfLoader.connect('notify::document',
-                                Lang.bind(this, this._onDocumentLoaded));
+        this._pdfLoader.connect('notify::document', this._onDocumentLoaded.bind(this));
         this._pdfLoader.uri = file.get_uri();
 
         this._view = EvView.View.new();
@@ -79,7 +78,7 @@ const EvinceRenderer = new Lang.Class({
         this._model.set_sizing_mode(EvView.SizingMode.FIT_WIDTH);
         this._model.set_continuous(true);
 
-        this._model.connect('page-changed', Lang.bind(this, this._updatePageLabel));
+        this._model.connect('page-changed', this._updatePageLabel.bind(this));
         this._updatePageLabel();
 
         this._view.set_model(this._model);
@@ -90,10 +89,9 @@ const EvinceRenderer = new Lang.Class({
     },
 
     populateToolbar : function(toolbar) {
-        this._toolbarBack =
-            Utils.createToolButton('go-previous-symbolic', Lang.bind(this, function () {
-                this._view.previous_page();
-            }));
+        this._toolbarBack = Utils.createToolButton('go-previous-symbolic', () => {
+            this._view.previous_page();
+        });
         toolbar.add(this._toolbarBack);
 
         this._pageLabel = new Gtk.Label({ hexpand: true,
@@ -101,10 +99,9 @@ const EvinceRenderer = new Lang.Class({
                                           margin_end: 10 });
         toolbar.add(this._pageLabel);
 
-        this._toolbarForward =
-            Utils.createToolButton('go-next-symbolic', Lang.bind(this, function () {
-                this._view.next_page();
-            }));
+        this._toolbarForward = Utils.createToolButton('go-next-symbolic', () => {
+            this._view.next_page();
+        });
         toolbar.add(this._toolbarForward);
 
         let separator = new Gtk.Separator({ orientation: Gtk.Orientation.VERTICAL });
diff --git a/src/js/viewers/image.js b/src/js/viewers/image.js
index 366066b..6ba8f17 100644
--- a/src/js/viewers/image.js
+++ b/src/js/viewers/image.js
@@ -147,40 +147,34 @@ const ImageRenderer = new Lang.Class({
     },
 
     _createImageTexture : function(file) {
-        file.read_async
-        (GLib.PRIORITY_DEFAULT, null,
-         Lang.bind(this,
-                   function(obj, res) {
-                       try {
-                           let stream = obj.read_finish(res);
-                           this._textureFromStream(stream);
-                       } catch (e) {
-                           logError(e, `Unable to read image file ${file.get_uri()}`);
-                       }
-                   }));
+        file.read_async(GLib.PRIORITY_DEFAULT, null, (obj, res) => {
+            try {
+                let stream = obj.read_finish(res);
+                this._textureFromStream(stream);
+            } catch (e) {
+                logError(e, `Unable to read image file ${file.get_uri()}`);
+            }
+        });
     },
 
     _textureFromStream : function(stream) {
-        GdkPixbuf.PixbufAnimation.new_from_stream_async
-        (stream, null,
-         Lang.bind(this, function(obj, res) {
-             let anim = GdkPixbuf.PixbufAnimation.new_from_stream_finish(res);
+        GdkPixbuf.PixbufAnimation.new_from_stream_async(stream, null, (obj, res) => {
+            let anim = GdkPixbuf.PixbufAnimation.new_from_stream_finish(res);
 
-             this._iter = anim.get_iter(null);
-             this.pix = this._iter.get_pixbuf().apply_embedded_orientation();
+            this._iter = anim.get_iter(null);
+            this.pix = this._iter.get_pixbuf().apply_embedded_orientation();
 
-             if (!anim.is_static_image())
-                 this._startTimeout();
+            if (!anim.is_static_image())
+                this._startTimeout();
 
-             stream.close_async(GLib.PRIORITY_DEFAULT,
-                                null, function(object, res) {
-                                    try {
-                                        object.close_finish(res);
-                                    } catch (e) {
-                                        logError(e, 'Unable to close the stream');
-                                    }
-                                });
-         }));
+            stream.close_async(GLib.PRIORITY_DEFAULT, null, (obj, res) => {
+                try {
+                    obj.close_finish(res);
+                } catch (e) {
+                    logError(e, 'Unable to close the stream');
+                }
+            });
+         });
     },
 
     get resizePolicy() {
@@ -188,9 +182,8 @@ const ImageRenderer = new Lang.Class({
     },
 
     _startTimeout : function() {
-        this._timeoutId = Mainloop.timeout_add(this._iter.get_delay_time(),
-                                               Lang.bind(this,
-                                                         this._advanceImage));
+        this._timeoutId = Mainloop.timeout_add(
+            this._iter.get_delay_time(), this._advanceImage.bind(this));
     },
 
     populateToolbar : function(toolbar) {
diff --git a/src/js/viewers/text.js b/src/js/viewers/text.js
index fa325cd..15aaa4d 100644
--- a/src/js/viewers/text.js
+++ b/src/js/viewers/text.js
@@ -64,21 +64,20 @@ const TextRenderer = new Lang.Class({
         this._file = file;
 
         let textLoader = new Sushi.TextLoader();
-        textLoader.connect('loaded',
-                           Lang.bind(this, this._onBufferLoaded));
+        textLoader.connect('loaded', this._onBufferLoaded.bind(this));
         textLoader.uri = file.get_uri();
 
         this._view = new GtkSource.View({ editable: false,
                                           cursor_visible: false,
                                           monospace: true });
         this._view.set_can_focus(false);
-        this._view.connect('button-press-event', Lang.bind(this, function(view, event) {
+        this._view.connect('button-press-event', (view, event) => {
             let [, button] = event.get_button();
             if (button == Gdk.BUTTON_SECONDARY)
                 return true;
 
             return false;
-        }));
+        });
 
         this.add(this._view);
     },


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