Created
November 15, 2017 04:20
-
-
Save tomoima525/159cfc17a97acf0ba698726f6b67cc41 to your computer and use it in GitHub Desktop.
Storing state
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
| @Override | |
| public Completable getArticles() { | |
| return remoteDataSource.getArticles() | |
| .flatMapCompletable(articles -> localDataSource | |
| .saveArticles(articles); | |
| } | |
| public Observable<List<Article>> observeArticles() { | |
| return localDataSource.observeArticles(); | |
| } |
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
| BehaviorProcessor<List<Article>> articleList = BehaviorProcessor.create(); | |
| LocalDataSource(ArticleDao articleDao) { | |
| this.articleDao = articleDao; | |
| articleDao.subscribeOn(Schedulars.io()).getAll().subscribe(articleList::onNext) | |
| } | |
| public Completable saveArticles(List<Article> article) { | |
| return Completable.fromAction(() -> articleDao.insert(article)) | |
| .doOnSuccess(articleList::onNext); | |
| } | |
| public Observable<List<Article>> observeArticles() { | |
| return articleList; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment