https://kotlinlang.org logo
#mvikotlin
Title
# mvikotlin
f

Francis Mariano

02/28/2023, 6:32 PM
@Arkadii Ivanov the latest version has a new stateflow to observe state. Do you have a sample how we can use it ???
a

Arkadii Ivanov

02/28/2023, 6:34 PM
No, as far as I know. But this should be essentially the same as with usual
state.states
.
f

Francis Mariano

02/28/2023, 6:35 PM
so we do not need use
Value<out T : Any>
anymore
a

Arkadii Ivanov

02/28/2023, 7:02 PM
I mean you can use the new API, or you can continue using Value. MVIKotlin can be used without Decompose. 😀
f

Francis Mariano

02/28/2023, 8:38 PM
ok. I want use the new API together with Decompose.
Copy code
interface ScanComponent {
    val states: Flow<ScanStore.State>
}
Copy code
class ScanComponentImpl {
    override val states: StateFlow<ScanStore.State> = store.stateFlow
}
And in the UI a call
val uistate by component.states.collectAsState(null)
. Everything works like a charm but the collectAsState need for initial state and the
uistate
can be null. The store has an initial state, so it is interesting collectAsState to wait the store emit the first state. Do you have some idea???
a

Arkadii Ivanov

02/28/2023, 8:40 PM
I think you need to use StateFlow in your ScanComponent interface.
f

Francis Mariano

02/28/2023, 8:43 PM
You are right as always
thank you so much
a

Arkadii Ivanov

02/28/2023, 10:20 PM
6 Views