Last active
May 2, 2023 22:38
-
-
Save tomoima525/39f31d3a14ba8ea2797e22e19021b4ba to your computer and use it in GitHub Desktop.
Observer pattern sample
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
| PublishProcessor<List<Article>> articleList = PublishProcessor.create(); | |
| @Override | |
| public Completable getArticles() { | |
| return remoteDataSource.getArticles() | |
| .flatMapCompletable(articles -> localDataSource | |
| .saveArticles(articles) | |
| .doOnSuccess(articleList::onNext)) | |
| } | |
| public Observable<List<Article>> observeArticles() { | |
| return articleList; | |
| } |
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
| /// ArticleViewModel.java | |
| disposables.addAll( | |
| articleService.getArticles() | |
| .subscribeOn(Schedular.io()) | |
| .subscribe(() -> { }, e -> {}), | |
| articleService.observeArticles() | |
| .toSingle() | |
| .observeOn(Android.mainthread()) | |
| .subscribe(list -> view::bind) | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment