alexhelder
06/20/2025, 1:25 AMFlow<PagingData<T>>
is combined with another flow in the Repository, not the ViewModel. According to the Paging3 docs the combine()
operator should be used with .cachedIn(scope)
where scope is typically a ViewModel scope. I don’t think I should be passing this into the Repository like:
class FileRepository {
fun getPagedFiles(coroutineScope:CoroutineScope, query:Query):Flow<PagingData<DomainType> =
combine(
pager.flow.cachedIn(coroutineScope) // returns Room Entity
anotherFlow,
anotherFlow
) { a,b,c ->
...
}
I can
1. put the transformation in the ViewModel, using its scope, but then have to expose types in the Repository interface (pagingSource is from Room) that ideally should not be exposed (Room entities)
2. use some other scope, not the ViewModel scopemattinger
06/30/2025, 4:00 PMrememberCoroutineScope()
to tie the lifecycle to your composable.mattinger
06/30/2025, 4:02 PMoverride suspend fun monitor(scope: CoroutineScope): StateFlow<StringTable> =
dataStore.data.map {
PreferencesStringTable(it)
}.stateIn(scope)
mattinger
06/30/2025, 4:04 PM