On Sat, Apr 9, 2016 at 12:19 PM Andrea Giammarchi <
andrea.giammar...@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.chime...@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
_______________________________________________
javascript-list mailing list
javascript-list@gnome.org
https://mail.gnome.org/mailman/listinfo/javascript-list

Reply via email to