From f44393c1d8236c8b2ee0bb6342c9d06b99a835e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Garci=CC=81a?= Date: Sun, 15 May 2016 15:23:08 +0200 Subject: [PATCH] More comprensible `ActivityIndicator` --- .../Services/ActivityIndicator.swift | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/RxExample/RxExample/Services/ActivityIndicator.swift b/RxExample/RxExample/Services/ActivityIndicator.swift index 9f69a16f4..807359ca4 100644 --- a/RxExample/RxExample/Services/ActivityIndicator.swift +++ b/RxExample/RxExample/Services/ActivityIndicator.swift @@ -12,7 +12,7 @@ import RxSwift import RxCocoa #endif -struct ActivityToken : ObservableConvertibleType, Disposable { +private struct ActivityToken : ObservableConvertibleType, Disposable { private let _source: Observable private let _dispose: AnonymousDisposable @@ -36,26 +36,26 @@ Enables monitoring of sequence computation. If there is at least one sequence computation in progress, `true` will be sent. When all activities complete `false` will be sent. */ -class ActivityIndicator : DriverConvertibleType { - typealias E = Bool +public class ActivityIndicator : DriverConvertibleType { + public typealias E = Bool private let _lock = NSRecursiveLock() private let _variable = Variable(0) private let _loading: Driver - init() { + public init() { _loading = _variable.asObservable() .map { $0 > 0 } .distinctUntilChanged() .asDriver(onErrorRecover: ActivityIndicator.ifItStillErrors) } - static func ifItStillErrors(error: ErrorType) -> Driver { + private static func ifItStillErrors(error: ErrorType) -> Driver { _ = fatalError("Loader can't fail") } - func trackActivity(source: O) -> Observable { + private func trackActivityOfObservable(source: O) -> Observable { return Observable.using({ () -> ActivityToken in self.increment() return ActivityToken(source: source.asObservable(), disposeAction: self.decrement) @@ -76,13 +76,13 @@ class ActivityIndicator : DriverConvertibleType { _lock.unlock() } - func asDriver() -> Driver { + public func asDriver() -> Driver { return _loading } } -extension ObservableConvertibleType { - func trackActivity(activityIndicator: ActivityIndicator) -> Observable { - return activityIndicator.trackActivity(self) +public extension ObservableConvertibleType { + public func trackActivity(activityIndicator: ActivityIndicator) -> Observable { + return activityIndicator.trackActivityOfObservable(self) } } \ No newline at end of file