Skip to content

Commit b46fa5b

Browse files
committed
wip
1 parent e8c3de6 commit b46fa5b

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

Examples/TicTacToe/tic-tac-toe/Sources/LoginCore/LoginCore.swift

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@ public struct Login: ReducerProtocol, Sendable {
1515
public init() {}
1616
}
1717

18-
public enum Action: BindableAction, Equatable {
18+
public enum Action: Equatable {
1919
case alert(PresentationAction<AlertAction>)
20-
case binding(BindingAction<State>)
21-
case loginButtonTapped
2220
case loginResponse(TaskResult<AuthenticationResponse>)
2321
case twoFactor(PresentationAction<TwoFactor.Action>)
22+
case view(View)
23+
24+
public enum View: BindableAction, Equatable {
25+
case binding(BindingAction<State>)
26+
case loginButtonTapped
27+
}
2428
}
2529

2630
public enum AlertAction: Equatable, Sendable {}
@@ -30,16 +34,12 @@ public struct Login: ReducerProtocol, Sendable {
3034
public init() {}
3135

3236
public var body: some ReducerProtocol<State, Action> {
33-
BindingReducer()
37+
BindingReducer(action: /Action.view)
3438
Reduce { state, action in
3539
switch action {
3640
case .alert:
3741
return .none
3842

39-
case .binding:
40-
state.isFormValid = !state.email.isEmpty && !state.password.isEmpty
41-
return .none
42-
4343
case let .loginResponse(.success(response)):
4444
state.isLoginRequestInFlight = false
4545
if response.twoFactorRequired {
@@ -52,7 +52,14 @@ public struct Login: ReducerProtocol, Sendable {
5252
state.isLoginRequestInFlight = false
5353
return .none
5454

55-
case .loginButtonTapped:
55+
case .twoFactor:
56+
return .none
57+
58+
case .view(.binding):
59+
state.isFormValid = !state.email.isEmpty && !state.password.isEmpty
60+
return .none
61+
62+
case .view(.loginButtonTapped):
5663
state.isLoginRequestInFlight = true
5764
return .run { [email = state.email, password = state.password] send in
5865
await send(
@@ -65,9 +72,6 @@ public struct Login: ReducerProtocol, Sendable {
6572
)
6673
)
6774
}
68-
69-
case .twoFactor:
70-
return .none
7175
}
7276
}
7377
.ifLet(\.$alert, action: /Action.alert)

Examples/TicTacToe/tic-tac-toe/Sources/LoginSwiftUI/LoginView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public struct LoginView: View {
3131
}
3232

3333
public var body: some View {
34-
WithViewStore(self.store, observe: ViewState.init) { viewStore in
34+
WithViewStore(self.store, observe: ViewState.init, send: { .view($0) }) { viewStore in
3535
Form {
3636
Text(
3737
"""

Examples/TicTacToe/tic-tac-toe/Sources/LoginUIKit/LoginViewController.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,11 @@ extension Login.Action {
200200
case .alertDismissed:
201201
self = .alert(.dismiss)
202202
case let .emailChanged(email):
203-
self = .set(\.$email, email ?? "")
203+
self = .view(.set(\.$email, email ?? ""))
204204
case .loginButtonTapped:
205-
self = .loginButtonTapped
205+
self = .view(.loginButtonTapped)
206206
case let .passwordChanged(password):
207-
self = .set(\.$password, password ?? "")
207+
self = .view(.set(\.$password, password ?? ""))
208208
case .twoFactorDismissed:
209209
self = .twoFactor(.dismiss)
210210
}

0 commit comments

Comments
 (0)