cleanup: Use arrow notation for anonymous functions

Arrow notation is great, use it consistently through-out the code base
to bind `this` to anonymous functions, replacing the more overbose
Lang.bind(this, function() {}).

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/23
This commit is contained in:
Florian Müllner
2017-10-31 01:38:18 +01:00
committed by Florian Müllner
parent 76f09b1e49
commit 213e38c2ef
105 changed files with 2165 additions and 2408 deletions

View File

@ -16,17 +16,17 @@ var ComponentManager = new Lang.Class({
_sessionUpdated() {
let newEnabledComponents = Main.sessionMode.components;
newEnabledComponents.filter(Lang.bind(this, function(name) {
return this._enabledComponents.indexOf(name) == -1;
})).forEach(Lang.bind(this, function(name) {
newEnabledComponents.filter(
name => this._enabledComponents.indexOf(name) == -1
).forEach(name => {
this._enableComponent(name);
}));
});
this._enabledComponents.filter(Lang.bind(this, function(name) {
return newEnabledComponents.indexOf(name) == -1;
})).forEach(Lang.bind(this, function(name) {
this._enabledComponents.filter(
name => newEnabledComponents.indexOf(name) == -1
).forEach(name => {
this._disableComponent(name);
}));
});
this._enabledComponents = newEnabledComponents;
},

View File

@ -61,21 +61,20 @@ var AutomountManager = new Lang.Class({
_InhibitorsChanged(object, senderName, [inhibtor]) {
this._session.IsInhibitedRemote(GNOME_SESSION_AUTOMOUNT_INHIBIT,
Lang.bind(this,
function(result, error) {
if (!error) {
this._inhibited = result[0];
}
}));
(result, error) => {
if (!error) {
this._inhibited = result[0];
}
});
},
_startupMountAll() {
let volumes = this._volumeMonitor.get_volumes();
volumes.forEach(Lang.bind(this, function(volume) {
volumes.forEach(volume => {
this._checkAndMountVolume(volume, { checkSession: false,
useMountOp: false,
allowAutorun: false });
}));
});
this._mountAllId = 0;
return GLib.SOURCE_REMOVE;
@ -114,23 +113,23 @@ var AutomountManager = new Lang.Class({
if (drive.can_stop()) {
drive.stop
(Gio.MountUnmountFlags.FORCE, null, null,
Lang.bind(this, function(drive, res) {
(drive, res) => {
try {
drive.stop_finish(res);
} catch (e) {
log("Unable to stop the drive after drive-eject-button " + e.toString());
}
}));
});
} else if (drive.can_eject()) {
drive.eject_with_operation
(Gio.MountUnmountFlags.FORCE, null, null,
Lang.bind(this, function(drive, res) {
(drive, res) => {
try {
drive.eject_with_operation_finish(res);
} catch (e) {
log("Unable to eject the drive after drive-eject-button " + e.toString());
}
}));
});
}
},
@ -212,9 +211,7 @@ var AutomountManager = new Lang.Class({
_onVolumeRemoved(monitor, volume) {
this._volumeQueue =
this._volumeQueue.filter(function(element) {
return (element != volume);
});
this._volumeQueue.filter(element => (element != volume));
},
_reaskPassword(volume) {
@ -235,7 +232,7 @@ var AutomountManager = new Lang.Class({
},
_allowAutorunExpire(volume) {
let id = Mainloop.timeout_add_seconds(AUTORUN_EXPIRE_TIMEOUT_SECS, function() {
let id = Mainloop.timeout_add_seconds(AUTORUN_EXPIRE_TIMEOUT_SECS, () => {
volume.allowAutorun = false;
return GLib.SOURCE_REMOVE;
});

View File

@ -129,9 +129,9 @@ var ContentTypeDiscoverer = new Lang.Class({
let hotplugSniffer = new HotplugSniffer();
hotplugSniffer.SniffURIRemote(root.get_uri(),
Lang.bind(this, function([contentTypes]) {
([contentTypes]) => {
this._emitCallback(mount, contentTypes);
}));
});
}
},
@ -140,12 +140,12 @@ var ContentTypeDiscoverer = new Lang.Class({
contentTypes = [];
// we're not interested in win32 software content types here
contentTypes = contentTypes.filter(function(type) {
return (type != 'x-content/win32-software');
});
contentTypes = contentTypes.filter(
type => (type != 'x-content/win32-software')
);
let apps = [];
contentTypes.forEach(function(type) {
contentTypes.forEach(type => {
let app = Gio.app_info_get_default_for_type(type, false);
if (app)
@ -185,9 +185,9 @@ var AutorunManager = new Lang.Class({
if (!this._session.SessionIsActive)
return;
let discoverer = new ContentTypeDiscoverer(Lang.bind(this, function(mount, apps, contentTypes) {
let discoverer = new ContentTypeDiscoverer((mount, apps, contentTypes) => {
this._dispatcher.addMount(mount, apps, contentTypes);
}));
});
discoverer.guessContentTypes(mount);
},
@ -222,10 +222,7 @@ var AutorunDispatcher = new Lang.Class({
},
_getSourceForMount(mount) {
let filtered =
this._sources.filter(function (source) {
return (source.mount == mount);
});
let filtered = this._sources.filter(source => (source.mount == mount));
// we always make sure not to add two sources for the same
// mount in addMount(), so it's safe to assume filtered.length
@ -337,12 +334,12 @@ var AutorunNotification = new Lang.Class({
createBanner() {
let banner = new MessageTray.NotificationBanner(this);
this.source.apps.forEach(Lang.bind(this, function (app) {
this.source.apps.forEach(app => {
let actor = this._buttonForApp(app);
if (actor)
banner.addButton(actor);
}));
});
return banner;
},
@ -366,10 +363,10 @@ var AutorunNotification = new Lang.Class({
button_mask: St.ButtonMask.ONE,
style_class: 'hotplug-notification-item button' });
button.connect('clicked', Lang.bind(this, function() {
button.connect('clicked', () => {
startAppForMount(app, this._mount);
this.destroy();
}));
});
return button;
},

View File

@ -279,13 +279,12 @@ var KeyringPrompter = new Lang.Class({
_init() {
this._prompter = new Gcr.SystemPrompter();
this._prompter.connect('new-prompt', Lang.bind(this,
function() {
let dialog = this._enabled ? new KeyringDialog()
: new KeyringDummyDialog();
this._currentPrompt = dialog.prompt;
return this._currentPrompt;
}));
this._prompter.connect('new-prompt', () => {
let dialog = this._enabled ? new KeyringDialog()
: new KeyringDummyDialog();
this._currentPrompt = dialog.prompt;
return this._currentPrompt;
});
this._dbusId = null;
this._registered = false;
this._enabled = false;

View File

@ -83,14 +83,14 @@ var NetworkSecretDialog = new Lang.Class({
}
secret.entry.clutter_text.connect('activate', Lang.bind(this, this._onOk));
secret.entry.clutter_text.connect('text-changed', Lang.bind(this, function() {
secret.entry.clutter_text.connect('text-changed', () => {
secret.value = secret.entry.get_text();
if (secret.validate)
secret.valid = secret.validate(secret);
else
secret.valid = secret.value.length > 0;
this._updateOkButton();
}));
});
} else
secret.valid = true;
@ -464,7 +464,7 @@ var VPNRequestHandler = new Lang.Class({
},
_readStdoutOldStyle() {
this._dataStdout.read_line_async(GLib.PRIORITY_DEFAULT, null, Lang.bind(this, function(stream, result) {
this._dataStdout.read_line_async(GLib.PRIORITY_DEFAULT, null, (stream, result) => {
let [line, len] = this._dataStdout.read_line_finish_utf8(result);
if (line == null) {
@ -477,11 +477,11 @@ var VPNRequestHandler = new Lang.Class({
// try to read more!
this._readStdoutOldStyle();
}));
});
},
_readStdoutNewStyle() {
this._dataStdout.fill_async(-1, GLib.PRIORITY_DEFAULT, null, Lang.bind(this, function(stream, result) {
this._dataStdout.fill_async(-1, GLib.PRIORITY_DEFAULT, null, (stream, result) => {
let cnt = this._dataStdout.fill_finish(result);
if (cnt == 0) {
@ -495,7 +495,7 @@ var VPNRequestHandler = new Lang.Class({
// Try to read more
this._dataStdout.set_buffer_size(2 * this._dataStdout.get_buffer_size());
this._readStdoutNewStyle();
}));
});
},
_showNewStyleDialog() {
@ -562,14 +562,14 @@ var VPNRequestHandler = new Lang.Class({
let vpnSetting = this._connection.get_setting_vpn();
try {
vpnSetting.foreach_data_item(Lang.bind(this, function(key, value) {
vpnSetting.foreach_data_item((key, value) => {
this._stdin.write('DATA_KEY=' + key + '\n', null);
this._stdin.write('DATA_VAL=' + (value || '') + '\n\n', null);
}));
vpnSetting.foreach_secret(Lang.bind(this, function(key, value) {
});
vpnSetting.foreach_secret((key, value) => {
this._stdin.write('SECRET_KEY=' + key + '\n', null);
this._stdin.write('SECRET_VAL=' + (value || '') + '\n\n', null);
}));
});
this._stdin.write('DONE\n\n', null);
} catch(e) {
logError(e, 'internal error while writing connection to helper');
@ -688,17 +688,17 @@ var NetworkAgent = new Lang.Class({
let notification = new MessageTray.Notification(source, title, body);
notification.connect('activated', Lang.bind(this, function() {
notification.connect('activated', () => {
notification.answered = true;
this._handleRequest(requestId, connection, settingName, hints, flags);
}));
});
this._notifications[requestId] = notification;
notification.connect('destroy', Lang.bind(this, function() {
notification.connect('destroy', () => {
if (!notification.answered)
this._native.respond(requestId, Shell.NetworkAgentResponse.USER_CANCELED);
delete this._notifications[requestId];
}));
});
Main.messageTray.add(source);
source.notify(notification);
@ -718,9 +718,9 @@ var NetworkAgent = new Lang.Class({
}
let dialog = new NetworkSecretDialog(this._native, requestId, connection, settingName, hints);
dialog.connect('destroy', Lang.bind(this, function() {
dialog.connect('destroy', () => {
delete this._dialogs[requestId];
}));
});
this._dialogs[requestId] = dialog;
dialog.open(global.get_current_time());
},
@ -752,9 +752,9 @@ var NetworkAgent = new Lang.Class({
}
let vpnRequest = new VPNRequestHandler(this._native, requestId, binary, serviceType, connection, hints, flags);
vpnRequest.connect('destroy', Lang.bind(this, function() {
vpnRequest.connect('destroy', () => {
delete this._vpnRequests[requestId];
}));
});
this._vpnRequests[requestId] = vpnRequest;
},

View File

@ -47,7 +47,7 @@ var NotificationDirection = {
RECEIVED: 'chat-received'
};
var N_ = function(s) { return s; };
var N_ = s => s;
function makeMessageFromTpMessage(tpMessage, direction) {
let [text, flags] = tpMessage.to_text();
@ -188,10 +188,9 @@ var TelepathyClient = HAVE_TP ? new Lang.Class({
let source = new ChatSource(account, conn, channel, contact, this);
this._chatSources[channel.get_object_path()] = source;
source.connect('destroy', Lang.bind(this,
function() {
delete this._chatSources[channel.get_object_path()];
}));
source.connect('destroy', () => {
delete this._chatSources[channel.get_object_path()];
});
},
vfunc_handle_channels(account, conn, channels, requests,
@ -262,14 +261,14 @@ var TelepathyClient = HAVE_TP ? new Lang.Class({
}
// Approve private text channels right away as we are going to handle it
dispatchOp.claim_with_async(this, Lang.bind(this, function(dispatchOp, result) {
dispatchOp.claim_with_async(this, (dispatchOp, result) => {
try {
dispatchOp.claim_with_finish(result);
this._handlingChannels(account, conn, [channel], false);
} catch (err) {
log('Failed to Claim channel: ' + err);
}
}));
});
context.accept();
},
@ -322,15 +321,13 @@ var ChatSource = new Lang.Class({
this._notification = new ChatNotification(this);
this._notification.connect('activated', Lang.bind(this, this.open));
this._notification.connect('updated', Lang.bind(this,
function() {
if (this._banner && this._banner.expanded)
this._ackMessages();
}));
this._notification.connect('destroy', Lang.bind(this,
function() {
this._notification = null;
}));
this._notification.connect('updated', () => {
if (this._banner && this._banner.expanded)
this._ackMessages();
});
this._notification.connect('destroy', () => {
this._notification = null;
});
this.pushNotification(this._notification);
},
@ -345,11 +342,10 @@ var ChatSource = new Lang.Class({
// We ack messages when the user expands the new notification
let id = this._banner.connect('expanded', Lang.bind(this, this._ackMessages));
this._banner.actor.connect('destroy', Lang.bind(this,
function() {
this._banner.disconnect(id);
this._banner = null;
}));
this._banner.actor.connect('destroy', () => {
this._banner.disconnect(id);
this._banner = null;
});
return this._banner;
},
@ -504,7 +500,7 @@ var ChatSource = new Lang.Class({
this._ackMessages();
// The chat box has been destroyed so it can't
// handle the channel any more.
this._channel.close_async(function(channel, result) {
this._channel.close_async((channel, result) => {
channel.close_finish(result);
});
} else {
@ -602,9 +598,9 @@ var ChatSource = new Lang.Class({
}
let msg = Tp.ClientMessage.new_text(type, text);
this._channel.send_message_async(msg, 0, Lang.bind(this, function (src, result) {
this._channel.send_message_async(msg, 0, (src, result) => {
this._channel.send_message_finish(result);
}));
});
},
setChatState(state) {
@ -722,7 +718,7 @@ var ChatNotification = new Lang.Class({
let maxLength = (lastMessageTime < currentTime - SCROLLBACK_RECENT_TIME) ?
SCROLLBACK_IDLE_LENGTH : SCROLLBACK_RECENT_LENGTH;
let filteredHistory = this.messages.filter(function(item) { return item.realMessage });
let filteredHistory = this.messages.filter(item => item.realMessage);
if (filteredHistory.length > maxLength) {
let lastMessageToKeep = filteredHistory[maxLength];
let expired = this.messages.splice(this.messages.indexOf(lastMessageToKeep));
@ -830,13 +826,13 @@ var ChatNotificationBanner = new Lang.Class({
this._responseEntry.clutter_text.connect('text-changed', Lang.bind(this, this._onEntryChanged));
this.setActionArea(this._responseEntry);
this._responseEntry.clutter_text.connect('key-focus-in', Lang.bind(this, function() {
this._responseEntry.clutter_text.connect('key-focus-in', () => {
this.focused = true;
}));
this._responseEntry.clutter_text.connect('key-focus-out', Lang.bind(this, function() {
});
this._responseEntry.clutter_text.connect('key-focus-out', () => {
this.focused = false;
this.emit('unfocused');
}));
});
this._scrollArea = new St.ScrollView({ style_class: 'chat-scrollview vfade',
vscrollbar_policy: Gtk.PolicyType.AUTOMATIC,
@ -855,11 +851,11 @@ var ChatNotificationBanner = new Lang.Class({
// force a scroll to the bottom if things change while we were at the
// bottom
this._oldMaxScrollValue = this._scrollArea.vscroll.adjustment.value;
this._scrollArea.vscroll.adjustment.connect('changed', Lang.bind(this, function(adjustment) {
this._scrollArea.vscroll.adjustment.connect('changed', adjustment => {
if (adjustment.value == this._oldMaxScrollValue)
this.scrollTo(St.Side.BOTTOM);
this._oldMaxScrollValue = Math.max(adjustment.lower, adjustment.upper - adjustment.page_size);
}));
});
this._inputHistory = new History.HistoryManager({ entry: this._responseEntry.clutter_text });
@ -868,19 +864,19 @@ var ChatNotificationBanner = new Lang.Class({
this._messageActors = new Map();
this._messageAddedId = this.notification.connect('message-added',
Lang.bind(this, function(n, message) {
(n, message) => {
this._addMessage(message);
}));
});
this._messageRemovedId = this.notification.connect('message-removed',
Lang.bind(this, function(n, message) {
(n, message) => {
let actor = this._messageActors.get(message);
if (this._messageActors.delete(message))
actor.destroy();
}));
});
this._timestampChangedId = this.notification.connect('timestamp-changed',
Lang.bind(this, function(n, message) {
(n, message) => {
this._updateTimestamp(message);
}));
});
for (let i = this.notification.messages.length - 1; i >= 0; i--)
this._addMessage(this.notification.messages[i]);