Hi Philip, so ... one problem per time. First one: how to drop lint warnings
trivial if you have an executable, like in my case. I'll use `window.name` property since it's pointless to have `window` at all, generally speaking, but in GJS case is even more pointless to have a `window.name` property. Hack #1 is to drop `#!/usr/bin/env gjs` as executable header, and use the following instead: ``` #!/usr/bin/env bash name=// GJS_DISABLE_EXTRA_WARNINGS=1 exec gjs "$0" "$@" ``` This seems to work like a charm in my case, please let me know if there's something that might go wrong. Second problem: my `require("GObject")` is missing something, so I need to make it work as `imports.gi.GObject` does. I'm probaby ignoring, for some reason, `GObject.ParamSpec.uint`, or not attaching it to the ` GObject.ParamSpec` object. I need to solve this first before moving on. Third problem: `new Lang.Class({Name: 'TimerLabel', Extends: Gtk.Label })` There's something happening behind the `imports.lang` logic I might be able to either replicate or intercept overwriting `Object.getPrototypeOf` or other native methods. I'm not sure it's possible, but I'm confident having a native polyfill/shim/sham/patcher included helps understanding transpiled code too. After all, it's Babel, and what gets executed passes through what's available on GJS so yes, it might be superfluous, but I don't have a solution yet. Thanks for taking time to answer, showing hints, and examples. Best Regards On Sat, Apr 9, 2016 at 9:47 PM, <philip.chime...@gmail.com> wrote: > 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