Skip to content

Commit

Permalink
[Refactor] MainCoordinator 코드 작성 DO-SOPT-iOS-Part#20
Browse files Browse the repository at this point in the history
  • Loading branch information
HELLOHIDI committed Jul 5, 2024
1 parent 13165d3 commit ac8ea4b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Core

public protocol MainViewControllable: ViewControllable { }
public protocol MainCoordinatable {
var onWeatherCellTap: ((Int) -> Void)? { get set }
}
public typealias MainViewModelType = ViewModelType & MainCoordinatable
public typealias MainPresentable = (vc: MainViewControllable, vm: any MainViewModelType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public typealias DefaultMainCoordinator = BaseCoordinator & MainCoordinatorOutpu

public
final class MainCoordinator: DefaultMainCoordinator {

public var requestCoordinating: ((MainCoordinatorDestination) -> Void)?

private let factory: MainFeatureViewBuildable
Expand All @@ -33,6 +33,9 @@ final class MainCoordinator: DefaultMainCoordinator {
public override func start() {
var main = factory.makeMain()

main.vm.onWeatherCellTap = { [weak self] page in
self?.requestCoordinating?(.detail)
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public final class MainViewModel: MainViewModelType {
public var weatherList = BehaviorRelay<[CurrentWeatherModel]>(value: [])
}

//MARK: - MainCoordinator

public var onWeatherCellTap: ((Int) -> Void)?

public func transform(from input: Input, disposeBag: DisposeBag) -> Output {
let output = Output()
self.bindOutput(output: output, disposeBag: disposeBag)
Expand All @@ -42,7 +46,7 @@ public final class MainViewModel: MainViewModelType {
}).disposed(by: disposeBag)

input.weatherListViewDidTapEvent.subscribe(with: self, onNext: { owner, page in
//owner.mainCoordinator?.pushToDetailVC(with: page.item)
owner.onWeatherCellTap?(page.item)
}).disposed(by: disposeBag)

input.searchBarDidChangeEvent.subscribe(with: self, onNext: { owner, text in
Expand Down

0 comments on commit ac8ea4b

Please sign in to comment.