Add: configureLayout method to InitializeableView protocol and all implementations.

Update: GeneralDataLoadingViewModel now can handle state changes and result of data source. Previously it was possible only in view controller.
Add: GeneralDataLoadingHandler protocol, that defines methods for common data loading states handling.
Add: resultObservable and resultDriver properties to GeneralDataLoadingViewModel.
Add: hidesWhenStopped option to SpinnerView, so you can stop animation without hiding image inside it.
Update: Migrate to Swift 4.2 & Xcode 10. Update dependencies.
This commit is contained in:
2018-10-01 15:58:15 +03:00
parent 03701b4d82
commit e7eb1bd51f
26 changed files with 275 additions and 141 deletions
@@ -23,7 +23,8 @@
import RxSwift
import RxCocoa
open class GeneralDataLoadingViewModel<ResultType>: BaseViewModel {
/// ViewModel that loads data from given data source with loading state tracking.
open class GeneralDataLoadingViewModel<ResultType>: BaseViewModel, GeneralDataLoadingHandler, DisposeBagHolder {
public typealias LoadingModel = GeneralDataLoadingModel<ResultType>
public typealias DataSourceType = Single<ResultType>
@@ -33,6 +34,8 @@ open class GeneralDataLoadingViewModel<ResultType>: BaseViewModel {
private let loadingStateRelay = BehaviorRelay<LoadingState>(value: .initial)
// MARK: - DisposeBagHolder
public let disposeBag = DisposeBag()
/// Initializer with single result sequence and empty result checker closure.
@@ -53,6 +56,8 @@ open class GeneralDataLoadingViewModel<ResultType>: BaseViewModel {
.drive(loadingStateRelay)
.disposed(by: disposeBag)
bindLoadingState(from: loadingStateDriver)
loadingModel.reload()
}
@@ -106,4 +111,22 @@ open class GeneralDataLoadingViewModel<ResultType>: BaseViewModel {
loadingModel.reload()
}
// MARK: - GeneralDataLoadingHandler
open func onLoadingState() {
// override in subclass
}
open func onResultsState(result: ResultType) {
// override in subclass
}
open func onEmptyState() {
// override in subclass
}
open func onErrorState(error: Error) {
// override in subclass
}
}