Skip to content

Commit cc409ba

Browse files
committed
Renamed Action to AsyncAction to be more clear about what it actually is
1 parent ab5597a commit cc409ba

File tree

8 files changed

+252
-31
lines changed

8 files changed

+252
-31
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "1620"
4+
version = "1.7">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES"
8+
buildArchitectures = "Automatic">
9+
<BuildActionEntries>
10+
<BuildActionEntry
11+
buildForTesting = "YES"
12+
buildForRunning = "YES"
13+
buildForProfiling = "YES"
14+
buildForArchiving = "YES"
15+
buildForAnalyzing = "YES">
16+
<BuildableReference
17+
BuildableIdentifier = "primary"
18+
BlueprintIdentifier = "Reactor"
19+
BuildableName = "Reactor"
20+
BlueprintName = "Reactor"
21+
ReferencedContainer = "container:">
22+
</BuildableReference>
23+
</BuildActionEntry>
24+
</BuildActionEntries>
25+
</BuildAction>
26+
<TestAction
27+
buildConfiguration = "Debug"
28+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
29+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
30+
shouldUseLaunchSchemeArgsEnv = "YES"
31+
shouldAutocreateTestPlan = "YES">
32+
</TestAction>
33+
<LaunchAction
34+
buildConfiguration = "Debug"
35+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
36+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
37+
launchStyle = "0"
38+
useCustomWorkingDirectory = "NO"
39+
ignoresPersistentStateOnLaunch = "NO"
40+
debugDocumentVersioning = "YES"
41+
debugServiceExtension = "internal"
42+
allowLocationSimulation = "YES">
43+
</LaunchAction>
44+
<ProfileAction
45+
buildConfiguration = "Release"
46+
shouldUseLaunchSchemeArgsEnv = "YES"
47+
savedToolIdentifier = ""
48+
useCustomWorkingDirectory = "NO"
49+
debugDocumentVersioning = "YES">
50+
<MacroExpansion>
51+
<BuildableReference
52+
BuildableIdentifier = "primary"
53+
BlueprintIdentifier = "Reactor"
54+
BuildableName = "Reactor"
55+
BlueprintName = "Reactor"
56+
ReferencedContainer = "container:">
57+
</BuildableReference>
58+
</MacroExpansion>
59+
</ProfileAction>
60+
<AnalyzeAction
61+
buildConfiguration = "Debug">
62+
</AnalyzeAction>
63+
<ArchiveAction
64+
buildConfiguration = "Release"
65+
revealArchiveInOrganizer = "YES">
66+
</ArchiveAction>
67+
</Scheme>
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "1620"
4+
version = "1.7">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES"
8+
buildArchitectures = "Automatic">
9+
<BuildActionEntries>
10+
<BuildActionEntry
11+
buildForTesting = "YES"
12+
buildForRunning = "YES"
13+
buildForProfiling = "YES"
14+
buildForArchiving = "YES"
15+
buildForAnalyzing = "YES">
16+
<BuildableReference
17+
BuildableIdentifier = "primary"
18+
BlueprintIdentifier = "B4ECB0AB2A1250AE00B0CAAE"
19+
BuildableName = "AsyncReactorExample.app"
20+
BlueprintName = "AsyncReactorExample"
21+
ReferencedContainer = "container:AsyncReactorExample.xcodeproj">
22+
</BuildableReference>
23+
</BuildActionEntry>
24+
</BuildActionEntries>
25+
</BuildAction>
26+
<TestAction
27+
buildConfiguration = "Debug"
28+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
29+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
30+
shouldUseLaunchSchemeArgsEnv = "YES"
31+
shouldAutocreateTestPlan = "YES">
32+
</TestAction>
33+
<LaunchAction
34+
buildConfiguration = "Debug"
35+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
36+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
37+
launchStyle = "0"
38+
useCustomWorkingDirectory = "NO"
39+
ignoresPersistentStateOnLaunch = "NO"
40+
debugDocumentVersioning = "YES"
41+
debugServiceExtension = "internal"
42+
allowLocationSimulation = "YES">
43+
<BuildableProductRunnable
44+
runnableDebuggingMode = "0">
45+
<BuildableReference
46+
BuildableIdentifier = "primary"
47+
BlueprintIdentifier = "B4ECB0AB2A1250AE00B0CAAE"
48+
BuildableName = "AsyncReactorExample.app"
49+
BlueprintName = "AsyncReactorExample"
50+
ReferencedContainer = "container:AsyncReactorExample.xcodeproj">
51+
</BuildableReference>
52+
</BuildableProductRunnable>
53+
</LaunchAction>
54+
<ProfileAction
55+
buildConfiguration = "Release"
56+
shouldUseLaunchSchemeArgsEnv = "YES"
57+
savedToolIdentifier = ""
58+
useCustomWorkingDirectory = "NO"
59+
debugDocumentVersioning = "YES">
60+
<BuildableProductRunnable
61+
runnableDebuggingMode = "0">
62+
<BuildableReference
63+
BuildableIdentifier = "primary"
64+
BlueprintIdentifier = "B4ECB0AB2A1250AE00B0CAAE"
65+
BuildableName = "AsyncReactorExample.app"
66+
BlueprintName = "AsyncReactorExample"
67+
ReferencedContainer = "container:AsyncReactorExample.xcodeproj">
68+
</BuildableReference>
69+
</BuildableProductRunnable>
70+
</ProfileAction>
71+
<AnalyzeAction
72+
buildConfiguration = "Debug">
73+
</AnalyzeAction>
74+
<ArchiveAction
75+
buildConfiguration = "Release"
76+
revealArchiveInOrganizer = "YES">
77+
</ArchiveAction>
78+
</Scheme>

