ooops, forgot the remove `require("Glib")` since it's not even used. Updated the repo:Best RegardsOn Mon, Apr 11, 2016 at 12:03 PM, Andrea Giammarchi <andrea giammarchi gmail com> wrote:Hi Philip,I forgot to push and post about it. It took a bit more than expected and it required a different approach:
- add special AST to babel class parser
- replace some babel helper to avoid errors with natives
- overwrite Object.getPrototypeOf to avoid errors with natives
- use behind the scene imports.lang since there's a lot going on in there
In any case, the final result, using the example code you gave me, is the following:```jsconst GLib = require('GLib'), Gtk = require('Gtk') ; class TimerLabel extends Gtk.Label { constructor(props) { super(props); this._count = 0; this.label = 'Hello World!'; setInterval(() => { this._count++; this.emit('count'); }, 1000); } get count() { return this._count; } } Gtk.init(null); let win = new Gtk.Window(); win.add( new TimerLabel() .on('count', function () { if (this.count === 2) Gtk.mainQuit(); }) ); win .on('show', Gtk.main) .on('destroy', Gtk.mainQuit) .showAll() ;```I'm not sure I've missed some essential part of your example code but doesn't that look good now? :-)Best RegardsOn Sat, Apr 9, 2016 at 9:47 PM, <philip chimento gmail com> wrote:On Sat, Apr 9, 2016 at 12:19 PM Andrea Giammarchi <andrea giammarchi gmail com> wrote:Hi Philip,rather than submitting PRs to the entirety of the JS community, I believe it would make more sense to release a version of gjs that suppresses all mozjs24 lint warnings **unless** specified otherwise.Like I've said, it's about interoperability and linters rules **THANKS GOSH** are team and developers dependent.I specially found `return undefined;` as fix for `return;` being the most pointless waste of time I've ever had in my life ... so no, I'm not planning to submit PRs around to make stuff work on GJS (at least not yet and I believe that won't really solve a thing).I suggest then that you open a bug report on bugzilla.gnome.org proposing to reverse the flag. It would be a 3-line patch to change GJS_DISABLE_EXTRA_WARNINGS to GJS_ENABLE_EXTRA_WARNINGS, so I don't think doing the work will be the problem. I think your reasons make sense, so you shouldn't have trouble convincing the maintainers.On Sat, Apr 9, 2016 at 8:08 PM, <philip chimento gmail com> wrote:Is there a way to write GObject-derived classes using the native ES6 class keyword? (That's the only reason for the existence of the Lang.Class metaclass, as far as I'm concerned.)could you give me a single example where `imports.lang` is needed? In the entire `jsgtk` I haven't used it at all and I think I don't need it.`_init` methods? that's like very old style MooTools stuff but it takes nothing to have a generic ES6 class invoking it within its constructor ... right?If you could give me an example, I'd be more than happy to investigate it.Sure. Here's a slightly contrived example of writing a GObject-derived class with GObject properties:const GLib = imports.gi.GLib;const GObject = imports.gi.GObject;const Gtk = imports.gi.Gtk;const Lang = imports.lang;Gtk.init(null);const TimerLabel = new Lang.Class({Name: 'TimerLabel',Extends: Gtk.Label,Properties: {'timeout': GObject.ParamSpec.uint('timeout', '', '',GObject.ParamFlags.READWRITE | GObject.ParamFlags.CONSTRUCT_ONLY,1, 10, 1),'count': GObject.ParamSpec.uint('count', '', '',GObject.ParamFlags.READABLE, 0, GLib.MAXUINT32, 0),},_init: function (props) {this.parent(props);this._count = 0;this.label = 'Hello World!';GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, this.timeout, () => {this._count++;this.notify('count');return GLib.SOURCE_CONTINUE;});},get count() {return this._count;},});let win = new Gtk.Window();let label = new TimerLabel();win.add(label);win.connect('destroy', Gtk.main_quit);label.connect('notify::count', (obj) => {if (obj.count === 10)Gtk.main_quit();});win.show_all();Gtk.main();The Lang.Class metaclass looks for two special keys, Properties and Signals, to create GObject properties and signals internally. You could use ES2015 native properties, but AFAIU you won't get features like GObject's "notify" signal (used in the example above.)Philip