galex
07/07/2023, 12:07 PMBilagi
07/07/2023, 12:09 PMFlow
inside a UI state, especially for paginated results. Using a Flow
in your UI state allows you to handle asynchronous and reactive updates to your data.
When dealing with paginated results, a common approach is to use a Flow
to represent the data stream. As new pages of data are fetched, the Flow
emits updated results, and you can update your UI accordingly. By including the Flow
in your UI state, you can observe it in your UI layer and react to any changes.Bilagi
07/07/2023, 12:10 PMdata class UiState(
val data: Flow<List<Item>>,
val isLoading: Boolean,
val error: Throwable?
)
galex
07/07/2023, 5:01 PMDaniel Weidensdörfer
07/07/2023, 5:34 PMgalex
07/07/2023, 8:34 PMMohsen
07/08/2023, 9:51 PMcopy()
, toString()
, equals()
, etc methods. I wonder how the compiler would react to Flow for comparing or checking its data.
You’re passing a Flow inside a data class, and you shouldn’t. Consider checking MutableStateFlow or StateFlow for that purpose, and use sealed interfaces to pass the UI state to your Composables.
Also, don’t forget about the collectAsStateWithLifecycle()
galex
07/09/2023, 3:38 AMcollectAsStateWithLifecycle()
, but within it, I need paginated results that come from Paging3 directly used into my screen so I can call this function from paging-compose.
While the paginated results do change the data of the UIState stays the same, so I don't need to update the UIState, and it does seems to work!Mohsen
07/09/2023, 3:33 PMMohsen
07/09/2023, 3:34 PMgalex
07/10/2023, 2:30 AMgalex
07/10/2023, 2:38 AMMohsen
07/10/2023, 11:09 AMcollectAsLazyPagingItems()
extension function receives a type of Flow<PagingData<T>>
. You should be able to use another more convenient and reasonable solution for this instead of passing a Flow
inside a Data class in which the parameter is immutable. Flow is mutable.