Luc Girardin
04/26/2023, 10:01 PMturansky
04/27/2023, 8:09 PMFlow
is fine, 2-3 additional common hooks required to simplify Flow
usageMike Dawson
04/30/2023, 6:05 PMfun <T> Flow<T>.collectAsState(
initialState: T,
): StateInstance<T> {
val state = useState { initialState }
useEffect(dependencies = arrayOf(this)) {
val coroutineScope = CoroutineScope(Dispatchers.Main + Job())
coroutineScope.launch {
this@collectAsState.collect {
state.component2().invoke(it)
}
}
cleanup {
coroutineScope.cancel()
}
}
return state
}
turansky
05/01/2023, 8:20 PMLuc Girardin
05/10/2023, 3:32 PMturansky
05/10/2023, 3:33 PMLuc Girardin
05/10/2023, 3:35 PMturansky
05/10/2023, 3:37 PMfun useAsyncEffect(
vararg dependencies: Any?
block: suspend CoroutineScope.() -> Unit,
)
where it will be possible to create flowsLuc Girardin
05/10/2023, 3:47 PMturansky
05/14/2023, 1:13 PMuseAsyncEffect
implementation is herepre.549
Mike Dawson
05/15/2023, 7:13 AM