[gnome-characters] character: Utilize lexical binding rather than instance variable



commit bdf7f776f1f8ea84282d0e5b8d4de3aec67aecf7
Author: Daiki Ueno <dueno src gnome org>
Date:   Mon Mar 12 10:01:20 2018 +0100

    character: Utilize lexical binding rather than instance variable

 src/character.js | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)
---
diff --git a/src/character.js b/src/character.js
index 61aa672..66dd7f4 100644
--- a/src/character.js
+++ b/src/character.js
@@ -70,18 +70,6 @@ var CharacterDialog = new Lang.Class({
         this._setCharacter(filtered.character);
 
         this._copyRevealerTimeoutId = 0;
-        this._clipboardOwnerChangedId = 0;
-
-        this.connect('destroy', Lang.bind(this, this._disconnectSignals));
-    },
-
-    _disconnectSignals: function() {
-        if (this._copyRevealerTimeoutId > 0) {
-            GLib.source_remove(this._copyRevealerTimeoutId);
-            this._copyRevealerTimeoutId = 0;
-        }
-        if (this._clipboardOwnerChangedId > 0)
-            this._clipboard.disconnect(this._clipboardOwnerChangedId);
     },
 
     _finishSearch: function(result) {
@@ -193,10 +181,14 @@ var CharacterDialog = new Lang.Class({
     _copyCharacter: function() {
         if (this._clipboard == null) {
             this._clipboard = Gc.gtk_clipboard_get();
-            this._clipboardOwnerChangedId =
+            let clipboardOwnerChanged =
                 this._clipboard.connect('owner-change',
                                         Lang.bind(this,
                                                   this._clipboardOwnerChanged));
+            this.connect('destroy',
+                         Lang.bind(this, function() {
+                             this._clipboard.disconnect(clipboardOwnerChanged);
+                         }));
         }
         this._clipboard.set_text(this._character, -1);
         this.emit('character-copied', this._character);
@@ -209,6 +201,11 @@ var CharacterDialog = new Lang.Class({
         this._copyRevealerTimeoutId =
             GLib.timeout_add(GLib.PRIORITY_DEFAULT, 2000,
                              Lang.bind(this, this._hideCopyRevealer));
+        this.connect('destroy',
+                     Lang.bind(this, function() {
+                         if (this._copyRevealerTimeoutId > 0)
+                             GLib.source_remove(this._copyRevealerTimeoutId);
+                     }));
     },
 
     _handleRowSelected: function(listBox, row) {


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