Closed MisterGuinness closed 2 years ago
Here's a list of remaining uses of Lang
$ grep -i lang\. extension.js prefs.js utilities.js
extension.js:const Lang = imports.lang;
extension.js: Utilities.UDisks.get_drive_ata_proxies(Lang.bind(this, function(proxies) {
extension.js: this._settingsChanged = this._settings.connect('changed', Lang.bind(this, this._querySensors));
extension.js: this.connect('destroy', Lang.bind(this, this._onDestroy));
extension.js: this._eventLoop = Mainloop.timeout_add_seconds(this._settings.get_int('update-time'), Lang.bind(this, function (){
extension.js: this._sensorsFuture = new Utilities.Future(this.sensorsArgv, Lang.bind(this,function(stdout){
extension.js: this._hddtempFuture = new Utilities.Future(this.hddtempArgv, Lang.bind(this,function(stdout){
extension.js: item.connect('activate', Lang.bind(this, function () {
extension.js: item.connect('activate', Lang.bind(this, function () {
prefs.js:const Lang = imports.lang;
prefs.js: update_time.connect('value-changed', Lang.bind(this, this._onUpdateTimeChanged));
prefs.js: fahrenheitRadio.connect('toggled', Lang.bind(this, this._onUnitChanged, 'Fahrenheit'));
prefs.js: centigradeRadio.connect('toggled', Lang.bind(this, this._onUnitChanged, 'Centigrade'));
utilities.js:const Lang = imports.lang;
utilities.js:var Future = new Lang.Class({
utilities.js: this._childWatch = GLib.child_watch_add(GLib.PRIORITY_DEFAULT, pid, Lang.bind(this, function(pid, status, requestObj) {
utilities.js: this._dataStdout.fill_async(-1, GLib.PRIORITY_DEFAULT, null, Lang.bind(this, function(stream, result) {
Check out the "Future" class in utilities. How is that working without complaint in F36Beta, or is it never used?
One thing I found out the hard way when switching from the old Lang.bind to the new [function].bind is that the additional arguments to bind, or I should say the new different implementation of bind, are now prepended to underlying signal's "default" arguments to form the signal's callback signature
So, where the old code had
centigradeRadio.connect('toggled', Lang.bind(this, this._onUnitChanged, 'Centigrade'));
and the corresponding callback
_onUnitChanged: function (button, unit) {
where button (widget) is the default argument to the toggle callback, and the text 'Centigrade' is an additional argument appended, ie after button
now I have
centigradeRadio.connect('toggled', this._onUnitChanged.bind(this, 'Centigrade'));
_onUnitChanged: function (unit, button) {
where the additional argument comes first, then the default argument (ie in this case swapped around compared to Lang.bind)
Note, on MDN for .bind() is does mention this prepending
arg1, arg2, ...argN
Optional
Arguments to prepend to arguments provided to the bound function when invoking func.
Tested ok
Based on the success of issue #60 switching away from Lang.Class, it is time to also switch from Lang.bind to function.bind or similar and remove the Lang import altogether.