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
@@ -20,18 +20,40 @@
// THE SOFTWARE.
//
import RxSwift
import RxCocoa
public extension GeneralDataLoadingViewModel {
/// Manually update state to result with given value.
///
/// - Parameter newResult: New value to use as result.
func updateResultManually(to newResult: ResultType) {
updateStateManually(to: .result(newResult: newResult, from: .just(newResult)))
}
}
/// Emit elements of ResultType from state observable.
var resultObservable: Observable<ResultType> {
return loadingStateObservable.flatMap { state -> Observable<ResultType> in
switch state {
case .result(let newResult, _):
return .just(newResult)
default:
return .empty()
}
}
}
public extension GeneralDataLoadingViewModel where ResultType: Collection {
convenience init(dataSource: DataSourceType) {
self.init(dataSource: dataSource) { $0.isEmpty }
/// Emit elements of ResultType from state driver.
var resultDriver: Driver<ResultType> {
return loadingStateDriver.flatMap { state -> Driver<ResultType> in
switch state {
case .result(let newResult, _):
return .just(newResult)
default:
return .empty()
}
}
}
}