diff --git a/src/controls/Action.qml b/src/controls/Action.qml --- a/src/controls/Action.qml +++ b/src/controls/Action.qml @@ -145,28 +145,14 @@ property list __children onChildrenChanged: { - var child; - for (var i in children) { - child = children[i]; - if (child.hasOwnProperty("parent")) { - child.parent = root - } - } + Array.prototype.filter.call(children, child => child.hasOwnProperty("parent")).forEach(child => child.parent = root) } /** * visibleChildren: list * All child actions that are visible */ readonly property var visibleChildren: { - var visible = []; - var child; - for (var i in children) { - child = children[i]; - if (!child.hasOwnProperty("visible") || child.visible) { - visible.push(child) - } - } - return visible; + return Array.prototype.filter.call(children, child => !child.hasOwnProperty("visible") || child.visible) } } diff --git a/src/controls/CardsLayout.qml b/src/controls/CardsLayout.qml --- a/src/controls/CardsLayout.qml +++ b/src/controls/CardsLayout.qml @@ -71,8 +71,6 @@ Component.onCompleted: childrenChanged() onChildrenChanged: { - for (var i = 0; i < children.length; ++i) { - children[i].Layout.fillHeight = true; - } + Array.prototype.forEach.call(children, child => child.Layout.fillHeight = true) } } diff --git a/src/controls/ContextDrawer.qml b/src/controls/ContextDrawer.qml --- a/src/controls/ContextDrawer.qml +++ b/src/controls/ContextDrawer.qml @@ -132,13 +132,7 @@ } else { // Check if at least one action is visible - var somethingVisible = false; - for (var i=0; i action.visible); if (!somethingVisible) { return null; diff --git a/src/controls/FormLayout.qml b/src/controls/FormLayout.qml --- a/src/controls/FormLayout.qml +++ b/src/controls/FormLayout.qml @@ -81,20 +81,10 @@ property var knownItems: [] property var buddies: [] property int knownItemsImplicitWidth: { - var hint = 0; - for (var i in knownItems) { - hint = Math.max(hint, knownItems[i].Layout.preferredWidth > 0 ? knownItems[i].Layout.preferredWidth : knownItems[i].implicitWidth); - } - return hint; + return knownItems.reduce((item, widthAccumulator) => Math.max(widthAccumulator, item.Layout.preferredWidth > 0 ? item.Layout.preferredWidth : item.implicitWidth)); } property int buddiesImplicitWidth: { - var hint = 0; - for (var i in buddies) { - if (buddies[i].visible) { - hint = Math.max(hint, buddies[i].implicitWidth); - } - } - return hint; + return buddies.filter(buddy => buddy.visible).reduce((buddy, widthAccumulator) => Math.max(widthAccumulator, buddy.implicitWidth)); } states: [ State { @@ -147,18 +137,14 @@ Item { Layout.preferredWidth: { var hint = 1; - for (var i in root.twinFormLayouts) { - hint = Math.max(hint, root.twinFormLayouts[i].children[0].buddiesImplicitWidth); - } + root.twinFormLayouts.forEach(item => hint = Math.max(hint, item.children[0].buddiesImplicitWidth)); return hint; } } Item { Layout.preferredWidth: { var hint = 1; - for (var i in root.twinFormLayouts) { - hint = Math.max(hint, root.twinFormLayouts[i].children[0].knownItemsImplicitWidth); - } + root.twinFormLayouts.forEach(item => hint = Math.max(hint, item.children[0].knownItemsImplicitWidth)); return hint; } } diff --git a/src/controls/templates/SwipeListItem.qml b/src/controls/templates/SwipeListItem.qml --- a/src/controls/templates/SwipeListItem.qml +++ b/src/controls/templates/SwipeListItem.qml @@ -418,15 +418,7 @@ if (definitelyVisible) { hasVisibleActions = true; } else { - var actionCount = listItem.actions.length; - for (var i = 0; i < actionCount; i++) { - // Assuming that visible is only false if it is explicitly false, and not just falsy - if (listItem.actions[i].visible === false) { - continue; - } - hasVisibleActions = true; - break; - } + hasVisibleActions = listItem.actions.some(action => action.visible); } } diff --git a/src/controls/templates/private/PassiveNotification.qml b/src/controls/templates/private/PassiveNotification.qml --- a/src/controls/templates/private/PassiveNotification.qml +++ b/src/controls/templates/private/PassiveNotification.qml @@ -59,9 +59,8 @@ open(); - for (let i = 0; i < outerLayout.children.length - 3; ++i) { - outerLayout.children[i].close(); - } + // Skip the last three elements of this array. + outerLayout.children.slice(0, -3).forEach(child => child.close()); let delegate = delegateComponent.createObject(outerLayout, { "text": message, @@ -71,10 +70,9 @@ }); // Reorder items to have the last on top - let children = outerLayout.children; - for (let i in children) { - children[i].Layout.row = children.length-1-i; - } + outerLayout.children.forEach((value, index) => { + value.Layout.row = outerLayout.children.length-1-index; + }); } Kirigami.Theme.colorSet: Kirigami.Theme.Complementary