Skip to content

Commit

Permalink
[Feat] #66 - reactor 생성 및 연결
Browse files Browse the repository at this point in the history
  • Loading branch information
513sojin committed Jan 22, 2023
1 parent 728c6da commit 9e9d38c
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 6 deletions.
12 changes: 7 additions & 5 deletions FootprintIOS/FootprintIOS/Sources/CompositionRoot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ extension CompositionRoot {
let footprintRootViewController = makeFootprintRootScreen(walkService: walkService)
let calendarViewController = makeCalendarScreen(infoService: infoService)
let recommendViewController = makeRecommendScreen()
let myPageViewController = makeMyPageScreen(walkRecordService: walkRecordService)

let myFootprintInfosService: MyFootprintInfosServiceType = MyFootprintInfosService()
let myPageViewController = makeMyPageScreen(walkRecordService: walkRecordService, myFootprintInfoService: myFootprintInfosService)

tabBarViewController.viewControllers = [
footprintRootViewController.navigationWrap(),
Expand Down Expand Up @@ -147,17 +149,17 @@ extension CompositionRoot {
return controller
}

static func makeMyPageScreen(walkRecordService: WalkRecordServiceType) -> MyPageViewController {
static func makeMyPageScreen(walkRecordService: WalkRecordServiceType, myFootprintInfoService: MyFootprintInfosServiceType) -> MyPageViewController {
var pushMyFootprintScreen: () -> MyFootprintViewController
pushMyFootprintScreen = {
let controller = MyFootprintViewController()

let reactor: MyFootprintReactor = .init(service: myFootprintInfoService)
let controller = MyFootprintViewController(reactor: reactor)
return controller
}

var pushWalkRecordScreen: () -> WalkRecordViewController
pushWalkRecordScreen = {
let reactor = WalkRecordReactor(walkRecordService: walkRecordService)
let reactor = WalkRecordReactor(service: walkRecordService)
let controller = WalkRecordViewController(reactor: reactor)
return controller
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//
// MyFootprintReactor.swift
// Footprint-iOS
//
// Created by Sojin Lee on 2023/01/22.
// Copyright © 2023 Footprint-iOS. All rights reserved.
//

import UIKit

import ReactorKit

class MyFootprintReactor: Reactor {
enum Action {
case refresh
}

enum Mutation {
case setInfos(MyFootprintInfosResponseDTO)
}

struct State {
var infos: MyFootprintInfosResponseDTO?
}

let initialState: State
let service: MyFootprintInfosServiceType

init(service: MyFootprintInfosServiceType) {
self.initialState = State()
self.service = service
}

func mutate(action: Action) -> Observable<Mutation> {
switch action {
case .refresh:
service.get()

return .empty()
}
}

func reduce(state: State, mutation: Mutation) -> State {
var newState = state

switch mutation {
case let .setInfos(data):
newState.infos = data
}

return newState
}

func transform(mutation: Observable<Mutation>) -> Observable<Mutation> {
let eventMutation = service.event
.flatMap({ (event) -> Observable<Mutation> in
switch event {
case let .get(result):
return .just(.setInfos(result))
}
})

return Observable.merge(mutation, eventMutation)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,21 @@ import UIKit
import SnapKit
import Then
import RxSwift
import ReactorKit

class MyFootprintViewController: BaseViewController {
class MyFootprintViewController: BaseViewController, View {
typealias Reactor = MyFootprintReactor

init(reactor: Reactor) {
super.init(nibName: nil, bundle: nil)

self.reactor = reactor
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

// MARK: - UI Components
enum TabItem: CaseIterable {
case dayAchievement
Expand Down Expand Up @@ -111,6 +124,14 @@ class MyFootprintViewController: BaseViewController {
setTabPager()
}

// MARK: - bind
func bind(reactor: MyFootprintReactor) {
rx.viewWillAppear
.map { _ in .refresh }
.bind(to: reactor.action)
.disposed(by: disposeBag)
}

// MARK: - setupProperty
override func setupProperty() {
super.setupProperty()
Expand Down

0 comments on commit 9e9d38c

Please sign in to comment.