You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
// // NotificationHistoryPresenter.swift // GME Remit // // Created by InKwon James Kim on 2020/02/11. //Copyright © 2020 Gobal Money Express Co. Ltd. All rights reserved. //
import RxSwift import RxCocoa
class NotificationHistoryPresenter: ViewModelType { var interactor: NotificationHistoryInteractorInput? var wireframe: NotificationHistoryWireframeInput? struct Input { let viewWillAppear: Driver<Void> let selectNoticeIndex: Driver<Int> } struct Output { let isError: Driver<Error> let isProgress: Driver<Bool> let models: Driver<[NoticeModel]> }
private let disposeBag = DisposeBag() private let progressLinker = PublishSubject<Bool>() private let errorLinker = PublishSubject<Error>()
private let model = PublishSubject<[NoticeModel]>() func transform(input: Input) -> Output { input.viewWillAppear.drive(onNext: {[weak self] in self?.progressLinker.onNext(true) self?.interactor?.fetchNotices() }).disposed(by: disposeBag) input.selectNoticeIndex .withLatestFrom(model.asDriverOnErrorJustComplete()) { (indexPath, notices) -> NoticeModel in return notices[indexPath] } .drive(onNext: {[weak self] in self?.wireframe?.detail(index: $0.key ?? "") }).disposed(by: disposeBag) return Output( isError: errorLinker.asDriverOnErrorJustComplete(), isProgress: progressLinker.asDriverOnErrorJustComplete(), models: model.asDriverOnErrorJustComplete() ) } }
// MARK: NotificationHistory interactor output interface extension NotificationHistoryPresenter: NotificationHistoryInteractorOutput { func setNotices(with model: [NoticeModel]) { progressLinker.onNext(false) self.model.onNext(model) } func setError(with error: Error) { progressLinker.onNext(false) errorLinker.onNext(error) } }
|