cleanup: Use default parameters where appropriate

Since ES6 it is possible to set an explicit default value for optional
parameters (overriding the implicit value of 'undefined'). Use them
for a nice small cleanup.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/626
This commit is contained in:
Florian Müllner 2019-07-12 01:31:38 +02:00 committed by Georges Basile Stavracas Neto
parent 16ca7a21a7
commit 404bc34089
9 changed files with 9 additions and 32 deletions

View File

@ -151,11 +151,7 @@ function getAllProps(obj) {
// e.g., expr="({ foo: null, bar: null, 4: null })" will
// return ["foo", "bar", ...] but the list will not include "4",
// since methods accessed with '.' notation must star with a letter or _.
function getPropertyNamesFromExpression(expr, commandHeader) {
if (commandHeader == null) {
commandHeader = '';
}
function getPropertyNamesFromExpression(expr, commandHeader = '') {
let obj = {};
if (!isUnsafeExpression(expr)) {
try {

View File

@ -1416,7 +1416,7 @@ var AppFolderPopup = class AppFolderPopup {
Signals.addSignalMethods(AppFolderPopup.prototype);
var AppIcon = class AppIcon {
constructor(app, iconParams) {
constructor(app, iconParams = {}) {
this.app = app;
this.id = app.get_id();
this.name = app.get_name();
@ -1442,9 +1442,6 @@ var AppIcon = class AppIcon {
this.actor._delegate = this;
if (!iconParams)
iconParams = {};
// Get the isDraggable property without passing it on to the BaseIcon:
let appIconParams = Params.parse(iconParams, { isDraggable: true }, true);
let isDraggable = appIconParams['isDraggable'];

View File

@ -4,7 +4,7 @@ const { Atk, Clutter, St } = imports.gi;
const Signals = imports.signals;
var BarLevel = class {
constructor(value, params) {
constructor(value, params = {}) {
if (isNaN(value))
// Avoid spreading NaNs around
throw TypeError('The bar level value must be a number');
@ -13,9 +13,6 @@ var BarLevel = class {
this._overdriveStart = 1;
this._barLevelWidth = 0;
if (params == undefined)
params = {};
this.actor = new St.DrawingArea({ styleClass: params['styleClass'] || 'barlevel',
can_focus: params['canFocus'] || false,
reactive: params['reactive'] || false,

View File

@ -122,10 +122,7 @@ var ContentTypeDiscoverer = class {
}
}
_emitCallback(mount, contentTypes) {
if (!contentTypes)
contentTypes = [];
_emitCallback(mount, contentTypes = []) {
// we're not interested in win32 software content types here
contentTypes = contentTypes.filter(
type => (type != 'x-content/win32-software')

View File

@ -841,7 +841,7 @@ var LayoutManager = GObject.registerClass({
// @params can have any of the same values as in addChrome(),
// though some possibilities don't make sense. By default, @actor has
// the same params as its chrome ancestor.
trackChrome(actor, params) {
trackChrome(actor, params = {}) {
let ancestor = actor.get_parent();
let index = this._findActor(ancestor);
while (ancestor && index == -1) {
@ -851,8 +851,6 @@ var LayoutManager = GObject.registerClass({
let ancestorData = ancestor ? this._trackedActors[index]
: defaultParams;
if (!params)
params = {};
// We can't use Params.parse here because we want to drop
// the extra values like ancestorData.actor
for (let prop in defaultParams) {

View File

@ -33,9 +33,7 @@ function _fixMarkup(text, allowMarkup) {
}
var URLHighlighter = class URLHighlighter {
constructor(text, lineWrap, allowMarkup) {
if (!text)
text = '';
constructor(text = '', lineWrap, allowMarkup) {
this.actor = new St.Label({ reactive: true, style_class: 'url-highlighter',
x_expand: true, x_align: Clutter.ActorAlign.START });
this._linkColor = '#ccccff';

View File

@ -473,9 +473,7 @@ var Notification = class Notification {
this.destroy();
}
destroy(reason) {
if (!reason)
reason = NotificationDestroyedReason.DISMISSED;
destroy(reason = NotificationDestroyedReason.DISMISSED) {
this.emit('destroy', reason);
}
};

View File

@ -151,9 +151,7 @@ var OsdWindow = class {
}
}
setMaxLevel(maxLevel) {
if (maxLevel === undefined)
maxLevel = 100;
setMaxLevel(maxLevel = 100) {
this._level.maxLevel = maxLevel;
}

View File

@ -706,9 +706,7 @@ var PanelCorner = class {
var AggregateLayout = GObject.registerClass(
class AggregateLayout extends Clutter.BoxLayout {
_init(params) {
if (!params)
params = {};
_init(params = {}) {
params['orientation'] = Clutter.Orientation.VERTICAL;
super._init(params);