mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 14:07:05 +05:30
fix: cache pager flows in ViewModel scope
This commit is contained in:
parent
6cd57b72b7
commit
6b05a2991d
1 changed files with 5 additions and 4 deletions
|
@ -10,6 +10,7 @@ import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import androidx.paging.Pager
|
import androidx.paging.Pager
|
||||||
import androidx.paging.PagingConfig
|
import androidx.paging.PagingConfig
|
||||||
|
import androidx.paging.cachedIn
|
||||||
import com.deliveryhero.whetstone.viewmodel.ContributesViewModel
|
import com.deliveryhero.whetstone.viewmodel.ContributesViewModel
|
||||||
import com.slack.eithernet.ApiResult.Failure
|
import com.slack.eithernet.ApiResult.Failure
|
||||||
import com.slack.eithernet.ApiResult.Success
|
import com.slack.eithernet.ApiResult.Success
|
||||||
|
@ -40,19 +41,19 @@ constructor(
|
||||||
private var hottestPostsPagingSource: LobstersPagingSource? = null
|
private var hottestPostsPagingSource: LobstersPagingSource? = null
|
||||||
private var newestPostsPagingSource: LobstersPagingSource? = null
|
private var newestPostsPagingSource: LobstersPagingSource? = null
|
||||||
private val hottestPostsPager =
|
private val hottestPostsPager =
|
||||||
Pager(PagingConfig(20)) {
|
Pager(PagingConfig(pageSize = 20)) {
|
||||||
pagingSourceFactory.create(api::getHottestPosts).also { hottestPostsPagingSource = it }
|
pagingSourceFactory.create(api::getHottestPosts).also { hottestPostsPagingSource = it }
|
||||||
}
|
}
|
||||||
private val newestPostsPager =
|
private val newestPostsPager =
|
||||||
Pager(PagingConfig(20)) {
|
Pager(PagingConfig(pageSize = 20)) {
|
||||||
pagingSourceFactory.create(api::getHottestPosts).also { newestPostsPagingSource = it }
|
pagingSourceFactory.create(api::getHottestPosts).also { newestPostsPagingSource = it }
|
||||||
}
|
}
|
||||||
|
|
||||||
val hottestPosts
|
val hottestPosts
|
||||||
get() = hottestPostsPager.flow
|
get() = hottestPostsPager.flow.cachedIn(viewModelScope)
|
||||||
|
|
||||||
val newestPosts
|
val newestPosts
|
||||||
get() = newestPostsPager.flow
|
get() = newestPostsPager.flow.cachedIn(viewModelScope)
|
||||||
|
|
||||||
private val savedPostsFlow
|
private val savedPostsFlow
|
||||||
get() = savedPostsRepository.savedPosts
|
get() = savedPostsRepository.savedPosts
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue