@@ -13,123 +13,125 @@ import Domain
13
13
14
14
public struct AppFeature : FeatureReducer {
15
15
16
- @Dependency ( \. appClient) var appClient
16
+ @Dependency ( \. appClient) var appClient
17
17
18
- public init ( ) { }
19
-
20
- public struct State : Equatable , Hashable {
21
18
public init ( ) { }
22
19
23
- @PresentationState var destination : Destination . State ?
24
- var product : Product ?
25
- }
26
-
27
- public enum ViewAction : Equatable {
28
- case onAppear
29
- case showSheet
30
- case showFullScreenCover
31
- case save
32
- }
33
-
34
- public enum InternalAction : Equatable {
35
- case dismissDestination
36
- case productResponse( TaskResult < Product ? > )
37
- }
38
-
39
- public var body : some ReducerOf < Self > {
40
- Reduce ( core)
41
- . ifLet ( \. $destination, action: \. destination) {
42
- Destination ( )
43
- }
44
- }
45
-
46
- public func reduce( into state: inout State , viewAction: ViewAction ) -> Effect <
47
- Action
48
- > {
49
- switch viewAction {
50
- case . onAppear:
51
- return . run { send in
52
- await appClient. prepare ( Void ( ) )
53
- await send (
54
- . internal(
55
- . productResponse(
56
- TaskResult {
57
- try await appClient. product ( 1 )
58
- } ) ) )
59
- }
60
- case . showSheet:
61
- state. destination = . sheet( . init( ) )
62
- return . none
63
-
64
- case . showFullScreenCover:
65
- state. destination = . fullScreenCover( . init( ) )
66
- return . none
67
-
68
- case . save:
69
- return . run { [ product = state. product] send in
70
- do {
71
- try await appClient. save ( product!)
72
- } catch {
20
+ @ObservableState
21
+ public struct State : Equatable , Hashable {
22
+ public init ( ) { }
73
23
74
- }
75
- }
24
+ @ Presents var destination : Destination . State ?
25
+ var product : Product ?
76
26
}
77
- }
78
27
79
- public func reduce (
80
- into state : inout State , presentedAction : Destination . Action
81
- ) -> Effect < Action > {
82
- switch presentedAction {
83
- case . sheet ( . delegate ( . close ) ) :
84
- return . send ( . internal ( . dismissDestination ) )
28
+ public enum ViewAction {
29
+ case onAppear
30
+ case showSheet
31
+ case showFullScreenCover
32
+ case save
33
+ }
85
34
86
- case . fullScreenCover( . delegate( . close) ) :
87
- return . send( . internal( . dismissDestination) )
35
+ public enum InternalAction {
36
+ case dismissDestination
37
+ case productResponse( Result < Product ? , Error > )
38
+ }
88
39
89
- default :
90
- return . none
40
+ public var body : some ReducerOf < Self > {
41
+ Reduce ( core)
42
+ . ifLet ( \. $destination, action: \. destination) {
43
+ Destination ( )
44
+ }
91
45
}
92
- }
93
-
94
- public func reduce( into state: inout State , internalAction: InternalAction )
95
- -> Effect < Action >
96
- {
97
- switch internalAction {
98
- case let . productResponse( . success( product) ) :
99
- state. product = product
100
- return . none
101
- case let . productResponse( . failure( error) ) :
102
- print ( error)
103
- return . none
104
- case . dismissDestination:
105
- state. destination = nil
106
- return . none
46
+
47
+ public func reduce( into state: inout State , viewAction: ViewAction ) -> Effect <
48
+ Action
49
+ > {
50
+ switch viewAction {
51
+ case . onAppear:
52
+ return . run { send in
53
+ await appClient. prepare ( Void ( ) )
54
+ await send (
55
+ . internal(
56
+ . productResponse(
57
+ Result {
58
+ try await appClient. product ( 1 )
59
+ } ) ) )
60
+ }
61
+ case . showSheet:
62
+ state. destination = . sheet( . init( ) )
63
+ return . none
64
+
65
+ case . showFullScreenCover:
66
+ state. destination = . fullScreenCover( . init( ) )
67
+ return . none
68
+
69
+ case . save:
70
+ return . run { [ product = state. product] send in
71
+ do {
72
+ try await appClient. save ( product!)
73
+ } catch {
74
+
75
+ }
76
+ }
77
+ }
107
78
}
108
- }
109
79
110
- public struct Destination : DestinationReducer {
80
+ public func reduce(
81
+ into state: inout State , presentedAction: Destination . Action
82
+ ) -> Effect < Action > {
83
+ switch presentedAction {
84
+ case . sheet( . delegate( . close) ) :
85
+ return . send( . internal( . dismissDestination) )
111
86
112
- public init ( ) { }
87
+ case . fullScreenCover( . delegate( . close) ) :
88
+ return . send( . internal( . dismissDestination) )
113
89
114
- @CasePathable
115
- public enum State : Hashable {
116
- case sheet( Counter . State )
117
- case fullScreenCover( Counter . State )
90
+ default :
91
+ return . none
92
+ }
118
93
}
119
94
120
- @CasePathable
121
- public enum Action : Equatable {
122
- case sheet( Counter . Action )
123
- case fullScreenCover( Counter . Action )
95
+ public func reduce( into state: inout State , internalAction: InternalAction )
96
+ -> Effect < Action >
97
+ {
98
+ switch internalAction {
99
+ case let . productResponse( . success( product) ) :
100
+ state. product = product
101
+ return . none
102
+ case let . productResponse( . failure( error) ) :
103
+ print ( error)
104
+ return . none
105
+ case . dismissDestination:
106
+ state. destination = nil
107
+ return . none
108
+ }
124
109
}
125
110
126
- public var body : some ReducerOf < Self > {
127
- Scope ( state: \. sheet, action: \. sheet) {
128
- Counter ( )
129
- }
130
- Scope ( state: \. fullScreenCover, action: \. fullScreenCover) {
131
- Counter ( )
132
- }
111
+ public struct Destination : DestinationReducer {
112
+
113
+ public init ( ) { }
114
+
115
+ @dynamicMemberLookup
116
+ @CasePathable
117
+ public enum State : Hashable {
118
+ case sheet( Counter . State )
119
+ case fullScreenCover( Counter . State )
120
+ }
121
+
122
+ @CasePathable
123
+ public enum Action {
124
+ case sheet( Counter . Action )
125
+ case fullScreenCover( Counter . Action )
126
+ }
127
+
128
+ public var body : some ReducerOf < Self > {
129
+ Scope ( state: \. sheet, action: \. sheet) {
130
+ Counter ( )
131
+ }
132
+ Scope ( state: \. fullScreenCover, action: \. fullScreenCover) {
133
+ Counter ( )
134
+ }
135
+ }
133
136
}
134
- }
135
137
}
0 commit comments