From 983808df92b16ad942b3039ace80d18119a1b17f Mon Sep 17 00:00:00 2001 From: Arman Morshed Date: Thu, 7 Dec 2023 12:33:33 +0600 Subject: [PATCH] feat: call delete action from internal action instead from view action --- .../Features/Sources/Counter/CounterFeature.swift | 15 +++++++++++++++ .../Features/Sources/Counter/CounterView.swift | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/{{cookiecutter.app_name}}/Features/Sources/Counter/CounterFeature.swift b/{{cookiecutter.app_name}}/Features/Sources/Counter/CounterFeature.swift index 96c73f6..a4a84f9 100644 --- a/{{cookiecutter.app_name}}/Features/Sources/Counter/CounterFeature.swift +++ b/{{cookiecutter.app_name}}/Features/Sources/Counter/CounterFeature.swift @@ -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 { @@ -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 { + switch internalAction { + case .close: + return .send(.delegate(.close)) } } } diff --git a/{{cookiecutter.app_name}}/Features/Sources/Counter/CounterView.swift b/{{cookiecutter.app_name}}/Features/Sources/Counter/CounterView.swift index c67a017..63fa1fd 100644 --- a/{{cookiecutter.app_name}}/Features/Sources/Counter/CounterView.swift +++ b/{{cookiecutter.app_name}}/Features/Sources/Counter/CounterView.swift @@ -39,7 +39,7 @@ public struct CounterView: View { } Button { - viewstore.send(.delegate(.close)) + viewstore.send(.view(.closeButtonTapped)) } label: { Text("Dismiss") .foregroundStyle(.white)