Skip to content

Commit

Permalink
feat: call delete action from internal action instead from view action
Browse files Browse the repository at this point in the history
  • Loading branch information
Arman-Morshed committed Dec 7, 2023
1 parent 0b986cd commit 983808d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public struct Counter: FeatureReducer {
public enum ViewAction: Equatable {
case decrementButtonTapped
case incrementButtonTapped
case closeButtonTapped
}

public enum InternalAction: Equatable {
case close
}

public enum DelegateAction: Equatable {
Expand All @@ -38,6 +43,16 @@ public struct Counter: FeatureReducer {
case .incrementButtonTapped:
state.count += 1
return .none

case .closeButtonTapped:
return .send(.internal(.close))
}
}

public func reduce(into state: inout State, internalAction: InternalAction) -> Effect<Action> {
switch internalAction {
case .close:
return .send(.delegate(.close))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public struct CounterView: View {
}

Button {
viewstore.send(.delegate(.close))
viewstore.send(.view(.closeButtonTapped))
} label: {
Text("Dismiss")
.foregroundStyle(.white)
Expand Down

0 comments on commit 983808d

Please sign in to comment.