Last active
May 22, 2019 04:52
-
-
Save GeekTree0101/08608216494d86dad48f28e8a144f27e to your computer and use it in GitHub Desktop.
RxVIP Sample
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
// Interactor | |
import UIKit | |
import RxSwift | |
import RxCocoa | |
protocol UserInteractorInputLogic { | |
var input: PublishRelay<UserModels.Model.Request> { get } | |
} | |
protocol UserInteractorOutputLogic { | |
var output: Observable<UserModels.Model.Response> { get } | |
} | |
protocol UserDataStore { | |
var title: String { get set } | |
} | |
class UserInteractor: UserInteractorInputLogic & UserDataStore { | |
// MARK: Input Properties | |
public var input: PublishRelay<UserModels.Model.Request> = .init() | |
// MARK: DataStore | |
public var title: String = "" | |
// MARK: Workers | |
private var worker: UserWorker | |
// MARK: Presenter | |
public var presenter: UserPresenterInputLogic! { | |
get { | |
fatalError("Do not access presenter input logic") | |
} | |
set(newPresenter) { | |
self.disposeBag = DisposeBag() | |
self.configuration(newPresenter) | |
} | |
} | |
private var disposeBag = DisposeBag() | |
init(worker: UserWorker) { | |
self.worker = worker | |
} | |
} | |
extension UserInteractor: UserInteractorOutputLogic { | |
var output: Observable<UserModels.Model.Response> { | |
return self.input | |
.flatMap({ [unowned self] request -> Observable<Int> in | |
return self.worker.mul(request.input) | |
}) | |
.map { num in | |
return .init(output: num) | |
} | |
} | |
private func configuration(_ presenter: UserPresenterInputLogic) { | |
output.bind(to: presenter.input) | |
.disposed(by: disposeBag) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
장점: Interactor Output Property를 직접보면서 bind 처리해줄 수 있음
단점: Interactor가 Massive해지는 느낌