-
I was wondering why you use your own State implementation instead of using MutableStateFlow. Is there any benefit in using your State implementation, as it looks like it's just an observer pattern? As I really like to use flows, I was also asking myself if there is something similar to the Android viewModelScope, a componentScope maybe, that is cancelled when the component is killed. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Hello and thanks for the question.
This is required to avoid direct dependency on Another benefit of using Also please note, that
Since components are lifecycle-aware, you are free to create your own coroutine scope! fun LifecycleOwner.coroutineScope(context: CoroutineContext): CoroutineScope {
val scope = CoroutineScope(context)
lifecycle.doOnDestroy(scope::cancel)
return scope
} And then use it in a component as follows: class SomeComponent(componentContext: ComponentContext): ComponentContext by componentContext {
private val scope = coroutineScope(Dispatchers.Main)
} |
Beta Was this translation helpful? Give feedback.
Hello and thanks for the question.
This is required to avoid direct dependency on
kotlinx.coroutines
. One may prefer another library (e.g. Reaktive or RxJava). Or if Jetpack Compose is used as UI framework, then there isState
and you may not need coroutines as well.Another benefit of using
Value
is better interoperability with Swift.Value
is a normal class with normal functions and callbacks - it can be easily exposed to Swift and subscribed/unsubscribed there.Also please note, that
Value
is directly used only inRouter
. Usually its state is exposed to UI and subscribed without coroutines - e…