Skip to content

Instantly share code, notes, and snippets.

@sanogueralorenzo
Last active November 6, 2018 13:43
Show Gist options
  • Save sanogueralorenzo/1ae19de07b9542cd62614ebc68ad1b3e to your computer and use it in GitHub Desktop.
Save sanogueralorenzo/1ae19de07b9542cd62614ebc68ad1b3e to your computer and use it in GitHub Desktop.
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()
}
}
@allidoiswarren
Copy link

Isn't the observeOn() call on line 15 irrelevant since you have subscribeOn() above it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment