-
-
Save vmaraccini/e8a5de678dc504a2a3419aa1be6d91ae to your computer and use it in GitHub Desktop.
This file contains 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
class Controller { | |
enum Action { | |
case confirm | |
} | |
let disposeBag = DisposeBag() | |
let viewController: ViewController | |
let rewardsManager: RewardsManager | |
lazy var action: Observable<Action> = { | |
return self.viewController.confirm.map { .confirm } | |
}() | |
init(status: Observable<CardStatus>, | |
rewardsManager: RewardsManager = .init(), | |
viewController: ViewController = .init()) { | |
self.viewController = viewController | |
self.rewardsManager = rewardsManager | |
subscribe(toStatus: status) | |
subscribe(toAction: action) | |
} | |
func subscribe(toStatus accountStatus: Observable<CardStatus>) { | |
accountStatus | |
.subscribe(onNext: { [viewController] in | |
let viewModel = ViewModel(cardStatus: $0) | |
viewController.bind(viewModel) | |
}).disposed(by: disposeBag) | |
} | |
func subscribe(toAction action: Observable<Action>) { | |
action | |
.flatMap { [rewardsManager] action -> Completable in | |
switch action { | |
case .confirm: | |
return rewardsManager.signup() | |
} | |
}.subscribe() | |
.disposed(by: disposeBag) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment