class LoginViewModel : ViewModel() {
val registeredUsers = mutableStateListOf<UIRegisteredUser>()
in the view model
1. Is there way to protect this registeredUsers list from updating the object values from other than view model ? I'm tryting to avoid accidental modification these values from out side view model, trying to keep vm as single source of truth.
a
annsofi
03/21/2022, 12:59 PM
you can use
private set
on it, that way only the LoginViewModel will be allowed to change it.
👍 1
a
Alex Vanyo
03/21/2022, 3:58 PM
If you expose the
mutableStateListOf
from the
ViewModel
as just a normal
List
instead of a
MutableList
, then anything outside of the
ViewModel
won’t be able to change the list.
✅ 1
Alex Vanyo
03/21/2022, 3:59 PM
Whoops, I didn’t read the next thread. Glad to see the same conclusion there 😄 .