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:

committed by
Florian Müllner

parent
76f09b1e49
commit
213e38c2ef
@ -293,12 +293,10 @@ var NMConnectionSection = new Lang.Class({
|
||||
if (!item)
|
||||
return;
|
||||
|
||||
item.connect('icon-changed', Lang.bind(this, function() {
|
||||
this._iconChanged();
|
||||
}));
|
||||
item.connect('activation-failed', Lang.bind(this, function(item, reason) {
|
||||
item.connect('icon-changed', () => { this._iconChanged(); });
|
||||
item.connect('activation-failed', (item, reason) => {
|
||||
this.emit('activation-failed', reason);
|
||||
}));
|
||||
});
|
||||
item.connect('name-changed', Lang.bind(this, this._sync));
|
||||
|
||||
let pos = Util.insertSorted(this._connections, connection, Lang.bind(this, this._connectionSortFunction));
|
||||
@ -550,9 +548,9 @@ var NMDeviceModem = new Lang.Class({
|
||||
|
||||
if (this._mobileDevice) {
|
||||
this._operatorNameId = this._mobileDevice.connect('notify::operator-name', Lang.bind(this, this._sync));
|
||||
this._signalQualityId = this._mobileDevice.connect('notify::signal-quality', Lang.bind(this, function() {
|
||||
this._signalQualityId = this._mobileDevice.connect('notify::signal-quality', () => {
|
||||
this._iconChanged();
|
||||
}));
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
@ -649,13 +647,9 @@ var NMWirelessDialogItem = new Lang.Class({
|
||||
this.actor = new St.BoxLayout({ style_class: 'nm-dialog-item',
|
||||
can_focus: true,
|
||||
reactive: true });
|
||||
this.actor.connect('key-focus-in', Lang.bind(this, function() {
|
||||
this.emit('selected');
|
||||
}));
|
||||
this.actor.connect('key-focus-in', () => { this.emit('selected'); });
|
||||
let action = new Clutter.ClickAction();
|
||||
action.connect('clicked', Lang.bind(this, function() {
|
||||
this.actor.grab_key_focus();
|
||||
}));
|
||||
action.connect('clicked', () => { this.actor.grab_key_focus(); });
|
||||
this.actor.add_action(action);
|
||||
|
||||
let title = ssidToLabel(this._ap.get_ssid());
|
||||
@ -725,9 +719,9 @@ var NMWirelessDialog = new Lang.Class({
|
||||
this._buildLayout();
|
||||
|
||||
let connections = client.get_connections();
|
||||
this._connections = connections.filter(Lang.bind(this, function(connection) {
|
||||
return device.connection_valid(connection);
|
||||
}));
|
||||
this._connections = connections.filter(
|
||||
connection => device.connection_valid(connection)
|
||||
);
|
||||
|
||||
this._apAddedId = device.connect('access-point-added', Lang.bind(this, this._accessPointAdded));
|
||||
this._apRemovedId = device.connect('access-point-removed', Lang.bind(this, this._accessPointRemoved));
|
||||
@ -735,9 +729,9 @@ var NMWirelessDialog = new Lang.Class({
|
||||
|
||||
// accessPointAdded will also create dialog items
|
||||
let accessPoints = device.get_access_points() || [ ];
|
||||
accessPoints.forEach(Lang.bind(this, function(ap) {
|
||||
accessPoints.forEach(ap => {
|
||||
this._accessPointAdded(this._device, ap);
|
||||
}));
|
||||
});
|
||||
|
||||
this._selectedNetwork = null;
|
||||
this._activeApChanged();
|
||||
@ -902,12 +896,12 @@ var NMWirelessDialog = new Lang.Class({
|
||||
|
||||
let airplaneSubStack = new St.Widget({ layout_manager: new Clutter.BinLayout });
|
||||
this._airplaneButton = new St.Button({ style_class: 'modal-dialog-button button' });
|
||||
this._airplaneButton.connect('clicked', Lang.bind(this, function() {
|
||||
this._airplaneButton.connect('clicked', () => {
|
||||
if (this._rfkill.airplaneMode)
|
||||
this._rfkill.airplaneMode = false;
|
||||
else
|
||||
this._client.wireless_enabled = true;
|
||||
}));
|
||||
});
|
||||
airplaneSubStack.add_actor(this._airplaneButton);
|
||||
this._airplaneInactive = new St.Label({ style_class: 'nm-dialog-airplane-text',
|
||||
text: _("Use hardware switch to turn off") });
|
||||
@ -1058,7 +1052,7 @@ var NMWirelessDialog = new Lang.Class({
|
||||
},
|
||||
|
||||
_checkConnections(network, accessPoint) {
|
||||
this._connections.forEach(function(connection) {
|
||||
this._connections.forEach(connection => {
|
||||
if (accessPoint.connection_valid(connection) &&
|
||||
network.connections.indexOf(connection) == -1) {
|
||||
network.connections.push(connection);
|
||||
@ -1084,7 +1078,7 @@ var NMWirelessDialog = new Lang.Class({
|
||||
return;
|
||||
}
|
||||
|
||||
Util.insertSorted(network.accessPoints, accessPoint, function(one, two) {
|
||||
Util.insertSorted(network.accessPoints, accessPoint, (one, two) => {
|
||||
return two.strength - one.strength;
|
||||
});
|
||||
network.item.updateBestAP(network.accessPoints[0]);
|
||||
@ -1137,9 +1131,9 @@ var NMWirelessDialog = new Lang.Class({
|
||||
let scrollValue = adjustment.value;
|
||||
|
||||
this._itemBox.remove_all_children();
|
||||
this._networks.forEach(Lang.bind(this, function(network) {
|
||||
this._networks.forEach(network => {
|
||||
this._itemBox.add_child(network.item.actor);
|
||||
}));
|
||||
});
|
||||
|
||||
adjustment.value = scrollValue;
|
||||
},
|
||||
@ -1158,10 +1152,10 @@ var NMWirelessDialog = new Lang.Class({
|
||||
_createNetworkItem(network) {
|
||||
network.item = new NMWirelessDialogItem(network);
|
||||
network.item.setActive(network == this._selectedNetwork);
|
||||
network.item.connect('selected', Lang.bind(this, function() {
|
||||
network.item.connect('selected', () => {
|
||||
Util.ensureActorVisibleInScrollView(this._scrollView, network.item.actor);
|
||||
this._selectNetwork(network);
|
||||
}));
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@ -1518,12 +1512,12 @@ var NMVpnSection = new Lang.Class({
|
||||
for (let item of connections) {
|
||||
item.setActiveConnection(null);
|
||||
}
|
||||
vpnConnections.forEach(Lang.bind(this, function(a) {
|
||||
vpnConnections.forEach(a => {
|
||||
if (a.connection) {
|
||||
let item = this._connectionItems.get(a.connection.get_uuid());
|
||||
item.setActiveConnection(a);
|
||||
}
|
||||
}));
|
||||
});
|
||||
},
|
||||
|
||||
_makeConnectionItem(connection) {
|
||||
@ -1570,9 +1564,7 @@ var DeviceCategory = new Lang.Class({
|
||||
|
||||
_sync() {
|
||||
let nDevices = this.section.box.get_children().reduce(
|
||||
function(prev, child) {
|
||||
return prev + (child.visible ? 1 : 0);
|
||||
}, 0);
|
||||
(prev, child) => prev + (child.visible ? 1 : 0), 0);
|
||||
this._summaryItem.label.text = this._getSummaryLabel(nDevices);
|
||||
let shouldSummarize = nDevices > MAX_DEVICE_ITEMS;
|
||||
this._summaryItem.actor.visible = shouldSummarize;
|
||||
@ -1700,9 +1692,7 @@ var NMApplet = new Lang.Class({
|
||||
'network-transmit-receive');
|
||||
this._source.policy = new MessageTray.NotificationApplicationPolicy('gnome-network-panel');
|
||||
|
||||
this._source.connect('destroy', Lang.bind(this, function() {
|
||||
this._source = null;
|
||||
}));
|
||||
this._source.connect('destroy', () => { this._source = null; });
|
||||
Main.messageTray.add(this._source);
|
||||
}
|
||||
},
|
||||
@ -1725,7 +1715,7 @@ var NMApplet = new Lang.Class({
|
||||
this._notification = new MessageTray.Notification(this._source, title, text, { gicon: gicon });
|
||||
this._notification.setUrgency(urgency);
|
||||
this._notification.setTransient(true);
|
||||
this._notification.connect('destroy', function() {
|
||||
this._notification.connect('destroy', () => {
|
||||
this._notification = null;
|
||||
});
|
||||
this._source.notify(this._notification);
|
||||
@ -1767,7 +1757,7 @@ var NMApplet = new Lang.Class({
|
||||
this._syncDeviceNames();
|
||||
|
||||
if (wrapper instanceof NMConnectionSection) {
|
||||
this._connections.forEach(function(connection) {
|
||||
this._connections.forEach(connection => {
|
||||
wrapper.checkConnection(connection);
|
||||
});
|
||||
}
|
||||
@ -1854,12 +1844,12 @@ var NMApplet = new Lang.Class({
|
||||
|
||||
_syncVpnConnections() {
|
||||
let activeConnections = this._client.get_active_connections() || [];
|
||||
let vpnConnections = activeConnections.filter(function(a) {
|
||||
return (a instanceof NM.VpnConnection);
|
||||
});
|
||||
vpnConnections.forEach(Lang.bind(this, function(a) {
|
||||
let vpnConnections = activeConnections.filter(
|
||||
a => (a instanceof NM.VpnConnection)
|
||||
);
|
||||
vpnConnections.forEach(a => {
|
||||
ensureActiveConnectionProps(a, this._client);
|
||||
}));
|
||||
});
|
||||
this._vpnSection.setActiveConnections(vpnConnections);
|
||||
|
||||
this._updateIcon();
|
||||
@ -1943,7 +1933,7 @@ var NMApplet = new Lang.Class({
|
||||
this._vpnSection.checkConnection(connection);
|
||||
} else {
|
||||
let devices = this._devices[section].devices;
|
||||
devices.forEach(function(wrapper) {
|
||||
devices.forEach(wrapper => {
|
||||
if (wrapper instanceof NMConnectionSection)
|
||||
wrapper.checkConnection(connection);
|
||||
});
|
||||
@ -1989,13 +1979,13 @@ var NMApplet = new Lang.Class({
|
||||
this._closeConnectivityCheck(path);
|
||||
return;
|
||||
} else if (result == PortalHelperResult.RECHECK) {
|
||||
this._client.check_connectivity_async(null, Lang.bind(this, function(client, result) {
|
||||
this._client.check_connectivity_async(null, (client, result) => {
|
||||
try {
|
||||
let state = client.check_connectivity_finish(result);
|
||||
if (state >= NM.ConnectivityState.FULL)
|
||||
this._closeConnectivityCheck(path);
|
||||
} catch(e) { }
|
||||
}));
|
||||
});
|
||||
} else {
|
||||
log('Invalid result from portal helper: ' + result);
|
||||
}
|
||||
@ -2030,7 +2020,7 @@ var NMApplet = new Lang.Class({
|
||||
this._portalHelperProxy.AuthenticateRemote(path, '', timestamp);
|
||||
} else {
|
||||
new PortalHelperProxy(Gio.DBus.session, 'org.gnome.Shell.PortalHelper',
|
||||
'/org/gnome/Shell/PortalHelper', Lang.bind(this, function (proxy, error) {
|
||||
'/org/gnome/Shell/PortalHelper', (proxy, error) => {
|
||||
if (error) {
|
||||
log('Error launching the portal helper: ' + error);
|
||||
return;
|
||||
@ -2040,7 +2030,7 @@ var NMApplet = new Lang.Class({
|
||||
proxy.connectSignal('Done', Lang.bind(this, this._portalHelperDone));
|
||||
|
||||
proxy.AuthenticateRemote(path, '', timestamp);
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
this._connectivityQueue.push(path);
|
||||
|
Reference in New Issue
Block a user