Last active
October 4, 2021 08:39
-
-
Save VictorAlbertos/dc429d6337e540c996c752085bc73fee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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