https://kotlinlang.org logo
#squarelibraries
Title
# squarelibraries
j

Javier

02/12/2023, 11:59 AM
Not strictly related to molecule but I got the use case with it Currently in the
LaunchedEffect
we need to operate over flows in the "normal" way, with
collect
or any chain.
Copy code
LaunchedEffect(Unit) {
    events.collect { event ->
        when (event) {
            ...
        }
    }
}
Should be great if I could remove the box there as we do with states
Copy code
LaunchedEffect(Unit) {
    val event by events.collectAsEvent()
    when (event) {
        ...
    }
}
k

kevin.cianfarini

02/12/2023, 2:39 PM
I might be misunderstanding your question, but it seems that your events flow is transient. I don't know why you'd want to collect events as state which is sticky.
j

Javier

02/12/2023, 2:47 PM
I don't want to collect them as State, I want to be able to have the same syntax but for event (
collectAsEvent
) Something so is what I mean
Copy code
// events is `Flow<Event>`

LaunchedEffect(Unit) {
    val eventEffect: Effect<Event> = events.collectAsEffect()
    val event: Event by events.collectAsEffect()
    when (event) {
        ...
    }
}
4 Views