@@ -6,7 +6,12 @@ import Foundation
66extension Reducer {
77
88 /// Integrate a Loadable child domain with a generic Request type
9- public func loadable< ChildState, ChildAction, Child: Reducer , Request> (
9+ public func loadable<
10+ ChildState: Sendable ,
11+ ChildAction,
12+ Child: Reducer ,
13+ Request: Sendable
14+ > (
1015 _ toLoadableState: WritableKeyPath < State , LoadableState < Request , ChildState > > ,
1116 action toLoadingAction: CaseKeyPath < Action , LoadingAction < Request , ChildState , ChildAction > > ,
1217 @ReducerBuilder < ChildState , ChildAction > child: ( ) -> Child ,
@@ -25,7 +30,11 @@ extension Reducer {
2530 }
2631
2732 /// Integrate a Loadable child domain which does not require a Request type
28- public func loadable< ChildState, ChildAction, Child: Reducer > (
33+ public func loadable<
34+ ChildState: Sendable ,
35+ ChildAction,
36+ Child: Reducer
37+ > (
2938 _ toLoadableState: WritableKeyPath < State , LoadableState < EmptyLoadRequest , ChildState > > ,
3039 action toLoadingAction: CaseKeyPath <
3140 Action , LoadingAction < EmptyLoadRequest , ChildState , ChildAction >
@@ -46,7 +55,10 @@ extension Reducer {
4655 }
4756
4857 /// Integrate some LoadableState which does not require a child domain
49- public func loadable< ChildState, Request> (
58+ public func loadable<
59+ ChildState: Sendable ,
60+ Request: Sendable
61+ > (
5062 _ toLoadableState: WritableKeyPath < State , LoadableState < Request , ChildState > > ,
5163 action toLoadingAction: CaseKeyPath < Action , LoadingAction < Request , ChildState , NoLoadingAction > > ,
5264 load: @escaping @Sendable ( Request, State) async throws -> ChildState ,
@@ -71,7 +83,7 @@ extension Reducer {
7183
7284 fileprivate func loadable<
7385 Child: Reducer ,
74- Request,
86+ Request: Sendable ,
7587 Client: LoadableClient < Request , State , Child . State >
7688 > (
7789 fileID: StaticString ,
@@ -80,7 +92,7 @@ extension Reducer {
8092 action toLoadingAction: CaseKeyPath < Action , LoadingAction < Request , Child . State , Child . Action > > ,
8193 client: Client ,
8294 @ReducerBuilder < Child . State , Child . Action > child: ( ) -> Child
83- ) -> LoadingReducer < Self , Child , Request , Client > {
95+ ) -> LoadingReducer < Self , Child , Request , Client > where Client . State : Sendable {
8496 LoadingReducer (
8597 parent: self ,
8698 child: child ( ) ,
@@ -98,9 +110,9 @@ extension Reducer {
98110private struct LoadingReducer <
99111 Parent: Reducer ,
100112 Child: Reducer ,
101- Request,
113+ Request: Sendable ,
102114 Client: LoadableClient < Request , Parent . State , Child . State >
103- > : Reducer {
115+ > : Reducer where Child . State : Sendable {
104116
105117 typealias State = Parent . State
106118 typealias Action = Parent . Action
@@ -155,16 +167,16 @@ private struct LoadingReducer<
155167 struct CancelID : Hashable { }
156168
157169 func reduce( into state: inout State , action: Action ) -> Effect < Action > {
158- let parentState = state
170+ let parentState = UncheckedSendable ( state)
159171 return CombineReducers {
160172 Scope ( state: toLoadableState, action: toLoadingAction) {
161173 Reduce { loadableState, loadingAction in
162174
163175 func send( refresh: Bool , _ request: Request ) -> Effect < ThisLoadingAction > {
164176 loadableState. becomeActive ( request)
165177 return
166- . run { send in
167- let value = try await client . load ( request, parentState)
178+ . run { [ load = client . load ] send in
179+ let value = try await load ( request, parentState. value )
168180 await send ( . finished( request, didRefresh: refresh, . success( value) ) )
169181 } catch: { error, send in
170182 await send ( . finished( request, didRefresh: refresh, . failure( error) ) )
0 commit comments