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
@ -126,7 +126,7 @@ var IBusManager = new Lang.Class({
|
||||
} catch (e) {
|
||||
}
|
||||
// If an engine is already active we need to get its properties
|
||||
this._ibus.get_global_engine_async(-1, null, Lang.bind(this, function(i, result) {
|
||||
this._ibus.get_global_engine_async(-1, null, (i, result) => {
|
||||
let engine;
|
||||
try {
|
||||
engine = this._ibus.get_global_engine_async_finish(result);
|
||||
@ -136,7 +136,7 @@ var IBusManager = new Lang.Class({
|
||||
return;
|
||||
}
|
||||
this._engineChanged(this._ibus, engine.get_name());
|
||||
}));
|
||||
});
|
||||
this._updateReadiness();
|
||||
} else {
|
||||
this._clear();
|
||||
@ -159,7 +159,7 @@ var IBusManager = new Lang.Class({
|
||||
return;
|
||||
|
||||
this._registerPropertiesId =
|
||||
this._panelService.connect('register-properties', Lang.bind(this, function(p, props) {
|
||||
this._panelService.connect('register-properties', (p, props) => {
|
||||
if (!props.get(0))
|
||||
return;
|
||||
|
||||
@ -167,7 +167,7 @@ var IBusManager = new Lang.Class({
|
||||
this._registerPropertiesId = 0;
|
||||
|
||||
this.emit('properties-registered', this._currentEngineName, props);
|
||||
}));
|
||||
});
|
||||
},
|
||||
|
||||
_updateProperty(panel, prop) {
|
||||
@ -214,7 +214,7 @@ var IBusManager = new Lang.Class({
|
||||
|
||||
this._preloadEnginesId =
|
||||
Mainloop.timeout_add_seconds(this._PRELOAD_ENGINES_DELAY_TIME,
|
||||
Lang.bind(this, function() {
|
||||
() => {
|
||||
this._ibus.preload_engines_async(
|
||||
ids,
|
||||
-1,
|
||||
@ -222,7 +222,7 @@ var IBusManager = new Lang.Class({
|
||||
null);
|
||||
this._preloadEnginesId = 0;
|
||||
return GLib.SOURCE_REMOVE;
|
||||
}));
|
||||
});
|
||||
},
|
||||
});
|
||||
Signals.addSignalMethods(IBusManager.prototype);
|
||||
|
@ -59,8 +59,8 @@ var InputMethod = new Lang.Class({
|
||||
|
||||
_setContext(bus, res) {
|
||||
this._context = this._ibus.create_input_context_async_finish(res);
|
||||
this._context.connect('enabled', Lang.bind(this, function () { this._enabled = true }));
|
||||
this._context.connect('disabled', Lang.bind(this, function () { this._enabled = false }));
|
||||
this._context.connect('enabled', () => { this._enabled = true });
|
||||
this._context.connect('disabled', () => { this._enabled = false });
|
||||
this._context.connect('commit-text', Lang.bind(this, this._onCommitText));
|
||||
this._context.connect('delete-surrounding-text', Lang.bind(this, this._onDeleteSurroundingText));
|
||||
this._context.connect('update-preedit-text', Lang.bind(this, this._onUpdatePreeditText));
|
||||
@ -201,14 +201,14 @@ var InputMethod = new Lang.Class({
|
||||
this._context.process_key_event_async(event.get_key_symbol(),
|
||||
event.get_key_code() - 8, // Convert XKB keycodes to evcodes
|
||||
state, -1, null,
|
||||
Lang.bind(this, (context, res) => {
|
||||
(context, res) => {
|
||||
try {
|
||||
let retval = context.process_key_event_async_finish(res);
|
||||
this.notify_key_event(event, retval);
|
||||
} catch (e) {
|
||||
log('Error processing key on IM: ' + e.message);
|
||||
}
|
||||
}));
|
||||
});
|
||||
return true;
|
||||
},
|
||||
});
|
||||
|
@ -23,9 +23,9 @@ function getCompletions(text, commandHeader, globalCompletionList) {
|
||||
if (matches) {
|
||||
[expr, base, attrHead] = matches;
|
||||
|
||||
methods = getPropertyNamesFromExpression(base, commandHeader).filter(function(attr) {
|
||||
return attr.slice(0, attrHead.length) == attrHead;
|
||||
});
|
||||
methods = getPropertyNamesFromExpression(base, commandHeader).filter(
|
||||
attr => attr.slice(0, attrHead.length) == attrHead
|
||||
);
|
||||
}
|
||||
|
||||
// Look for the empty expression or partially entered words
|
||||
@ -33,9 +33,9 @@ function getCompletions(text, commandHeader, globalCompletionList) {
|
||||
matches = text.match(/^(\w*)$/);
|
||||
if (text == '' || matches) {
|
||||
[expr, attrHead] = matches;
|
||||
methods = globalCompletionList.filter(function(attr) {
|
||||
return attr.slice(0, attrHead.length) == attrHead;
|
||||
});
|
||||
methods = globalCompletionList.filter(
|
||||
attr => attr.slice(0, attrHead.length) == attrHead
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -175,7 +175,7 @@ function getPropertyNamesFromExpression(expr, commandHeader) {
|
||||
|
||||
// Make sure propsUnique contains one key for every
|
||||
// property so we end up with a unique list of properties
|
||||
allProps.map(function(p){ propsUnique[p] = null; });
|
||||
allProps.map(p => propsUnique[p] = null);
|
||||
}
|
||||
return Object.keys(propsUnique).sort();
|
||||
}
|
||||
@ -233,7 +233,7 @@ function isUnsafeExpression(str) {
|
||||
// Returns a list of global keywords derived from str
|
||||
function getDeclaredConstants(str) {
|
||||
let ret = [];
|
||||
str.split(';').forEach(function(s) {
|
||||
str.split(';').forEach(s => {
|
||||
let base, keyword;
|
||||
let match = s.match(/const\s+(\w+)\s*=/);
|
||||
if (match) {
|
||||
|
@ -138,8 +138,8 @@ var KeyboardManager = new Lang.Class({
|
||||
|
||||
_buildGroupStrings(_group) {
|
||||
let group = _group.concat(this._localeLayoutInfo);
|
||||
let layouts = group.map(function(g) { return g.layout; }).join(',');
|
||||
let variants = group.map(function(g) { return g.variant; }).join(',');
|
||||
let layouts = group.map(g => g.layout).join(',');
|
||||
let variants = group.map(g => g.variant).join(',');
|
||||
return [layouts, variants];
|
||||
},
|
||||
|
||||
|
@ -125,21 +125,20 @@ var LoginManagerSystemd = new Lang.Class({
|
||||
return;
|
||||
}
|
||||
|
||||
this._proxy.GetSessionRemote(sessionId, Lang.bind(this,
|
||||
function(result, error) {
|
||||
if (error) {
|
||||
logError(error, 'Could not get a proxy for the current session');
|
||||
} else {
|
||||
this._currentSession = new SystemdLoginSession(Gio.DBus.system,
|
||||
'org.freedesktop.login1',
|
||||
result[0]);
|
||||
callback(this._currentSession);
|
||||
}
|
||||
}));
|
||||
this._proxy.GetSessionRemote(sessionId, (result, error) => {
|
||||
if (error) {
|
||||
logError(error, 'Could not get a proxy for the current session');
|
||||
} else {
|
||||
this._currentSession = new SystemdLoginSession(Gio.DBus.system,
|
||||
'org.freedesktop.login1',
|
||||
result[0]);
|
||||
callback(this._currentSession);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
canSuspend(asyncCallback) {
|
||||
this._proxy.CanSuspendRemote(function(result, error) {
|
||||
this._proxy.CanSuspendRemote((result, error) => {
|
||||
if (error) {
|
||||
asyncCallback(false, false);
|
||||
} else {
|
||||
@ -151,7 +150,7 @@ var LoginManagerSystemd = new Lang.Class({
|
||||
},
|
||||
|
||||
listSessions(asyncCallback) {
|
||||
this._proxy.ListSessionsRemote(function(result, error) {
|
||||
this._proxy.ListSessionsRemote((result, error) => {
|
||||
if (error)
|
||||
asyncCallback([]);
|
||||
else
|
||||
@ -170,7 +169,7 @@ var LoginManagerSystemd = new Lang.Class({
|
||||
reason,
|
||||
'delay']);
|
||||
this._proxy.call_with_unix_fd_list('Inhibit', inVariant, 0, -1, null, null,
|
||||
Lang.bind(this, function(proxy, result) {
|
||||
(proxy, result) => {
|
||||
let fd = -1;
|
||||
try {
|
||||
let [outVariant, fdList] = proxy.call_with_unix_fd_list_finish(result);
|
||||
@ -180,7 +179,7 @@ var LoginManagerSystemd = new Lang.Class({
|
||||
logError(e, "Error getting systemd inhibitor");
|
||||
callback(null);
|
||||
}
|
||||
}));
|
||||
});
|
||||
},
|
||||
|
||||
_prepareForSleep(proxy, sender, [aboutToSuspend]) {
|
||||
|
@ -140,15 +140,15 @@ var ModemGsm = new Lang.Class({
|
||||
this.operator_name = null;
|
||||
|
||||
// Code is duplicated because the function have different signatures
|
||||
this._proxy.connectSignal('SignalQuality', Lang.bind(this, function(proxy, sender, [quality]) {
|
||||
this._proxy.connectSignal('SignalQuality', (proxy, sender, [quality]) => {
|
||||
this.signal_quality = quality;
|
||||
this.emit('notify::signal-quality');
|
||||
}));
|
||||
this._proxy.connectSignal('RegistrationInfo', Lang.bind(this, function(proxy, sender, [status, code, name]) {
|
||||
});
|
||||
this._proxy.connectSignal('RegistrationInfo', (proxy, sender, [status, code, name]) => {
|
||||
this.operator_name = _findProviderForMccMnc(name, code);
|
||||
this.emit('notify::operator-name');
|
||||
}));
|
||||
this._proxy.GetRegistrationInfoRemote(Lang.bind(this, function([result], err) {
|
||||
});
|
||||
this._proxy.GetRegistrationInfoRemote(([result], err) => {
|
||||
if (err) {
|
||||
log(err);
|
||||
return;
|
||||
@ -157,8 +157,8 @@ var ModemGsm = new Lang.Class({
|
||||
let [status, code, name] = result;
|
||||
this.operator_name = _findProviderForMccMnc(name, code);
|
||||
this.emit('notify::operator-name');
|
||||
}));
|
||||
this._proxy.GetSignalQualityRemote(Lang.bind(this, function(result, err) {
|
||||
});
|
||||
this._proxy.GetSignalQualityRemote((result, err) => {
|
||||
if (err) {
|
||||
// it will return an error if the device is not connected
|
||||
this.signal_quality = 0;
|
||||
@ -167,7 +167,7 @@ var ModemGsm = new Lang.Class({
|
||||
this.signal_quality = quality;
|
||||
}
|
||||
this.emit('notify::signal-quality');
|
||||
}));
|
||||
});
|
||||
}
|
||||
});
|
||||
Signals.addSignalMethods(ModemGsm.prototype);
|
||||
@ -180,7 +180,7 @@ var ModemCdma = new Lang.Class({
|
||||
|
||||
this.signal_quality = 0;
|
||||
this.operator_name = null;
|
||||
this._proxy.connectSignal('SignalQuality', Lang.bind(this, function(proxy, sender, params) {
|
||||
this._proxy.connectSignal('SignalQuality', (proxy, sender, params) => {
|
||||
this.signal_quality = params[0];
|
||||
this.emit('notify::signal-quality');
|
||||
|
||||
@ -188,8 +188,8 @@ var ModemCdma = new Lang.Class({
|
||||
// and we can finally call GetServingSystem
|
||||
if (this.operator_name == null)
|
||||
this._refreshServingSystem();
|
||||
}));
|
||||
this._proxy.GetSignalQualityRemote(Lang.bind(this, function(result, err) {
|
||||
});
|
||||
this._proxy.GetSignalQualityRemote((result, err) => {
|
||||
if (err) {
|
||||
// it will return an error if the device is not connected
|
||||
this.signal_quality = 0;
|
||||
@ -198,11 +198,11 @@ var ModemCdma = new Lang.Class({
|
||||
this.signal_quality = quality;
|
||||
}
|
||||
this.emit('notify::signal-quality');
|
||||
}));
|
||||
});
|
||||
},
|
||||
|
||||
_refreshServingSystem() {
|
||||
this._proxy.GetServingSystemRemote(Lang.bind(this, function([result], err) {
|
||||
this._proxy.GetServingSystemRemote(([result], err) => {
|
||||
if (err) {
|
||||
// it will return an error if the device is not connected
|
||||
this.operator_name = null;
|
||||
@ -212,7 +212,7 @@ var ModemCdma = new Lang.Class({
|
||||
this.operator_name = _findProviderForSid(sid)
|
||||
}
|
||||
this.emit('notify::operator-name');
|
||||
}));
|
||||
});
|
||||
}
|
||||
});
|
||||
Signals.addSignalMethods(ModemCdma.prototype);
|
||||
@ -253,24 +253,24 @@ var BroadbandModem = new Lang.Class({
|
||||
this._proxy_cdma = new BroadbandModemCdmaProxy(Gio.DBus.system, 'org.freedesktop.ModemManager1', path);
|
||||
this._capabilities = capabilities;
|
||||
|
||||
this._proxy.connect('g-properties-changed', Lang.bind(this, function(proxy, properties) {
|
||||
this._proxy.connect('g-properties-changed', (proxy, properties) => {
|
||||
if ('SignalQuality' in properties.deep_unpack())
|
||||
this._reloadSignalQuality();
|
||||
}));
|
||||
});
|
||||
this._reloadSignalQuality();
|
||||
|
||||
this._proxy_3gpp.connect('g-properties-changed', Lang.bind(this, function(proxy, properties) {
|
||||
this._proxy_3gpp.connect('g-properties-changed', (proxy, properties) => {
|
||||
let unpacked = properties.deep_unpack();
|
||||
if ('OperatorName' in unpacked || 'OperatorCode' in unpacked)
|
||||
this._reload3gppOperatorName();
|
||||
}));
|
||||
});
|
||||
this._reload3gppOperatorName();
|
||||
|
||||
this._proxy_cdma.connect('g-properties-changed', Lang.bind(this, function(proxy, properties) {
|
||||
this._proxy_cdma.connect('g-properties-changed', (proxy, properties) => {
|
||||
let unpacked = properties.deep_unpack();
|
||||
if ('Nid' in unpacked || 'Sid' in unpacked)
|
||||
this._reloadCdmaOperatorName();
|
||||
}));
|
||||
});
|
||||
this._reloadCdmaOperatorName();
|
||||
},
|
||||
|
||||
|
@ -93,7 +93,7 @@ var ObjectManager = new Lang.Class({
|
||||
|
||||
proxy.init_async(GLib.PRIORITY_DEFAULT,
|
||||
this._cancellable,
|
||||
Lang.bind(this, function(initable, result) {
|
||||
(initable, result) => {
|
||||
let error = null;
|
||||
try {
|
||||
initable.init_finish(result);
|
||||
@ -127,7 +127,7 @@ var ObjectManager = new Lang.Class({
|
||||
|
||||
if (onFinished)
|
||||
onFinished();
|
||||
}));
|
||||
});
|
||||
},
|
||||
|
||||
_removeInterface(objectPath, interfaceName) {
|
||||
@ -168,35 +168,35 @@ var ObjectManager = new Lang.Class({
|
||||
}
|
||||
|
||||
this._managerProxy.connectSignal('InterfacesAdded',
|
||||
Lang.bind(this, function(objectManager, sender, [objectPath, interfaces]) {
|
||||
(objectManager, sender, [objectPath, interfaces]) => {
|
||||
let interfaceNames = Object.keys(interfaces);
|
||||
for (let i = 0; i < interfaceNames.length; i++)
|
||||
this._addInterface(objectPath, interfaceNames[i]);
|
||||
}));
|
||||
});
|
||||
this._managerProxy.connectSignal('InterfacesRemoved',
|
||||
Lang.bind(this, function(objectManager, sender, [objectPath, interfaceNames]) {
|
||||
(objectManager, sender, [objectPath, interfaceNames]) => {
|
||||
for (let i = 0; i < interfaceNames.length; i++)
|
||||
this._removeInterface(objectPath, interfaceNames[i]);
|
||||
}));
|
||||
});
|
||||
|
||||
if (Object.keys(this._interfaceInfos).length == 0) {
|
||||
this._tryToCompleteLoad();
|
||||
return;
|
||||
}
|
||||
|
||||
this._managerProxy.connect('notify::g-name-owner', Lang.bind(this, function() {
|
||||
this._managerProxy.connect('notify::g-name-owner', () => {
|
||||
if (this._managerProxy.g_name_owner)
|
||||
this._onNameAppeared();
|
||||
else
|
||||
this._onNameVanished();
|
||||
}));
|
||||
});
|
||||
|
||||
if (this._managerProxy.g_name_owner)
|
||||
this._onNameAppeared();
|
||||
},
|
||||
|
||||
_onNameAppeared() {
|
||||
this._managerProxy.GetManagedObjectsRemote(Lang.bind(this, function(result, error) {
|
||||
this._managerProxy.GetManagedObjectsRemote((result, error) => {
|
||||
if (!result) {
|
||||
if (error) {
|
||||
logError(error, 'could not get remote objects for service ' + this._serviceName + ' path ' + this._managerPath);
|
||||
@ -230,7 +230,7 @@ var ObjectManager = new Lang.Class({
|
||||
}
|
||||
}
|
||||
this._tryToCompleteLoad();
|
||||
}));
|
||||
});
|
||||
},
|
||||
|
||||
_onNameVanished() {
|
||||
|
@ -43,15 +43,15 @@ var SmartcardManager = new Lang.Class({
|
||||
for (let i = 0; i < tokens.length; i++)
|
||||
this._addToken(tokens[i]);
|
||||
|
||||
this._objectManager.connect('interface-added', Lang.bind(this, function(objectManager, interfaceName, proxy) {
|
||||
this._objectManager.connect('interface-added', (objectManager, interfaceName, proxy) => {
|
||||
if (interfaceName == 'org.gnome.SettingsDaemon.Smartcard.Token')
|
||||
this._addToken(proxy);
|
||||
}));
|
||||
});
|
||||
|
||||
this._objectManager.connect('interface-removed', Lang.bind(this, function(objectManager, interfaceName, proxy) {
|
||||
this._objectManager.connect('interface-removed', (objectManager, interfaceName, proxy) => {
|
||||
if (interfaceName == 'org.gnome.SettingsDaemon.Smartcard.Token')
|
||||
this._removeToken(proxy);
|
||||
}));
|
||||
});
|
||||
},
|
||||
|
||||
_updateToken(token) {
|
||||
@ -69,18 +69,17 @@ var SmartcardManager = new Lang.Class({
|
||||
_addToken(token) {
|
||||
this._updateToken(token);
|
||||
|
||||
token.connect('g-properties-changed',
|
||||
Lang.bind(this, function(proxy, properties) {
|
||||
if ('IsInserted' in properties.deep_unpack()) {
|
||||
this._updateToken(token);
|
||||
token.connect('g-properties-changed', (proxy, properties) => {
|
||||
if ('IsInserted' in properties.deep_unpack()) {
|
||||
this._updateToken(token);
|
||||
|
||||
if (token.IsInserted) {
|
||||
this.emit('smartcard-inserted', token);
|
||||
} else {
|
||||
this.emit('smartcard-removed', token);
|
||||
}
|
||||
}
|
||||
}));
|
||||
if (token.IsInserted) {
|
||||
this.emit('smartcard-inserted', token);
|
||||
} else {
|
||||
this.emit('smartcard-removed', token);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Emit a smartcard-inserted at startup if it's already plugged in
|
||||
if (token.IsInserted)
|
||||
|
@ -410,7 +410,7 @@ const SystemActions = new Lang.Class({
|
||||
if (Main.screenShield)
|
||||
Main.screenShield.lock(false);
|
||||
|
||||
Clutter.threads_add_repaint_func_full(Clutter.RepaintFlags.POST_PAINT, function() {
|
||||
Clutter.threads_add_repaint_func_full(Clutter.RepaintFlags.POST_PAINT, () => {
|
||||
Gdm.goto_login_session_sync(null);
|
||||
return false;
|
||||
});
|
||||
|
@ -136,7 +136,7 @@ function trySpawn(argv)
|
||||
// Dummy child watch; we don't want to double-fork internally
|
||||
// because then we lose the parent-child relationship, which
|
||||
// can break polkit. See https://bugzilla.redhat.com//show_bug.cgi?id=819275
|
||||
GLib.child_watch_add(GLib.PRIORITY_DEFAULT, pid, function () {});
|
||||
GLib.child_watch_add(GLib.PRIORITY_DEFAULT, pid, () => {});
|
||||
}
|
||||
|
||||
// trySpawnCommandLine:
|
||||
@ -291,12 +291,10 @@ function createTimeLabel(date, params) {
|
||||
_desktopSettings = new Gio.Settings({ schema_id: 'org.gnome.desktop.interface' });
|
||||
|
||||
let label = new St.Label({ text: formatTime(date, params) });
|
||||
let id = _desktopSettings.connect('changed::clock-format', function() {
|
||||
let id = _desktopSettings.connect('changed::clock-format', () => {
|
||||
label.text = formatTime(date, params);
|
||||
});
|
||||
label.connect('destroy', function() {
|
||||
_desktopSettings.disconnect(id);
|
||||
});
|
||||
label.connect('destroy', () => { _desktopSettings.disconnect(id); });
|
||||
return label;
|
||||
}
|
||||
|
||||
@ -316,7 +314,7 @@ function createTimeLabel(date, params) {
|
||||
|
||||
function lowerBound(array, val, cmp) {
|
||||
let min, max, mid, v;
|
||||
cmp = cmp || function(a, b) { return a - b; };
|
||||
cmp = cmp || ((a, b) => a - b);
|
||||
|
||||
if (array.length == 0)
|
||||
return 0;
|
||||
|
Reference in New Issue
Block a user