Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- APNS
- SWIFT
- 티스토리챌린지
- modern concurrency
- 야곰 # 야곰아카데미커리어스타터캠프 #iOS개발자 # 부트캠프
- 오블완
- modern concurrency deep dive
- WWDC
- ios
Archives
- Today
- Total
Geon
TCA complicated Action 해결방법 본문
프로젝트 진행시 Action이 너무 많아져 코드 유지보수가 하기 힘들어짐
해결방법
protocol Action {
associatedtype ViewAction
associatedtype InnerAction
associatedtype AsyncAction
associatedtype ScopeAction
associatedtype DelegateAction
// NOTE: view 에서 사용되는 Action 을 정의합니다.
static func view(_: ViewAction) -> Self
// NOTE: 그 외 Reducer 내부적으로 사용되는 Action 을 정의합니다.
static func inner(_: InnerAction) -> Self
// NOTE: 비동기적으로 돌아가는 Action 을 정의합니다.
static func async(_: AsyncAction) -> Self
// NOTE: 자식 Redcuer 에서 사용되는 Action 을 정의합니다.
static func scope(_: ScopeAction) -> Self
// NOTE: 부모 Reducer 에서 사용되는 Action 을 정의합니다.
static func delegate(_: DelegateAction) -> Self
}
struct MockStore {
struct State: Equatable {
}
enum Action: AuctionAction, Equatable {
case view(ViewAction)
case inner(InnerAction)
case async(AsyncAction)
case scope(ScopeAction)
case delegate(DelegateAction)
public enum ViewAction: Equatable {
}
public enum InnerAction: Equatable {
}
public enum AsyncAction: Equatable {
}
public enum ScopeAction: Equatable {
}
public enum DelegateAction: Equatable {
case dismiss
}
}
//MARK: - Store 내부에서도 각 action에 맞게 설정
var body: some Reducer<State, Action> {
Reduce { state, action in
switch action {
case .delegate(let action):
switch action {
case .dismiss:
return .none
}
}
}
}
//MARK: - 상위 객체에서 하위객체에 action을 컨트롤할 action의 경우 상위 객체에서 한 case로 묶어서 컨트롤 가능
case .router(.routeAction(_, .mockStore(.delegate(let action)))):
switch action {
case .dismiss:
state.routes.goBack()
}
나와 똑같은 문제를 겪는 사람이 있었고, 이를 Nested Enum으로 해결
- 장점: 이렇게 해결하면 큰 Action 내부에 switch 문을 통해 컨트롤할수 있어 확실히 보기 편해졌다.
- 단점: 매번마다 해당 Action을 구현해줘야 하는 단점이 있다.