Created
January 14, 2020 14:54
-
-
Save zafarivaev/dd30c2a72ce34a2efeba9931ad65b31b 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
| import RxSwift | |
| open class ReactiveCoordinator<ResultType>: NSObject { | |
| public typealias CoordinationResult = ResultType | |
| public let disposeBag = DisposeBag() | |
| private let identifier = UUID() | |
| private var childCoordinators = [UUID: Any]() | |
| private func store<T>(coordinator: ReactiveCoordinator<T>) { | |
| childCoordinators[coordinator.identifier] = coordinator | |
| } | |
| private func release<T>(coordinator: ReactiveCoordinator<T>) { | |
| childCoordinators[coordinator.identifier] = nil | |
| } | |
| @discardableResult | |
| open func coordinate<T>(to coordinator: ReactiveCoordinator<T>) -> Observable<T> { | |
| store(coordinator: coordinator) | |
| return coordinator.start() | |
| .do(onNext: { [weak self] _ in | |
| self?.release(coordinator: coordinator) }) | |
| } | |
| open func start() -> Observable<ResultType> { | |
| fatalError("start() method must be implemented") | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment