Fix getUser binding loops & coro race conditions

This commit is contained in:
miruka
2019-07-07 01:37:13 -04:00
parent 683ee3e1cf
commit be152c3acf
7 changed files with 30 additions and 27 deletions

View File

@@ -7,15 +7,13 @@ HListModel {
var found = getWhere({"userId": user_id}, 1)
if (found.length > 0) { return found[0] }
append({
py.callCoro("request_user_update_event", [user_id])
return {
"userId": user_id,
"displayName": "",
"avatarUrl": "",
"statusMessage": ""
})
py.callCoro("request_user_update_event", [user_id])
return getWhere({"userId": user_id}, 1)[0]
}
}
}

View File

@@ -17,17 +17,17 @@ Python {
}
function callCoro(name, args, kwargs, callback) {
call("APP.call_backend_coro", [name, args, kwargs], function(uuid){
pendingCoroutines[uuid] = callback || function() {}
})
var uuid = Math.random() + "." + name
pendingCoroutines[uuid] = callback || function() {}
call("APP.call_backend_coro", [name, uuid, args, kwargs])
}
function callClientCoro(account_id, name, args, kwargs, callback) {
var args = [account_id, name, args, kwargs]
var uuid = Math.random() + "." + name
call("APP.call_client_coro", args, function(uuid){
pendingCoroutines[uuid] = callback || function() {}
})
pendingCoroutines[uuid] = callback || function() {}
call("APP.call_client_coro", [account_id, name, uuid, args, kwargs])
}
Component.onCompleted: {

View File

@@ -6,9 +6,7 @@ Column {
id: accountDelegate
width: parent.width
// Avoid binding loop by using Component.onCompleted
property var userInfo: null
Component.onCompleted: userInfo = users.getUser(model.userId)
property var userInfo: users.getUser(model.userId)
property bool expanded: true
@@ -19,6 +17,7 @@ Column {
HUserAvatar {
id: avatar
// Need to do this because conflict with the model property
Component.onCompleted: userId = model.userId
}