Skip to content

Commit

Permalink
coordinator: use Signal for will/didNavigate
Browse files Browse the repository at this point in the history
  • Loading branch information
Thibault Wittemberg committed Nov 26, 2018
1 parent d1f6c93 commit 02acc53
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
21 changes: 11 additions & 10 deletions RxFlow/Coordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import RxSwift
import RxCocoa

/// Delegate used to communicate from a FlowCoordinator
protocol FlowCoordinatorDelegate: class {
Expand Down Expand Up @@ -213,8 +214,8 @@ class FlowCoordinator: HasDisposeBag {
final public class Coordinator: HasDisposeBag, Synchronizable {

private var flowCoordinators = [String: FlowCoordinator]()
fileprivate let willNavigateSubject = PublishSubject<(Flow, Step)>()
fileprivate let didNavigateSubject = PublishSubject<(Flow, Step)>()
fileprivate let willNavigateSubject = PublishRelay<(Flow, Step)>()
fileprivate let didNavigateSubject = PublishRelay<(Flow, Step)>()

/// Initialize the Coordinator
public init() {
Expand Down Expand Up @@ -284,13 +285,13 @@ extension Coordinator: FlowCoordinatorDelegate {

func willNavigate(to stepContext: StepContext) {
if let withinFlow = stepContext.withinFlow {
self.willNavigateSubject.onNext((withinFlow, stepContext.step))
self.willNavigateSubject.accept((withinFlow, stepContext.step))
}
}

func didNavigate(to stepContext: StepContext) {
if let withinFlow = stepContext.withinFlow {
self.didNavigateSubject.onNext((withinFlow, stepContext.step))
self.didNavigateSubject.accept((withinFlow, stepContext.step))
}
}
}
Expand All @@ -307,13 +308,13 @@ extension Coordinator {

extension Reactive where Base: Coordinator {

/// Rx Observable triggered before the Coordinator navigates a Flow/Step
public var willNavigate: Observable<(Flow, Step)> {
return self.base.willNavigateSubject.asObservable()
/// Rx Signal triggered before the Coordinator navigates a Flow/Step
public var willNavigate: Signal<(Flow, Step)> {
return self.base.willNavigateSubject.asSignal()
}

/// Rx Observable triggered after the Coordinator navigates a Flow/Step
public var didNavigate: Observable<(Flow, Step)> {
return self.base.didNavigateSubject.asObservable()
/// Rx Signal triggered after the Coordinator navigates a Flow/Step
public var didNavigate: Signal<(Flow, Step)> {
return self.base.didNavigateSubject.asSignal()
}
}
2 changes: 1 addition & 1 deletion RxFlowDemo/RxFlowDemo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

guard let window = self.window else { return false }

coordinator.rx.didNavigate.subscribe(onNext: { (flow, step) in
coordinator.rx.didNavigate.emit(onNext: { (flow, step) in
print ("did navigate to flow=\(flow) and step=\(step)")
}).disposed(by: self.disposeBag)

Expand Down

0 comments on commit 02acc53

Please sign in to comment.