Skip to content

Commit

Permalink
Add StackActionOf (#2906)
Browse files Browse the repository at this point in the history
Signed-off-by: Daiki Matsudate <[email protected]>
  • Loading branch information
Daiki Matsudate authored Mar 11, 2024
1 parent 8907f4f commit 8f0b350
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct NavigationDemo {
enum Action {
case goBackToScreen(id: StackElementID)
case goToABCButtonTapped
case path(StackAction<Path.State, Path.Action>)
case path(StackActionOf<Path>)
case popToRoot
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ private struct BindingLocalTestCase {
case fullScreenCoverButtonTapped
case navigationDestination(PresentationAction<Child.Action>)
case navigationDestinationButtonTapped
case path(StackAction<Child.State, Child.Action>)
case path(StackActionOf<Child>)
case popover(PresentationAction<Child.Action>)
case popoverButtonTapped
case sheet(PresentationAction<Child.Action>)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private struct NavigationStackTestCase {
var childResponse: Int?
}
enum Action {
case child(StackAction<ChildFeature.State, ChildFeature.Action>)
case child(StackActionOf<ChildFeature>)
}
var body: some ReducerOf<Self> {
Reduce { state, action in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct NavigationTestCaseView: View {
var path = StackState<BasicsView.Feature.State>()
}
enum Action {
case path(StackAction<BasicsView.Feature.State, BasicsView.Feature.Action>)
case path(StackActionOf<BasicsView.Feature>)
}
var body: some ReducerOf<Self> {
Reduce { state, action in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ private struct ObservableBindingLocalTestCase {
case fullScreenCoverButtonTapped
case navigationDestination(PresentationAction<Child.Action>)
case navigationDestinationButtonTapped
case path(StackAction<Child.State, Child.Action>)
case path(StackActionOf<Child>)
case popover(PresentationAction<Child.Action>)
case popoverButtonTapped
case sheet(PresentationAction<Child.Action>)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct ObservableNavigationTestCaseView: View {
}
enum Action {
case path(
StackAction<ObservableBasicsView.Feature.State, ObservableBasicsView.Feature.Action>
StackActionOf<ObservableBasicsView.Feature>
)
}
var body: some ReducerOf<Self> {
Expand Down
2 changes: 1 addition & 1 deletion Examples/SyncUps/SyncUps/AppFeature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct AppFeature {
}

enum Action {
case path(StackAction<Path.State, Path.Action>)
case path(StackActionOf<Path>)
case syncUpsList(SyncUpsList.Action)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use these tools.
- <doc:StackBasedNavigation>
- ``StackState``
- ``StackAction``
- ``StackActionOf``
- ``StackElementID``
- ``Reducer/forEach(_:action:destination:fileID:line:)-yz3v``

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

- ``StackState``
- ``StackAction``
- ``StackActionOf``
- ``Reducer/forEach(_:action:destination:fileID:line:)-yz3v``
- ``Reducer/forEach(_:action:)``
- ``DismissEffect``
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ extension Reducer {
/// // ...
/// }
/// enum Action {
/// case path(StackAction<Path.State, Path.Action>)
/// case path(StackActionOf<Path>)
/// // ...
/// }
/// var body: some ReducerOf<Self> {
Expand Down Expand Up @@ -412,6 +412,21 @@ extension Reducer {
}
}

/// A convenience type alias for referring to a stack action of a given reducer's domain.
///
/// Instead of specifying two generics:
///
/// ```swift
/// case path(StackAction<Path.State, Path.Action>)
/// ```
///
/// You can specify a single generic:
///
/// ```swift
/// case path(StackActionOf<Path>)
/// ```
public typealias StackActionOf<R: Reducer> = StackAction<R.State, R.Action>

public struct _StackReducer<Base: Reducer, Destination: Reducer>: Reducer {
let base: Base
let toStackState: WritableKeyPath<Base.State, StackState<Destination.State>>
Expand Down
36 changes: 18 additions & 18 deletions Tests/ComposableArchitectureTests/Reducers/StackReducerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
var children = StackState<Child.State>()
}
enum Action: Equatable {
case children(StackAction<Child.State, Child.Action>)
case children(StackActionOf<Child>)
case pushChild
}
var body: some ReducerOf<Self> {
Expand Down Expand Up @@ -139,7 +139,7 @@
var children = StackState<Child.State>()
}
enum Action: Equatable {
case children(StackAction<Child.State, Child.Action>)
case children(StackActionOf<Child>)
case popChild
case pushChild
}
Expand Down Expand Up @@ -203,7 +203,7 @@
var children = StackState<Child.State>()
}
enum Action: Equatable {
case children(StackAction<Child.State, Child.Action>)
case children(StackActionOf<Child>)
case pushChild
}
var body: some ReducerOf<Self> {
Expand Down Expand Up @@ -252,7 +252,7 @@
var children = StackState<Child.State>()
}
enum Action: Equatable {
case children(StackAction<Child.State, Child.Action>)
case children(StackActionOf<Child>)
}
var body: some ReducerOf<Self> {
Reduce { _, _ in .none }.forEach(\.children, action: /Action.children) { Child() }
Expand Down Expand Up @@ -307,7 +307,7 @@
var children = StackState<Child.State>()
}
enum Action: Equatable {
case child(StackAction<Child.State, Child.Action>)
case child(StackActionOf<Child>)
}
var body: some ReducerOf<Self> {
Reduce { _, _ in .none }
Expand Down Expand Up @@ -369,7 +369,7 @@
var children = StackState<Child.State>()
}
enum Action: Equatable {
case children(StackAction<Child.State, Child.Action>)
case children(StackActionOf<Child>)
case pushChild
}
var body: some ReducerOf<Self> {
Expand Down Expand Up @@ -452,7 +452,7 @@
var path = StackState<Path.State>()
}
enum Action: Equatable {
case path(StackAction<Path.State, Path.Action>)
case path(StackActionOf<Path>)
case pushChild1
case pushChild2
}
Expand Down Expand Up @@ -507,7 +507,7 @@
var path = StackState<Child.State>()
}
enum Action {
case path(StackAction<Child.State, Child.Action>)
case path(StackActionOf<Child>)
case popToRoot
case pushChild
}
Expand Down Expand Up @@ -598,7 +598,7 @@
var path = StackState<Path.State>()
}
enum Action: Equatable {
case path(StackAction<Path.State, Path.Action>)
case path(StackActionOf<Path>)
case pushChild1
case pushChild2
}
Expand Down Expand Up @@ -697,7 +697,7 @@
var path = StackState<Path.State>()
}
enum Action: Equatable {
case path(StackAction<Path.State, Path.Action>)
case path(StackActionOf<Path>)
case popAll
case popFirst
}
Expand Down Expand Up @@ -861,7 +861,7 @@
var path = StackState<Child.State>()
}
enum Action {
case path(StackAction<Child.State, Child.Action>)
case path(StackActionOf<Child>)
}
var body: some ReducerOf<Self> {
EmptyReducer()
Expand Down Expand Up @@ -933,7 +933,7 @@
var children: StackState<Child.State>
}
enum Action: Equatable {
case child(StackAction<Child.State, Child.Action>)
case child(StackActionOf<Child>)
}
var body: some ReducerOf<Self> {
Reduce { _, _ in .none }
Expand Down Expand Up @@ -982,7 +982,7 @@
var children: StackState<Child.State>
}
enum Action: Equatable {
case child(StackAction<Child.State, Child.Action>)
case child(StackActionOf<Child>)
}
var body: some ReducerOf<Self> {
Reduce { _, _ in .none }
Expand Down Expand Up @@ -1019,7 +1019,7 @@
var children = StackState<Child.State>()
}
enum Action: Equatable {
case child(StackAction<Child.State, Child.Action>)
case child(StackActionOf<Child>)
case push
}
var body: some ReducerOf<Self> {
Expand Down Expand Up @@ -1074,7 +1074,7 @@
var children = StackState<Child.State>()
}
enum Action: Equatable {
case child(StackAction<Child.State, Child.Action>)
case child(StackActionOf<Child>)
}
var body: some ReducerOf<Self> {
Reduce { _, _ in .none }
Expand Down Expand Up @@ -1120,7 +1120,7 @@
var children = StackState<Child.State>()
}
enum Action: Equatable {
case child(StackAction<Child.State, Child.Action>)
case child(StackActionOf<Child>)
}
var body: some ReducerOf<Self> {
Reduce { _, _ in .none }
Expand Down Expand Up @@ -1164,7 +1164,7 @@
var children = StackState<Child.State>()
}
enum Action: Equatable {
case child(StackAction<Child.State, Child.Action>)
case child(StackActionOf<Child>)
}
var body: some ReducerOf<Self> {
Reduce { _, _ in .none }.forEach(\.children, action: /Action.child) { Child() }
Expand Down Expand Up @@ -1265,7 +1265,7 @@
var children = StackState<Child.State>()
}
enum Action: Equatable {
case children(StackAction<Child.State, Child.Action>)
case children(StackActionOf<Child>)
case tapAfter
case tapBefore
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/ComposableArchitectureTests/ScopeLoggerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
var path = StackState<BasicsView.Feature.State>()
}
enum Action {
case path(StackAction<BasicsView.Feature.State, BasicsView.Feature.Action>)
case path(StackActionOf<BasicsView.Feature>)
}
var body: some ReducerOf<Self> {
EmptyReducer()
Expand Down

0 comments on commit 8f0b350

Please sign in to comment.