Vitor Prado
01/06/2021, 2:01 PMTash
01/06/2021, 10:24 PMVitor Prado
01/06/2021, 10:29 PMSam
01/06/2021, 11:47 PMval communities by remember { store.mutableSubscribedStateOf { it.communities } }
Vitor Prado
01/06/2021, 11:51 PMSam
01/06/2021, 11:53 PMVitor Prado
01/06/2021, 11:54 PMSam
01/06/2021, 11:59 PMSam
01/07/2021, 12:03 AMSam
01/07/2021, 12:04 AMSam
01/07/2021, 12:12 AMLazyColumn
needs a list)
• updating the state tree with Actions
when user performs interactions (which looks like store.dispatch(AccountActions.UpdateUsername(usernameTextFieldState.text))
Vitor Prado
01/07/2021, 12:56 AMVitor Prado
01/07/2021, 1:01 AMval
instead of var
makes it harder to deal with state change?Sam
01/07/2021, 6:42 AMAction
gets reconciled into the existing state to form new state) you will build a new version of the state. The reducers are broken up into manageable chunks too, and kotlin+data classes make the immutable stuff pretty straightforwardSam
01/07/2021, 6:44 AMVitor Prado
01/07/2021, 3:55 PMdata class User(
val admin: Boolean
)
if (user.admin)
Button() // button for admins, open "edit" screen
else
Button() // button for users, open "show" screen
this is a really simple example.. but think about real complex UIs with a lot of validations.. it looks bad and adds complexity to de “view” layer.. and if i delegate it to my viewmodel it looks strage, ’cause my viewmodel deal with “view state” (loading / error / data) .. and this piece of view is rendered when data is loaded, looks like a mixed scenario with async data (view state) and a static data (the data loaded).. and how about testing?! looks like hellSam
01/07/2021, 7:49 PMAdminScreen
. Conversely, if the intention is a user screen with a little bit of admin functionality sprinkled in, then using conditional rendering based on user.admin
doesn’t look bad to me. There are other ways of distributing the logic, depending on your taste:
fun onPressStart() {
var action = if (user.admin) AccountActions.startAdmin() else AccountActions.startUser()
store.dispatch(action)
}
Column {
Button(::onPressStart) { Text(if (user.admin) "Start as Admin" else "Start") }
}