[gjs: 3/4] examples: Fix some best practices



commit 7e774490ecf4ddbc56ee5b48f799b1041aac922f
Author: Philip Chimento <philip chimento gmail com>
Date:   Wed Aug 8 23:10:09 2018 -0400

    examples: Fix some best practices
    
    As discussed in the code review of !207.

 examples/clutter.js     | 17 +++++++++--------
 examples/gio-cat.js     |  2 +-
 examples/gtk.js         |  2 +-
 examples/http-server.js |  4 ++--
 4 files changed, 13 insertions(+), 12 deletions(-)
---
diff --git a/examples/clutter.js b/examples/clutter.js
index 2fc3eabb..4a15669b 100644
--- a/examples/clutter.js
+++ b/examples/clutter.js
@@ -4,14 +4,15 @@ Clutter.init(null);
 
 let stage = new Clutter.Stage();
 
-let texture = new Clutter.Texture({filename: 'test.jpg',
-    reactive: true});
-
-texture.connect('button-press-event',
-    function(o, event) {
-        log('Clicked!');
-        return true;
-    });
+let texture = new Clutter.Texture({
+    filename: 'test.jpg',
+    reactive: true,
+});
+
+texture.connect('button-press-event', () => {
+    log('Clicked!');
+    return Clutter.EVENT_STOP;
+});
 
 let color = new Clutter.Color();
 color.from_string('Black');
diff --git a/examples/gio-cat.js b/examples/gio-cat.js
index 5b058d1a..93943caf 100644
--- a/examples/gio-cat.js
+++ b/examples/gio-cat.js
@@ -11,7 +11,7 @@ function cat(filename) {
         try {
             contents = f.load_contents_finish(res)[1];
         } catch (e) {
-            log(`*** ERROR: ${e.message}`);
+            logError(e);
             loop.quit();
             return;
         }
diff --git a/examples/gtk.js b/examples/gtk.js
index dc22a311..c3bf3836 100644
--- a/examples/gtk.js
+++ b/examples/gtk.js
@@ -23,7 +23,7 @@ let window = new Gtk.Window ({
 window.title = 'Hello World!';
 
 // This is a callback function
-function onDeleteEvent(widget, event) {
+function onDeleteEvent() {
     log('delete-event emitted');
     // If you return false in the "delete_event" signal handler, Gtk will emit
     // the "destroy" signal.
diff --git a/examples/http-server.js b/examples/http-server.js
index a49f0727..1137bfe7 100644
--- a/examples/http-server.js
+++ b/examples/http-server.js
@@ -8,7 +8,7 @@ function main() {
         msg.response_headers.set_content_type('text/html', {});
         msg.response_body.append(`<html><body>Greetings, visitor from ${client.get_host()}<br>What is your 
name?<form action="/hello"><input name="myname"></form></body></html>\n`);
     };
-    let helloHandler = function(server, msg, path, query, client) {
+    let helloHandler = function(server, msg, path, query) {
         if (!query) {
            msg.set_redirect(302, '/');
            return;
@@ -16,7 +16,7 @@ function main() {
 
         msg.status_code = 200;
         msg.response_headers.set_content_type('text/html', {charset: 'UTF-8'});
-        msg.response_body.append(`<html><body>Hello, ${query.myname}! \u263A<br><a href="/">Go 
back</a></body></html>`);
+        msg.response_body.append(`<html><body>Hello, ${query.myname}! ☺<br><a href="/">Go 
back</a></body></html>`);
     };
 
     let server = new Soup.Server({port: 1080});


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