Skip to content

Instantly share code, notes, and snippets.

@VictorAlbertos
Last active October 4, 2021 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VictorAlbertos/dc429d6337e540c996c752085bc73fee to your computer and use it in GitHub Desktop.
Save VictorAlbertos/dc429d6337e540c996c752085bc73fee to your computer and use it in GitHub Desktop.
class SampleViewModel : ViewModel() {
private val modificationEvents = MutableStateFlow<List<SampleViewEvents>>(emptyList())
// combine them with the data coming from paging
private val combined =
Pager(PagingConfig(pageSize = SampleRepository.PAGE_SIZE)) { SamplePagingSource(SampleRepository()) }.flow
.cachedIn(viewModelScope)
.combine(modificationEvents) { pagingData, modifications ->
modifications.fold(pagingData) { acc, event ->
applyEvents(acc, event)
}
}
val pagingDataViewStates: LiveData<PagingData<SampleEntity>> = combined.asLiveData()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment