Skip to content

Commit

Permalink
[refactor] #171 TCA Feature 내부 shared 함수 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
ShapeKim98 committed Jan 17, 2025
1 parent 3c21dce commit b54bb9f
Showing 1 changed file with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,21 @@ private extension ContentCardFeature {
}
return .run { _ in await openURL(url) }
case .컨텐츠_항목_케밥_버튼_눌렀을때:
return .send(.delegate(.컨텐츠_항목_케밥_버튼_눌렀을때(content: state.content)))
return shared(
.delegate(.컨텐츠_항목_케밥_버튼_눌렀을때(content: state.content)),
state: &state
)
case .메타데이터_조회:
return .send(.async(.메타데이터_조회_수행))
return shared(.async(.메타데이터_조회_수행), state: &state)
case .즐겨찾기_버튼_눌렀을때:
guard let isFavorite = state.content.isFavorite else {
return .none
}
UIImpactFeedbackGenerator(style: .light)
.impactOccurred()
return isFavorite
? .send(.async(.즐겨찾기_취소_API))
: .send(.async(.즐겨찾기_API))
? shared(.async(.즐겨찾기_취소_API), state: &state)
: shared(.async(.즐겨찾기_API), state: &state)
}
}

Expand All @@ -131,7 +134,7 @@ private extension ContentCardFeature {
switch action {
case let .메타데이터_조회_수행_반영(imageURL):
state.content.thumbNail = imageURL
return .send(.async(.썸네일_수정_API))
return shared(.async(.썸네일_수정_API), state: &state)
case .즐겨찾기_API_반영(let favorite):
state.content.isFavorite = favorite
return .none
Expand Down Expand Up @@ -181,4 +184,19 @@ private extension ContentCardFeature {
func handleDelegateAction(_ action: Action.DelegateAction, state: inout State) -> Effect<Action> {
return .none
}

func shared(_ action: Action, state: inout State) -> Effect<Action> {
switch action {
case .view(let viewAction):
return handleViewAction(viewAction, state: &state)
case .inner(let innerAction):
return handleInnerAction(innerAction, state: &state)
case .async(let asyncAction):
return handleAsyncAction(asyncAction, state: &state)
case .scope(let scopeAction):
return handleScopeAction(scopeAction, state: &state)
case .delegate(let delegateAction):
return handleDelegateAction(delegateAction, state: &state)
}
}
}

0 comments on commit b54bb9f

Please sign in to comment.