Let's say I have a Database with User and it is en...
# compose-desktop
y
Let's say I have a Database with User and it is encapsulated in a UserMgr layer (ex:
UserMgr.getUsers(userFilter) -> List<User>, UserMgr.removeUser(userID)
). I want to display this list of users and offer the ability to remove any item from the list (with the click of a button). I am not entirely sure how to handle this use case with compose-desktop. If I use
Copy code
val userFilter = xxx
val users = remember { userMgr.getUsers(userFilter) }

// ...
// for each user
val id = ...
Button(onClick = { userMgr.delete(id) } // ...
// ...
Then of course it does not get recomposed because there is no way for the framework to know that the list has changed... I apologize if this question has been asked before. Can somebody point me to the recommended way to handle a compose-dekstop application backed by a database with essentially screens that implement CRUD access to it?
t
I'd create a
ViewModel
layer between
View
and
Data
source and I'd store the
users
in a
StateFlow
(inside
ViewModel
). Then on each
create/update/delete
, I'd also update the
users
list. on the view layer, I'd use
collectAsState
(inside
@Composable
function)
r
Easy way if you're not worried about threading: make
users
a StateList (or whatever the real version is called) and remove the removed user from it.