-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
94 additions
and
6 deletions.
There are no files selected for viewing
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
65 changes: 65 additions & 0 deletions
65
FootprintIOS/FootprintIOS/Sources/ViewController/MyFootprint/MyFootprintReactor.swift
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
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) | ||
} | ||
} |
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