Example/AsyncReactorExample/Features/Repository/Search/RepositorySearchReactor.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ enum SortOptions: String, CaseIterable, Identifiable {
2929
}
3030

3131
class RepositorySearchReactor: AsyncReactor {
32-
enum Action {
32+
enum AsyncAction {
3333
case onHidePrivateToggle
3434
case enterQuery(String)
3535
case load
@@ -66,7 +66,7 @@ class RepositorySearchReactor: AsyncReactor {
6666
}
6767
}
6868

69-
func action(_ action: Action) async {
69+
func action(_ action: AsyncAction) async {
7070
switch action {
7171
case .onHidePrivateToggle:
7272
state.hidePrivate.toggle()

Example/AsyncReactorExample/Features/Repository/Search/RepositorySearchView.swift

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,26 @@ struct RepositorySearchView: View {
1313
@EnvironmentObject
1414
private var reactor: RepositorySearchReactor
1515

16-
@ActionBinding(RepositorySearchReactor.self, keyPath: \.hidePrivate, action: RepositorySearchReactor.SyncAction.toggleHidePrivate)
16+
@ActionBinding(
17+
RepositorySearchReactor.self,
18+
keyPath: \.hidePrivate,
19+
action: RepositorySearchReactor.SyncAction.toggleHidePrivate
20+
)
1721
private var hidePrivate: Bool
1822

19-
@ActionBinding(RepositorySearchReactor.self, keyPath: \.query, cancelId: .init(id: "enterQuery", mode: .inFlight), action: RepositorySearchReactor.Action.enterQuery)
23+
@ActionBinding(
24+
RepositorySearchReactor.self,
25+
keyPath: \.query,
26+
cancelId: .init(id: "enterQuery", mode: .inFlight),
27+
action: RepositorySearchReactor.AsyncAction.enterQuery
28+
)
2029
private var query: String
2130

22-
@ActionBinding(RepositorySearchReactor.self, keyPath: \.sortBy, action: RepositorySearchReactor.Action.onSortOptionSelected)
31+
@ActionBinding(
32+
RepositorySearchReactor.self,
33+
keyPath: \.sortBy,
34+
action: RepositorySearchReactor.AsyncAction.onSortOptionSelected
35+
)
2336
private var sortOption: SortOptions
2437

2538
var body: some View {

Sources/AsyncReactor/AsyncReactor+SwiftUI.swift

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,48 @@ public struct ActionBinding<Reactor: AsyncReactor, Action, Value>: DynamicProper
2121

2222
let cancelId: CancelId?
2323

24-
public init(_ reactorType: Reactor.Type, keyPath: KeyPath<Reactor.State, Value>, cancelId: CancelId? = nil, action: @escaping (Value) -> Reactor.Action) where Action == Reactor.Action {
24+
public init(
25+
_ reactorType: Reactor.Type,
26+
keyPath: KeyPath<Reactor.State, Value>,
27+
cancelId: CancelId? = nil,
28+
action: @escaping (Value) -> Reactor.AsyncAction
29+
) where Action == Reactor.AsyncAction {
2530
target = EnvironmentObject()
2631
self.keyPath = keyPath
2732
self.action = action
2833
self.cancelId = cancelId
2934
}
3035

31-
public init(_ reactorType: Reactor.Type, keyPath: KeyPath<Reactor.State, Value>, cancelId: CancelId? = nil, action: @escaping @autoclosure () -> Reactor.Action) where Action == Reactor.Action {
32-
self.init(reactorType, keyPath: keyPath, cancelId: cancelId, action: { _ in action() })
36+
public init(
37+
_ reactorType: Reactor.Type,
38+
keyPath: KeyPath<Reactor.State, Value>,
39+
cancelId: CancelId? = nil,
40+
action: @escaping @autoclosure () -> Reactor.AsyncAction
41+
) where Action == Reactor.AsyncAction {
42+
self.init(
43+
reactorType,
44+
keyPath: keyPath,
45+
cancelId: cancelId,
46+
action: { _ in action() }
47+
)
3348
}
3449

35-
public init(_ reactorType: Reactor.Type, keyPath: KeyPath<Reactor.State, Value>, action: @escaping (Value) -> Reactor.SyncAction) where Action == Reactor.SyncAction {
50+
public init(
51+
_ reactorType: Reactor.Type,
52+
keyPath: KeyPath<Reactor.State, Value>,
53+
action: @escaping (Value) -> Reactor.SyncAction
54+
) where Action == Reactor.SyncAction {
3655
target = EnvironmentObject()
3756
self.keyPath = keyPath
3857
self.action = action
3958
cancelId = nil
4059
}
4160

42-
public init(_ reactorType: Reactor.Type, keyPath: KeyPath<Reactor.State, Value>, action: @escaping @autoclosure () -> Reactor.SyncAction) where Action == Reactor.SyncAction {
61+
public init(
62+
_ reactorType: Reactor.Type,
63+
keyPath: KeyPath<Reactor.State, Value>,
64+
action: @escaping @autoclosure () -> Reactor.SyncAction
65+
) where Action == Reactor.SyncAction {
4366
self.init(reactorType, keyPath: keyPath, action: { _ in action() })
4467
}
4568

@@ -51,7 +74,7 @@ public struct ActionBinding<Reactor: AsyncReactor, Action, Value>: DynamicProper
5174
public var projectedValue: Binding<Value> {
5275
get {
5376
func bindAction() -> Binding<Value> {
54-
target.wrappedValue.bind(keyPath, cancelId: cancelId, action: action as! (Value) -> Reactor.Action)
77+
target.wrappedValue.bind(keyPath, cancelId: cancelId, action: action as! (Value) -> Reactor.AsyncAction)
5578
}
5679

5780
func bindSyncAction() -> Binding<Value> {
@@ -60,7 +83,7 @@ public struct ActionBinding<Reactor: AsyncReactor, Action, Value>: DynamicProper
6083

6184
if Action.self == Reactor.SyncAction.self {
6285
return bindSyncAction()
63-
} else if Action.self == Reactor.Action.self {
86+
} else if Action.self == Reactor.AsyncAction.self {
6487
return bindAction()
6588
} else {
6689
fatalError("this should never happen :)")
@@ -76,7 +99,11 @@ public struct ReactorView<Content: View, R: AsyncReactor>: View {
7699
@StateObject
77100
private var reactor: R
78101

79-
public init(_ reactor: @escaping @autoclosure () -> R, definesLifecycle: Bool = true, @ViewBuilder content: () -> Content) {
102+
public init(
103+
_ reactor: @escaping @autoclosure () -> R,
104+
definesLifecycle: Bool = true,
105+
@ViewBuilder content: () -> Content
106+
) {
80107
_reactor = StateObject(wrappedValue: reactor())
81108
self.content = content()
82109
self.definesLifecycle = definesLifecycle

Sources/Reactor/Reactor+SwiftUI.swift

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,43 @@ public struct ActionBinding<R: Reactor, Action, Value>: DynamicProperty {
2222

2323
let cancelId: CancelId?
2424

25-
public init(_ reactorType: R.Type, keyPath: KeyPath<R.State, Value>, cancelId: CancelId? = nil, action: @escaping (Value) -> R.Action) where Action == R.Action {
25+
public init(
26+
_ reactorType: R.Type,
27+
keyPath: KeyPath<R.State, Value>,
28+
cancelId: CancelId? = nil,
29+
action: @escaping (Value) -> R.AsyncAction
30+
) where Action == R.AsyncAction {
2631
target = Environment(R.self)
2732
self.keyPath = keyPath
2833
self.action = action
2934
self.cancelId = cancelId
3035
}
3136

32-
public init(_ reactorType: R.Type, keyPath: KeyPath<R.State, Value>, cancelId: CancelId? = nil, action: @escaping @autoclosure () -> R.Action) where Action == R.Action {
37+
public init(
38+
_ reactorType: R.Type,
39+
keyPath: KeyPath<R.State, Value>,
40+
cancelId: CancelId? = nil,
41+
action: @escaping @autoclosure () -> R.AsyncAction
42+
) where Action == R.AsyncAction {
3343
self.init(reactorType, keyPath: keyPath, cancelId: cancelId, action: { _ in action() })
3444
}
3545

36-
public init(_ reactorType: R.Type, keyPath: KeyPath<R.State, Value>, action: @escaping (Value) -> R.SyncAction) where Action == R.SyncAction {
46+
public init(
47+
_ reactorType: R.Type,
48+
keyPath: KeyPath<R.State, Value>,
49+
action: @escaping (Value) -> R.SyncAction
50+
) where Action == R.SyncAction {
3751
target = Environment(R.self)
3852
self.keyPath = keyPath
3953
self.action = action
4054
cancelId = nil
4155
}
4256

43-
public init(_ reactorType: R.Type, keyPath: KeyPath<R.State, Value>, action: @escaping @autoclosure () -> R.SyncAction) where Action == R.SyncAction {
57+
public init(
58+
_ reactorType: R.Type,
59+
keyPath: KeyPath<R.State, Value>,
60+
action: @escaping @autoclosure () -> R.SyncAction
61+
) where Action == R.SyncAction {
4462
self.init(reactorType, keyPath: keyPath, action: { _ in action() })
4563
}
4664

@@ -52,7 +70,7 @@ public struct ActionBinding<R: Reactor, Action, Value>: DynamicProperty {
5270
public var projectedValue: Binding<Value> {
5371
get {
5472
func bindAction() -> Binding<Value> {
55-
target.wrappedValue.bind(keyPath, cancelId: cancelId, action: action as! (Value) -> R.Action)
73+
target.wrappedValue.bind(keyPath, cancelId: cancelId, action: action as! (Value) -> R.AsyncAction)
5674
}
5775

5876
func bindSyncAction() -> Binding<Value> {
@@ -61,7 +79,7 @@ public struct ActionBinding<R: Reactor, Action, Value>: DynamicProperty {
6179

6280
if Action.self == R.SyncAction.self {
6381
return bindSyncAction()
64-
} else if Action.self == R.Action.self {
82+
} else if Action.self == R.AsyncAction.self {
6583
return bindAction()
6684
} else {
6785
fatalError("this should never happen :)")
@@ -78,7 +96,11 @@ public struct ReactorView<Content: View, R: Reactor>: View {
7896
@State
7997
private var reactor: R
8098

81-
public init(_ reactor: @escaping @autoclosure () -> R, definesLifecycle: Bool = true, @ViewBuilder content: () -> Content) {
99+
public init(
100+
_ reactor: @escaping @autoclosure () -> R,
101+
definesLifecycle: Bool = true,
102+
@ViewBuilder content: () -> Content
103+
) {
82104
_reactor = State(initialValue: reactor())
83105
self.content = content()
84106
self.definesLifecycle = definesLifecycle

0 commit comments

Comments
 (0)