ES5 → 7: Use function default parameters
This commit is contained in:
parent
8f53d2e018
commit
4920ff6212
|
@ -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++) {
|
||||
|
|
|
@ -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 ||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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() {}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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 "<font color='" + nameColor(name || alt_id.substring(1)) + "'>" +
|
||||
escapeHtml(display_text || name || alt_id) +
|
||||
|
|
Loading…
Reference in New Issue
Block a user