[gjs/wip/ptomato/classes] class: Move to ES6 classes in internal code



commit 207590bdbc465713ae6baba7a1d0a2e71bf35a11
Author: Philip Chimento <philip chimento gmail com>
Date:   Sun Jul 23 21:10:38 2017 -0700

    class: Move to ES6 classes in internal code
    
    Where possible, move usage of Lang.Class within GJS to use ES6 classes.
    That is currently possible for any classes which don't inherit from
    GObject classes and don't implement Lang.Interfaces.
    
    Remove the documentation for the Lang.Class class framework, as it's now
    become outdated.

 doc/Class_Framework.md            |   98 -------------------------------------
 installed-tests/js/minijasmine.js |   30 +++++------
 installed-tests/js/testLang.js    |   12 ++---
 installed-tests/js/testSignals.js |    5 +--
 4 files changed, 20 insertions(+), 125 deletions(-)
---
diff --git a/installed-tests/js/minijasmine.js b/installed-tests/js/minijasmine.js
index b03c205..6af74e3 100644
--- a/installed-tests/js/minijasmine.js
+++ b/installed-tests/js/minijasmine.js
@@ -48,19 +48,17 @@ Lang.copyProperties(jasmineInterface, window);
 
 // Reporter that outputs according to the Test Anything Protocol
 // See http://testanything.org/tap-specification.html
-const TapReporter = new Lang.Class({
-    Name: 'TapReporter',
-
-    _init: function () {
+class TapReporter {
+    constructor() {
         this._failedSuites = [];
         this._specCount = 0;
-    },
+    }
 
-    jasmineStarted: function (info) {
+    jasmineStarted(info) {
         print('1..' + info.totalSpecsDefined);
-    },
+    }
 
-    jasmineDone: function () {
+    jasmineDone() {
         this._failedSuites.forEach(failure => {
             failure.failedExpectations.forEach(result => {
                 print('not ok - An error was thrown outside a test');
@@ -69,9 +67,9 @@ const TapReporter = new Lang.Class({
         });
 
         window._jasmineMain.quit();
-    },
+    }
 
-    suiteDone: function (result) {
+    suiteDone(result) {
         if (result.failedExpectations && result.failedExpectations.length > 0) {
             window._jasmineRetval = 1;
             this._failedSuites.push(result);
@@ -80,13 +78,13 @@ const TapReporter = new Lang.Class({
         if (result.status === 'disabled') {
             print('# Suite was disabled:', result.fullName);
         }
-    },
+    }
 
-    specStarted: function () {
+    specStarted() {
         this._specCount++;
-    },
+    }
 
-    specDone: function (result) {
+    specDone(result) {
         let tap_report;
         if (result.status === 'failed') {
             window._jasmineRetval = 1;
@@ -110,7 +108,7 @@ const TapReporter = new Lang.Class({
                 print(stackTrace.split('\n').map((str) => '#   ' + str).join('\n'));
             });
         }
-    },
-});
+    }
+}
 
 window._jasmineEnv.addReporter(new TapReporter());
diff --git a/installed-tests/js/testLang.js b/installed-tests/js/testLang.js
index 1e0d307..13735e6 100644
--- a/installed-tests/js/testLang.js
+++ b/installed-tests/js/testLang.js
@@ -53,16 +53,14 @@ describe('Lang module', function () {
 
 
     describe('bind()', function () {
-        const Obj = new Lang.Class({
-            Name: 'Obj',
-            callback: function () {
-                return true;
-            },
-        });
         let o;
 
         beforeEach(function () {
-            o = new Obj();
+            o = {
+                callback() {
+                    return true;
+                }
+            };
             spyOn(o, 'callback').and.callThrough();
         });
 
diff --git a/installed-tests/js/testSignals.js b/installed-tests/js/testSignals.js
index 5944b29..6b1c0e3 100644
--- a/installed-tests/js/testSignals.js
+++ b/installed-tests/js/testSignals.js
@@ -12,10 +12,7 @@ describe('Object with signals', function () {
     testSignals(Foo);
 });
 
-const FooWithoutSignals = new Lang.Class({
-    Name: 'FooWithoutSignals',
-    _init: function () {},
-});
+class FooWithoutSignals {}
 Signals.addSignalMethods(FooWithoutSignals.prototype);
 
 describe('Object with signals added', function () {


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