You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class MyCheckBox(cs: CoroutineScope, initialValue: Boolean): JCheckBox() {
private val vm = MutableStateFlow(initialValue) // view model
init {
[email protected] = initialValue
cs.launch {
vm.collectLatest {
[email protected] = it
}
}
}
}
Instead of duplicating the logic, I'd like to write a single lambda, which would react on VM changes. The applying of VM state to the UI could take a while, and can suspend. We have a case, where some loading indication happens, then the final state is shown, but if the state is changed during loading, it should be kept on screen to avoid flickering.
It's currently possible to collect in an undispatched coroutine, if the value is available, then it's applied immediately during construction of the UI component.
But with collectLatest, the block is always dispatched to be executed later.
API-shape
I think this issue should be considered together with #3679 and #3533.
Since collectLatest launches new coroutines, it should accept start and context parameters somehow, and it should accept CoroutineScope lambda to be consistent with launch/async
The text was updated successfully, but these errors were encountered:
Use case
This a contrived example.
Instead of duplicating the logic, I'd like to write a single lambda, which would react on VM changes. The applying of VM state to the UI could take a while, and can suspend. We have a case, where some loading indication happens, then the final state is shown, but if the state is changed during loading, it should be kept on screen to avoid flickering.
It's currently possible to
collect
in an undispatched coroutine, if the value is available, then it's applied immediately during construction of the UI component.But with
collectLatest
, the block is always dispatched to be executed later.API-shape
I think this issue should be considered together with #3679 and #3533.
Since
collectLatest
launches new coroutines, it should acceptstart
andcontext
parameters somehow, and it should acceptCoroutineScope
lambda to be consistent withlaunch
/async
The text was updated successfully, but these errors were encountered: