Coroutines integration
The screenModelScope
and StateScreenModel
are part of the core library.
CoroutineScope
The ScreenModel
provides a screenModelScope
property. It's canceled automatically when the ScreenModel
is disposed.
State-aware ScreenModel
If your ScreenModel
needs to provide a state, use the StateScreenModel
. Set the initial state on the constructor and use mutableState
to change the current state.
In your screen use state.collectAsState()
and handle the current state.
Sample
Sample code here.
Desktop Note
If you are targeting Desktop, you should provide the dependency org.jetbrains.kotlinx:kotlinx-coroutines-swing
, the screenModelScope
depends on Dispatchers.Main
provided by this library on Desktop. We don't include it because this library is incompatible with IntelliJ Plugin, see. If you are targeting Desktop for IntelliJ plugins, this library does not require to be provied.
Last updated