Thank you for the input everyone!
I found using persistent collections from kotlinx fit my pattern best (thanks for the headsup
@Zach Klippenstein (he/him) [MOD]). I'll briefly explain my patterns around state, view model, and composables so you can see how it fits nicely for me -
• I'm collecting state at the top level composable on my screen:
val uiState by myViewModel.collectAsState()
• My view model is supporting a long input form
• My state is held in the ViewModel as a private data class:
val _uiState = MutableStateFlow(MyUiState())
• My state model has many fields that are related to a user recording information for a single report. Something like -
data class MyUiState constructor(
val firstName: String = "",
val lastName: String = "",
val hobbies: PersistentList<String> = persistentListOf()
)
• I'm updating state using MutableStateFlow.update() and copying state to emit new values
fun addHobby(newHobby: String) {
_uiState.update { it.copy(hobbies = it.hobbies.add(newHobby)) }
}