@@ -48,11 +48,13 @@ public struct ContentCardFeature {
4848 case λ©νλ°μ΄ν°_μ‘°ν
4949 }
5050
51+ @CasePathable
5152 public enum InnerAction : Equatable {
5253 case λ©νλ°μ΄ν°_μ‘°ν_μν_λ°μ( String )
5354 case μ¦κ²¨μ°ΎκΈ°_API_λ°μ( Bool )
5455 }
5556
57+ @CasePathable
5658 public enum AsyncAction : Equatable {
5759 case λ©νλ°μ΄ν°_μ‘°ν_μν
5860 case μ¦κ²¨μ°ΎκΈ°_API
@@ -113,16 +115,16 @@ private extension ContentCardFeature {
113115 case . 컨ν
μΈ _νλͺ©_μΌλ°₯_λ²νΌ_λλ μλ:
114116 return . send( . delegate( . 컨ν
μΈ _νλͺ©_μΌλ°₯_λ²νΌ_λλ μλ( content: state. content) ) )
115117 case . λ©νλ°μ΄ν°_μ‘°ν:
116- return . send ( . async( . λ©νλ°μ΄ν°_μ‘°ν_μν) )
118+ return shared ( . async( . λ©νλ°μ΄ν°_μ‘°ν_μν) , state : & state )
117119 case . μ¦κ²¨μ°ΎκΈ°_λ²νΌ_λλ μλ:
118120 guard let isFavorite = state. content. isFavorite else {
119121 return . none
120122 }
121123 UIImpactFeedbackGenerator ( style: . light)
122124 . impactOccurred ( )
123125 return isFavorite
124- ? . send ( . async( . μ¦κ²¨μ°ΎκΈ°_μ·¨μ_API) )
125- : . send ( . async( . μ¦κ²¨μ°ΎκΈ°_API) )
126+ ? shared ( . async( . μ¦κ²¨μ°ΎκΈ°_μ·¨μ_API) , state : & state )
127+ : shared ( . async( . μ¦κ²¨μ°ΎκΈ°_API) , state : & state )
126128 }
127129 }
128130
@@ -131,7 +133,7 @@ private extension ContentCardFeature {
131133 switch action {
132134 case let . λ©νλ°μ΄ν°_μ‘°ν_μν_λ°μ( imageURL) :
133135 state. content. thumbNail = imageURL
134- return . send ( . async( . μΈλ€μΌ_μμ _API) )
136+ return shared ( . async( . μΈλ€μΌ_μμ _API) , state : & state )
135137 case . μ¦κ²¨μ°ΎκΈ°_API_λ°μ( let favorite) :
136138 state. content. isFavorite = favorite
137139 return . none
@@ -164,10 +166,7 @@ private extension ContentCardFeature {
164166 return . run { [ content = state. content] _ in
165167 let request = ThumbnailRequest ( thumbnail: content. thumbNail)
166168
167- try await contentClient. μΈλ€μΌ_μμ (
168- contentId: " \( content. id) " ,
169- model: request
170- )
169+ try await contentClient. μΈλ€μΌ_μμ ( " \( content. id) " , request)
171170 }
172171 }
173172 }
@@ -181,4 +180,19 @@ private extension ContentCardFeature {
181180 func handleDelegateAction( _ action: Action . DelegateAction , state: inout State ) -> Effect < Action > {
182181 return . none
183182 }
183+
184+ func shared( _ action: Action , state: inout State ) -> Effect < Action > {
185+ switch action {
186+ case . view( let viewAction) :
187+ return handleViewAction ( viewAction, state: & state)
188+ case . inner( let innerAction) :
189+ return handleInnerAction ( innerAction, state: & state)
190+ case . async ( let asyncAction) :
191+ return handleAsyncAction ( asyncAction, state: & state)
192+ case . scope( let scopeAction) :
193+ return handleScopeAction ( scopeAction, state: & state)
194+ case . delegate( let delegateAction) :
195+ return handleDelegateAction ( delegateAction, state: & state)
196+ }
197+ }
184198}
0 commit comments