Lilly
04/21/2022, 10:29 AMfun someFunction(): Flow<Pair<Int, SomeStateType>>
Would you
1. define a data class and create a new object on every change (this might happen 100x). Disadvantage: object creation on every change, advantage: state is coupled to its function
2. expose 2 observable StateFlows
. Disadvantage: pollutes interface API, advantage: no object creation on every change
Is there any guidance about this or is this an issue of preference?Javier
04/21/2022, 11:20 AMColton Idle
04/21/2022, 12:04 PMAdam Powell
04/21/2022, 2:19 PMLilly
04/21/2022, 3:05 PMfun someFunction(): Flow<Pair<Int, SomeStateType>> = flow {
emit(SomeStateType.LOADING)
repeat(100) { i ->
emit(i)
}
emit(SomeStateType.COMPLETE)
}
or
val intValue: MutableStateFlow<Int> // has to be a Channel
val valueState: MutableStateFlow<SomeStateType>
fun someFunction(): Unit {
valueState.value = SomeStateType.LOADING
repeat(100) { i ->
intValue.value = i
}
}
ok while writing this sample I noticed two things:
1. in the latter case I would have to define a hot Channel
to ensure my int values are not conflated.
2. I could let the caller decide when operation is done and introduce SomeStateType there. Then I just need fun someFunction(): Flow<Int>
Sometimes just writing about the problem helps to make it more clear .Javier
04/21/2022, 3:13 PMLilly
04/21/2022, 3:18 PMErick Sumargo
04/21/2022, 5:14 PMLilly
04/21/2022, 8:28 PM