Created
September 19, 2021 17:19
-
-
Save fabioCollini/86f76305b5d04927b0f66fe886edc961 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CalculatorViewModel( | |
state: SavedStateHandle, | |
) : ViewModel() { | |
var v1 by state.mutableStateOf("0") | |
var v2 by state.mutableStateOf("0") | |
var result by state.mutableStateOf("0") | |
private set | |
init { | |
snapshotFlow { v1 to v2 } | |
.mapLatest { | |
sum(it.first, it.second) | |
} | |
.onEach { | |
result = it | |
} | |
.launchIn(viewModelScope) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment