Created
October 18, 2019 09:16
-
-
Save nalexn/635f2f30990f065906b6f9cb677539de to your computer and use it in GitHub Desktop.
Article_002 https://nalexn.github.io/mvvm-state-redundancy/
This file contains 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 PodcastsViewModel { | |
private let service: PodcastsService | |
let podcasts = BehaviorRelay<[Podcast]>(value: []) | |
let isLoading = BehaviorRelay<Bool>(value: false) | |
let onError = PublishRelay<Error> = PublishRelay() | |
func loadPodcasts() { | |
isLoading.accept(true) | |
service.loadPodcasts { [weak self] result in | |
self?.isLoading.accept(false) | |
if let error = result.error { | |
self?.onError.accept(error) | |
} | |
let records = result.value ?? [] | |
self?.podcasts.accept(records) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment