Что-то простое, например, модель представления, содержащая встречный поток:
Код: Выделить всё
class TestCounter : ViewModel() {
private val _counter = MutableStateFlow(0)
val counter = _counter.asStateFlow()
init {
viewModelScope.launch {
while (true){
delay(1000)
_counter.update {
it + 1
}
}
}
}
}
Код: Выделить всё
@Composable
fun App() {
val testCounter = TestCounter()
val counter = testCounter.counter.collectAsState()
SideEffect {
println("RECOMPOSING EVERY TIME IF PASSING VALUE")
}
DrawCount(counter.value)
// DrawCount(counter)
}
Не имеет значения, стабильно значение или нет.
Подробнее здесь: https://stackoverflow.com/questions/784 ... er-functio