-
Notifications
You must be signed in to change notification settings - Fork 299
/
Explorations.swift
179 lines (148 loc) · 3.85 KB
/
Explorations.swift
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import ComposableArchitecture
struct RowState: Identifiable {
let id = UUID()
}
enum RowAction {}
struct RowEnvironment {}
let rowReducer = Reducer<RowState, RowAction, RowEnvironment> { _, _, _ in .none }
struct ModalState {}
enum ModalAction {}
struct ModalEnvironment {}
let modalReducer = Reducer<ModalState, ModalAction, ModalEnvironment> { _, _, _ in
.none
}
enum Feature {
struct State {
var modal: ModalState?
var rows: IdentifiedArrayOf<RowState>
}
enum Action {
case buttonTapped
case otherButtonTapped
case modal(ModalAction)
case row(id: RowState.ID, action: RowAction)
case sharedButtonLogic
}
struct Environment {
}
static let reducer = Reducer<
State,
Action,
Environment
>.combine(
modalReducer
.optional()
.pullback(state: \.modal, action: /Action.modal, environment: { _ in .init() }),
rowReducer
.forEach(state: \.rows, action: /Action.row, environment: { _ in .init() }),
Reducer { state, action, environment in
switch action {
case .buttonTapped:
// Additional logic
//return sharedButtonTapLogic(state: &state, environment: environment)
//return state.sharedButtonTapLogic(environment: environment)
return Effect(value: .sharedButtonLogic)
case .otherButtonTapped:
// Additional logic
//return sharedButtonTapLogic(state: &state, environment: environment)
//return state.sharedButtonTapLogic(environment: environment)
return Effect(value: .sharedButtonLogic)
case .sharedButtonLogic:
// Do shared logic
return .none
case .modal:
return .none
case .row:
return .none
}
}
)
private static func sharedButtonTapLogic(
state: inout State,
environment: Environment
) -> Effect<Action, Never> {
.none
}
}
extension Feature.State {
fileprivate mutating func sharedButtonTapLogic(
environment: Feature.Environment
) -> Effect<Feature.Action, Never> {
.none
}
}
struct TabAState {}
enum TabAAction {}
struct TabAEnvironment {}
let tabAReducer = Reducer<TabAState, TabAAction, TabAEnvironment> { _, _, _ in .none }
struct TabBState {}
enum TabBAction {}
struct TabBEnvironment {}
let tabBReducer = Reducer<TabBState, TabBAction, TabBEnvironment> { _, _, _ in .none }
struct TabCState {}
enum TabCAction {}
struct TabCEnvironment {}
let tabCReducer = Reducer<TabCState, TabCAction, TabCEnvironment> { _, _, _ in .none }
struct AppState {
var tabA: TabAState
var tabB: TabBState
var tabC: TabCState
}
enum AppAction {
case tabA(TabAAction)
case tabB(TabBAction)
case tabC(TabCAction)
}
enum AppEnvironment {}
let appReducer = Reducer<_, _, AppEnvironment>.combine(
Reducer { _, _, _ in
// additional logic
.none
},
tabAReducer
.pullback(state: \.tabA, action: /AppAction.tabA, environment: { _ in .init() }),
tabBReducer
.pullback(state: \.tabB, action: /AppAction.tabB, environment: { _ in .init() }),
tabCReducer
.pullback(state: \AppState.tabC, action: /AppAction.tabC, environment: { _ in .init() }),
Reducer { _, _, _ in
// additional logic
.none
}
)
/*
Reducer1()
Reducer2()
Reducer3()
Reducer { _, _, _ in
// additional logic
.none
}
Scope(state: \.tabA, action: /AppAction.tabA, environment: { _ in .init() }) {
tabAReducer
}
Scope(state: \.tabB, action: /AppAction.tabB, environment: { _ in .init() }) {
tabBReducer
}
Scope(state: \.tabC, action: /AppAction.tabC, environment: { _ in .init() }) {
tabCReducer
}
Reducer { _, _, _ in
// additional logic
.none
}
Reducer { _, _, _ in
// core feature logic
.none
}
.ifLet(state: \.modal, action: /Action.modal, ...) {
BeforeModal()
Modal()
AfterModal()
}
.forEach(state: \.rows, action: /Action.row, ...) {
BeforeRow()
Row()
AfterRow()
}
*/