From 4920ff6212560cfb69f11f1182271350d5f529b3 Mon Sep 17 00:00:00 2001 From: miruka Date: Thu, 18 Jul 2019 03:35:30 -0400 Subject: [PATCH] =?UTF-8?q?ES5=20=E2=86=92=207:=20Use=20function=20default?= =?UTF-8?q?=20parameters?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/qml/Base/HListModel.qml | 33 +++++++++++++------------ src/qml/Chat/SendBox.qml | 2 +- src/qml/Chat/Timeline/EventDelegate.qml | 3 +-- src/qml/Python.qml | 6 ++--- src/qml/UI.qml | 4 +-- src/qml/utils.js | 6 ++--- 6 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/qml/Base/HListModel.qml b/src/qml/Base/HListModel.qml index 9cbea0ea..a5836dbc 100644 --- a/src/qml/Base/HListModel.qml +++ b/src/qml/Base/HListModel.qml @@ -13,13 +13,13 @@ SortFilterProxyModel { property ListModel model: ListModel {} sourceModel: model // Can't assign a "ListModel {}" directly here - function append(dict) { return model.append(dict) } - function clear() { return model.clear() } - function insert(index, dict) { return model.inset(index, dict) } - function move(from, to, n) { return model.move(from, to, n) } - function remove(index, count) { return model.remove(index, count) } - function set(index, dict) { return model.set(index, dict) } - function sync() { return model.sync() } + function append(dict) { return model.append(dict) } + function clear() { return model.clear() } + function insert(index, dict) { return model.inset(index, dict) } + function move(from, to, n=1) { return model.move(from, to, n) } + function remove(index, count=1) { return model.remove(index, count) } + function set(index, dict) { return model.set(index, dict) } + function sync() { return model.sync() } function setProperty(index, prop, value) { return model.setProperty(index, prop, value) } @@ -30,8 +30,8 @@ SortFilterProxyModel { } } - function getIndices(where_roles_are, max_results, max_tries) { - // max arguments: unefined or int + function getIndices(where_roles_are, max_results=null, max_tries=null) { + // max_results, max_tries: null or int var results = [] for (var i = 0; i < model.count; i++) { @@ -59,7 +59,7 @@ SortFilterProxyModel { return results } - function getWhere(roles_are, max_results, max_tries) { + function getWhere(roles_are, max_results=null, max_tries=null) { var indices = getIndices(roles_are, max_results, max_tries) var items = [] @@ -69,14 +69,16 @@ SortFilterProxyModel { return items } - function forEachWhere(roles_are, func, max_results, max_tries) { + function forEachWhere(roles_are, func, max_results=null, max_tries=null) { var items = getWhere(roles_are, max_results, max_tries) for (var i = 0; i < items.length; i++) { func(items[i]) } } - function upsert(where_roles_are, new_item, update_if_exist, max_tries) { + function upsert( + where_roles_are, new_item, update_if_exist=true, max_tries=null + ) { var indices = getIndices(where_roles_are, 1, max_tries) if (indices.length == 0) { @@ -85,7 +87,7 @@ SortFilterProxyModel { } var existing = model.get(indices[0]) - if (update_if_exist == false) { return existing } + if (! update_if_exist) { return existing } // Really update only if existing and new item have a difference for (var role in existing) { @@ -110,7 +112,7 @@ SortFilterProxyModel { return item } - function popWhere(roles_are, max_results, max_tries) { + function popWhere(roles_are, max_results=null, max_tries=null) { var indices = getIndices(roles_are, max_results, max_tries) var items = [] @@ -122,8 +124,7 @@ SortFilterProxyModel { } - function toObject(item_list) { - item_list = item_list || sortFilteredModel + function toObject(item_list=sortFilteredModel) { var obj_list = [] for (var i = 0; i < item_list.count; i++) { diff --git a/src/qml/Chat/SendBox.qml b/src/qml/Chat/SendBox.qml index 45e70b00..b1846ce6 100644 --- a/src/qml/Chat/SendBox.qml +++ b/src/qml/Chat/SendBox.qml @@ -56,7 +56,7 @@ HRectangle { } Component.onCompleted: { - area.Keys.onReturnPressed.connect(function (event) { + area.Keys.onReturnPressed.connect(event => { event.accepted = true if (event.modifiers & Qt.ShiftModifier || diff --git a/src/qml/Chat/Timeline/EventDelegate.qml b/src/qml/Chat/Timeline/EventDelegate.qml index 003fbc66..33184203 100644 --- a/src/qml/Chat/Timeline/EventDelegate.qml +++ b/src/qml/Chat/Timeline/EventDelegate.qml @@ -13,9 +13,8 @@ Column { return Math.round((((date2 - date1) % 86400000) % 3600000) / 60000) } - function getPreviousItem(nth) { + function getPreviousItem(nth=1) { // Remember, index 0 = newest bottomest message - nth = nth || 1 return eventList.model.count - 1 > model.index + nth ? eventList.model.get(model.index + nth) : null } diff --git a/src/qml/Python.qml b/src/qml/Python.qml index 9c90f981..26905407 100644 --- a/src/qml/Python.qml +++ b/src/qml/Python.qml @@ -15,18 +15,18 @@ Python { signal willLoadAccounts(bool will) property bool loadingAccounts: false - function callSync(name, args) { + function callSync(name, args=[]) { return call_sync("APP.backend." + name, args) } - function callCoro(name, args, callback) { + function callCoro(name, args=[], callback=null) { var uuid = Math.random() + "." + name pendingCoroutines[uuid] = callback || function() {} call("APP.call_backend_coro", [name, uuid, args]) } - function callClientCoro(account_id, name, args, callback) { + function callClientCoro(account_id, name, args=[], callback=null) { var uuid = Math.random() + "." + name pendingCoroutines[uuid] = callback || function() {} diff --git a/src/qml/UI.qml b/src/qml/UI.qml index 0b41a6b9..99bdcc6f 100644 --- a/src/qml/UI.qml +++ b/src/qml/UI.qml @@ -59,8 +59,8 @@ Item { StackView { id: pageStack - function showPage(name, properties) { - pageStack.replace("Pages/" + name + ".qml", properties || {}) + function showPage(name, properties={}) { + pageStack.replace("Pages/" + name + ".qml", properties) } function showRoom(userId, category, roomId) { diff --git a/src/qml/utils.js b/src/qml/utils.js index ba4345a0..2e403d95 100644 --- a/src/qml/utils.js +++ b/src/qml/utils.js @@ -3,11 +3,11 @@ function hsl(hue, saturation, lightness) { - return hsla(hue, saturation, lightness, 1.0) + return hsla(hue, saturation, lightness) } -function hsla(hue, saturation, lightness, alpha) { +function hsla(hue, saturation, lightness, alpha=1.0) { // Convert standard hsla(0-360, 1-100, 1-100, 0-1) to Qt format return Qt.hsla(hue / 360, saturation / 100, lightness / 100, alpha) } @@ -57,7 +57,7 @@ function nameColor(name) { } -function coloredNameHtml(name, user_id, display_text) { +function coloredNameHtml(name, user_id, display_text=null) { // substring: remove leading @ return "" + escapeHtml(display_text || name || alt_id) +