After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 790301 - extensions: Modernize JS usage
extensions: Modernize JS usage
Status: RESOLVED OBSOLETE
Product: gnome-shell
Classification: Core
Component: extensions-module
unspecified
Other All
: Normal normal
: ---
Assigned To: gnome-shell-maint
Depends on:
Blocks:
 
 
Reported: 2017-11-13 17:33 UTC by Florian Müllner
Modified: 2017-11-25 02:28 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
cleanup: Fix some coding style issues (6.34 KB, patch)
2017-11-13 17:33 UTC, Florian Müllner
none Details | Review
cleanup: Replace tabs with spaces (38.18 KB, patch)
2017-11-13 17:34 UTC, Florian Müllner
none Details | Review
cleanup: Use arrow-notation for anonymous functions (38.59 KB, patch)
2017-11-13 17:34 UTC, Florian Müllner
none Details | Review
cleanup: Use method syntax (61.74 KB, patch)
2017-11-13 17:34 UTC, Florian Müllner
none Details | Review
cleanup: Port non-GObject classes to ES6 classes (57.01 KB, patch)
2017-11-13 17:34 UTC, Florian Müllner
none Details | Review
cleanup: Port GObject classes to ES6 classes (9.33 KB, patch)
2017-11-13 17:34 UTC, Florian Müllner
none Details | Review
cleanup: Get rid of Lang.bind() (35.55 KB, patch)
2017-11-13 17:34 UTC, Florian Müllner
none Details | Review

Description Florian Müllner 2017-11-13 17:33:50 UTC
First fix a couple of style issues, then modernize the style to use:

 - arrow notation
 - method syntax
 - ES6 classes
 - GJS' ES6 class wrapper for GObject classes
 - Function.prototype.bind()

Doing a similar cleanup for gnome-shell is unfortunately harder:
While ES6 classes can inherit from Lang.Class, the reverse is not true. So this will need some more thought (or at least enough heads-up before pulling the switch) to not break extensions left and right ...
Comment 1 Florian Müllner 2017-11-13 17:33:57 UTC
Created attachment 363523 [details] [review]
cleanup: Fix some coding style issues
Comment 2 Florian Müllner 2017-11-13 17:34:02 UTC
Created attachment 363524 [details] [review]
cleanup: Replace tabs with spaces
Comment 3 Florian Müllner 2017-11-13 17:34:08 UTC
Created attachment 363525 [details] [review]
cleanup: Use arrow-notation for anonymous functions

Arrow notation is great, but as we only started using it recently,
we currently have a wild mix of Lang.bind(), function() and () => {}.
To make the style consistent again, change all anonymous functions
to arrow notation.
Comment 4 Florian Müllner 2017-11-13 17:34:13 UTC
Created attachment 363526 [details] [review]
cleanup: Use method syntax

Modern javascript has a short-hand for function properties, embrace
it for better readability and to prepare for porting to ES6 classes.
Comment 5 Florian Müllner 2017-11-13 17:34:19 UTC
Created attachment 363527 [details] [review]
cleanup: Port non-GObject classes to ES6 classes

ES6 finally adds standard class syntax to the language, so we can
replace our custom Lang.Class framework with the new syntax. Any
classes that inherit from GObject will need special treatment,
so limit the port to regular javascript classes for now.
Comment 6 Florian Müllner 2017-11-13 17:34:25 UTC
Created attachment 363528 [details] [review]
cleanup: Port GObject classes to ES6 classes

GJS added API for defining GObject classes with ES6 class syntax
last cycle, use it to port the remaining Lang.Class classes to
the new syntax.
Comment 7 Florian Müllner 2017-11-13 17:34:30 UTC
Created attachment 363529 [details] [review]
cleanup: Get rid of Lang.bind()

After replacing Lang.Class with ES6 classes and adopting arrow notation
for anonymous callbacks, we only use the Lang module to bind `this` to
named callbacks. However since ES5, this functionality is already provided
by Function.prototype.bind() - in fact, Lang.bind() itself uses it when
no extra arguments are specified.

So just use the built-in function directly instead of the wrapper.
Comment 8 Florian Müllner 2017-11-25 02:28:47 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/gnome-shell-extensions/issues/30.