Created
September 27, 2017 18:59
-
-
Save piotrbernad/ce9afffe989a39772766c403eef3890c 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
| struct FakeAPI { | |
| static let api = API<FakeAPITarget>() | |
| static func allPosts() -> Observable<[Post]> { | |
| return api.provide(.posts) | |
| } | |
| } | |
| class PostsDataSource { | |
| func reloadData() { | |
| self.state.value = .loading | |
| FakeAPI.allPosts().subscribe { [weak self] (event) in | |
| switch event { | |
| case .next(let posts): | |
| self?.state.value = .loaded(items: posts) | |
| case .error(let error): | |
| self?.state.value = .error(error: error) | |
| default: | |
| break | |
| } | |
| }.disposed(by: disposeBag) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment