ensody / ReactiveState-Kotlin

Easy reactive state management and ViewModels for Kotlin Multiplatform. No boilerplate. Compatible with Android.
https://ensody.github.io/ReactiveState-Kotlin/
Apache License 2.0
38 stars 2 forks source link

Use with Jetpack Compose? #28

Closed t1u1 closed 2 years ago

t1u1 commented 2 years ago

Hi,

I would like to understand how to use this library with Jetpack Compose. IIUC, this library can be used to build Business Logic and ViewModels, and then @Composables can consume the state-flows with .collectAsState().

Is that correct? If so, would .collectAsState() introduce too much additional overhead?

Alternatively, is it possible to create a class that implements both State and StateFlow to avoid code and memory duplication?

thanks!

wkornewald commented 2 years ago

Yes, you can just use collectAsState(). This is the official method to convert a StateFlow, so there shouldn't be any overhead worth discussing.