Skip to content

Instantly share code, notes, and snippets.

@rohitjakhar
Created March 28, 2021 22:42
Show Gist options
  • Save rohitjakhar/b735424f1cd406febe92fc722fc9ce03 to your computer and use it in GitHub Desktop.
Save rohitjakhar/b735424f1cd406febe92fc722fc9ce03 to your computer and use it in GitHub Desktop.
ViewModel
package com.rohitjakhar.blogx.ui.home
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.cachedIn
import com.rohitjakhar.blogx.model.PostData
import com.rohitjakhar.blogx.network.ApiService
import com.rohitjakhar.blogx.repository.PostDataSource
import com.rohitjakhar.blogx.repository.remote.RemoteDataSource
class HomeViewModel() : ViewModel() {
private val remoteData = RemoteDataSource
val listData = Pager(PagingConfig(pageSize = 10)) {
PostDataSource(remoteData)
}.flow.cachedIn(viewModelScope)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment