Last active
November 6, 2018 13:43
-
-
Save sanogueralorenzo/1ae19de07b9542cd62614ebc68ad1b3e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 PostListViewModel @Inject constructor(private val usersPostsUseCase: UsersPostsUseCase) : | |
ViewModel() { | |
val posts = MutableLiveData<Resource<List<PostItem>>>() | |
private val compositeDisposable = CompositeDisposable() | |
fun get(refresh: Boolean = false) = | |
compositeDisposable.add(usersPostsUseCase.get(refresh) | |
.doOnSubscribe { posts.setLoading() } | |
.subscribeOn(Schedulers.io()) | |
.map { it.mapToPresentation() } | |
.subscribe({ posts.setSuccess(it) }, { posts.setError(it.message) }) | |
) | |
override fun onCleared() { | |
compositeDisposable.dispose() | |
super.onCleared() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Isn't the
observeOn()
call on line 15 irrelevant since you havesubscribeOn()
above it?