I want to observe my network call changes inside my PageKeyedDataSource and Dispose of the RxJava subscription after user quitting a Fragment which leads to Data Source destruction.
class ProjectDataSource : PageKeyedDataSource<Int, ProjectPresenter>(), KoinComponent {
...
override fun loadInitial(
params: LoadInitialParams<Int>,
callback: LoadInitialCallback<Int, ProjectPresenter>
) {
val subscription = mProjectRepository.getProjects(DEFAULT_TAKE, 0)
.subscribe(
{ projectPresenters ->
...
},
{ throwable ->
...
}
)
//Where to dispose `subscription`
}
...
}
I have RxJava subscription in both my Repository and DataSource that both perform different operations on data. A Repository converts a remote model to a presenter model and ...
I'm not really sure it's a good idea to observe data inside DataSource.
I cannot provide any substantial proof my way is "right way" but here is what I think and typically follow in implementation:
onCleared
)loadInitial
and methods alike), I'm routing CompositeDisposable
instance from view model through data source factory.