joadar
11/22/2021, 5:56 PMprivate val _uiState = MutableStateFlow(DeveloperUiState(isLoading = true, sectionsItems = DeveloperSections()))
val uiState: StateFlow<DeveloperUiState> = _uiState.asStateFlow()
...
_uiState.update {
it.copy(
sectionsItems = it.sectionsItems.copy(
userSection = it.sectionsItems.userSection?.copy(
options = it.sectionsItems.userSection.options.copy(
userPremium = it.sectionsItems.userSection.options.userPremium.copy(
isSelected = isChecked,
summary = if (isChecked) "Yes" else "No"
)
)
)
)
)
}
Is there a way to reduce this path to edit a specific variable from an object?
Thanks for your inputs!Nick Allen
11/22/2021, 6:02 PMjoadar
11/22/2021, 6:12 PMNick Allen
11/22/2021, 6:12 PM_uiState.update {
var state = it
state.sectionsItems.userSection.options.userPremium.isSelected = isChecked
state.sectionsItems.userSection.options.userPremium.summary = if (isChecked) "Yes" else "No"
state
}
No guarantees though and I'm no expert on the proposal so I may be off a bit.joadar
11/22/2021, 6:16 PM