diff --git a/Examples/Integration/Integration/EnumTestCase.swift b/Examples/Integration/Integration/EnumTestCase.swift index 4df0931fe8c9..22aae01d8d64 100644 --- a/Examples/Integration/Integration/EnumTestCase.swift +++ b/Examples/Integration/Integration/EnumTestCase.swift @@ -51,26 +51,30 @@ struct EnumView: View { } } } - IfLetStore( - self.store.scope(state: \.$destination, action: { .destination($0) }), - state: /Feature.Destination.State.feature1, - action: { .feature1($0) } - ) { store in - Section { - BasicsView(store: store) - } header: { - Text("Feature 1") - } - } - IfLetStore( - self.store.scope(state: \.$destination, action: { .destination($0) }), - state: /Feature.Destination.State.feature2, - action: { .feature2($0) } - ) { store in - Section { - BasicsView(store: store) - } header: { - Text("Feature 2") + IfLetStore(self.store.scope(state: \.$destination, action: { .destination($0) })) { store in + SwitchStore(store) { + switch $0 { + case .feature1: + CaseLet( + /Feature.Destination.State.feature1, action: Feature.Destination.Action.feature1 + ) { store in + Section { + BasicsView(store: store) + } header: { + Text("Feature 1") + } + } + case .feature2: + CaseLet( + /Feature.Destination.State.feature2, action: Feature.Destination.Action.feature2 + ) { store in + Section { + BasicsView(store: store) + } header: { + Text("Feature 2") + } + } + } } } } diff --git a/Examples/Integration/Integration/PresentationTestCase.swift b/Examples/Integration/Integration/PresentationTestCase.swift index 380121fa92c8..fbb92c64cd6a 100644 --- a/Examples/Integration/Integration/PresentationTestCase.swift +++ b/Examples/Integration/Integration/PresentationTestCase.swift @@ -158,6 +158,9 @@ struct PresentationView: View { return .none } } + .ifLet(\.$destination, action: /Action.destination) { + Destination() + } .ifLet(\.$sheet, action: /Action.sheet) { BasicsView.Feature() } diff --git a/Examples/Integration/IntegrationUITests/EnumTests.swift b/Examples/Integration/IntegrationUITests/EnumTests.swift index c2cc22e2dfea..4f391ca4a2b9 100644 --- a/Examples/Integration/IntegrationUITests/EnumTests.swift +++ b/Examples/Integration/IntegrationUITests/EnumTests.swift @@ -18,14 +18,18 @@ final class EnumTests: BaseIntegrationTests { """ BasicsView.body EnumView.body - Store.init - Store.scope - Store.scope - Store, PresentationAction>.scope - Store, PresentationAction>.scope + PresentationStoreOf.scope StoreOf.init StoreOf.init - StoreOf.scope + StoreOf.init + StoreOf.init + StoreOf.init + StoreOf.init + StoreOf.init + StoreOf.init + StoreOf.init + StoreOf.scope + StoreOf.scope StoreOf.scope StoreOf.scope """ @@ -35,13 +39,17 @@ final class EnumTests: BaseIntegrationTests { self.assertLogs { """ BasicsView.body - Store.scope - Store.scope - Store.scope - Store, PresentationAction>.scope - Store, PresentationAction>.scope + PresentationStoreOf.scope StoreOf.scope - StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope StoreOf.scope StoreOf.scope """ @@ -57,14 +65,18 @@ final class EnumTests: BaseIntegrationTests { self.assertLogs { """ EnumView.body - Store.scope - Store.scope - Store.scope - Store.scope - Store, PresentationAction>.scope - Store, PresentationAction>.scope + PresentationStoreOf.scope StoreOf.scope - StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope StoreOf.scope StoreOf.scope """ @@ -81,19 +93,28 @@ final class EnumTests: BaseIntegrationTests { """ BasicsView.body EnumView.body - Store.init - Store.scope - Store.scope - Store.scope - Store.scope - Store.scope - Store.scope - Store, PresentationAction>.scope - Store, PresentationAction>.scope + PresentationStoreOf.scope StoreOf.init StoreOf.init StoreOf.scope - StoreOf.scope + StoreOf.deinit + StoreOf.init + StoreOf.init + StoreOf.init + StoreOf.init + StoreOf.init + StoreOf.init + StoreOf.init + StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope StoreOf.scope StoreOf.scope """ @@ -109,21 +130,29 @@ final class EnumTests: BaseIntegrationTests { self.assertLogs { """ EnumView.body - Store.scope - Store.scope - Store.scope - Store.scope - Store.scope - Store.scope - Store.scope - Store, PresentationAction>.scope - Store, PresentationAction>.scope - Store, PresentationAction>.scope - Store, PresentationAction>.scope + PresentationStoreOf.scope + PresentationStoreOf.scope StoreOf.scope StoreOf.scope - StoreOf.scope - StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope StoreOf.scope StoreOf.scope StoreOf.scope diff --git a/Examples/Integration/IntegrationUITests/NavigationTests.swift b/Examples/Integration/IntegrationUITests/NavigationTests.swift index fb48355e5ed9..4b125b3d5fd4 100644 --- a/Examples/Integration/IntegrationUITests/NavigationTests.swift +++ b/Examples/Integration/IntegrationUITests/NavigationTests.swift @@ -16,7 +16,7 @@ final class NavigationTests: BaseIntegrationTests { self.assertLogs { """ BasicsView.body - Store, StackAction>.init + StackStoreOf.init StoreOf.init StoreOf.init """ @@ -25,7 +25,7 @@ final class NavigationTests: BaseIntegrationTests { self.assertLogs { """ BasicsView.body - Store, StackAction>.scope + StackStoreOf.scope StoreOf.scope StoreOf.scope """ @@ -43,15 +43,15 @@ final class NavigationTests: BaseIntegrationTests { self.assertLogs { """ BasicsView.body - Store, StackAction>.scope - Store, StackAction>.scope - Store, StackAction>.scope - Store, StackAction>.scope - Store, StackAction>.scope - Store, StackAction>.scope - Store, StackAction>.scope - Store, StackAction>.scope - Store, StackAction>.scope + StackStoreOf.scope + StackStoreOf.scope + StackStoreOf.scope + StackStoreOf.scope + StackStoreOf.scope + StackStoreOf.scope + StackStoreOf.scope + StackStoreOf.scope + StackStoreOf.scope StoreOf.scope StoreOf.scope StoreOf.scope diff --git a/Examples/Integration/IntegrationUITests/OptionalTests.swift b/Examples/Integration/IntegrationUITests/OptionalTests.swift index 146617f2d0de..c0af1c094ee3 100644 --- a/Examples/Integration/IntegrationUITests/OptionalTests.swift +++ b/Examples/Integration/IntegrationUITests/OptionalTests.swift @@ -17,12 +17,12 @@ final class OptionalTests: BaseIntegrationTests { """ BasicsView.body OptionalView.body - Store.init - Store.scope - Store.scope - Store, PresentationAction>.scope + PresentationStoreOf.scope StoreOf.init StoreOf.init + StoreOf.init + StoreOf.scope + StoreOf.scope StoreOf.scope StoreOf.scope """ @@ -32,11 +32,11 @@ final class OptionalTests: BaseIntegrationTests { """ BasicsView.body OptionalView.body - Store.scope - Store.scope - Store.scope - Store, PresentationAction>.scope + PresentationStoreOf.scope StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope StoreOf.scope StoreOf.scope """ @@ -60,11 +60,11 @@ final class OptionalTests: BaseIntegrationTests { """ BasicsView.body OptionalView.body - Store.scope - Store.scope - Store.scope - Store, PresentationAction>.scope + PresentationStoreOf.scope StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope StoreOf.scope StoreOf.scope """ diff --git a/Examples/Integration/IntegrationUITests/PresentationTests.swift b/Examples/Integration/IntegrationUITests/PresentationTests.swift index 67a8b2c9e65c..4fff2816e1b4 100644 --- a/Examples/Integration/IntegrationUITests/PresentationTests.swift +++ b/Examples/Integration/IntegrationUITests/PresentationTests.swift @@ -8,7 +8,7 @@ final class PresentationTests: BaseIntegrationTests { super.setUp() self.app.buttons["Presentation"].tap() self.clearLogs() - //SnapshotTesting.isRecording = true + // SnapshotTesting.isRecording = true } func testOptional() { @@ -16,16 +16,16 @@ final class PresentationTests: BaseIntegrationTests { self.assertLogs { """ BasicsView.body - Store.deinit - Store.init - Store.init - Store.init - Store.init - Store.init - Store, PresentationAction>.scope - Store, PresentationAction>.scope + PresentationStoreOf.scope + PresentationStoreOf.scope StoreOf.init StoreOf.init + StoreOf.deinit + StoreOf.init + StoreOf.init + StoreOf.init + StoreOf.init + StoreOf.init StoreOf.scope StoreOf.scope """ @@ -34,13 +34,13 @@ final class PresentationTests: BaseIntegrationTests { self.assertLogs { """ BasicsView.body - Store.scope - Store.scope - Store.scope - Store.scope - Store, PresentationAction>.scope - Store, PresentationAction>.scope + PresentationStoreOf.scope + PresentationStoreOf.scope StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope StoreOf.scope StoreOf.scope """ @@ -48,22 +48,22 @@ final class PresentationTests: BaseIntegrationTests { self.app.buttons["Dismiss"].firstMatch.tap() self.assertLogs { """ - Store.deinit - Store.deinit - Store.deinit - Store.deinit - Store.deinit - Store.init - Store.scope - Store.scope - Store.scope - Store.scope - Store.scope - Store, PresentationAction>.scope - Store, PresentationAction>.scope + PresentationStoreOf.scope + PresentationStoreOf.scope StoreOf.deinit StoreOf.deinit StoreOf.scope + StoreOf.deinit + StoreOf.deinit + StoreOf.deinit + StoreOf.deinit + StoreOf.deinit + StoreOf.init + StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope StoreOf.scope StoreOf.scope StoreOf.scope @@ -77,16 +77,16 @@ final class PresentationTests: BaseIntegrationTests { self.assertLogs { """ BasicsView.body - Store.deinit - Store.init - Store.init - Store.init - Store.init - Store.init - Store, PresentationAction>.scope - Store, PresentationAction>.scope + PresentationStoreOf.scope + PresentationStoreOf.scope StoreOf.init StoreOf.init + StoreOf.deinit + StoreOf.init + StoreOf.init + StoreOf.init + StoreOf.init + StoreOf.init StoreOf.scope StoreOf.scope """ @@ -102,14 +102,14 @@ final class PresentationTests: BaseIntegrationTests { self.assertLogs { """ BasicsView.body + PresentationStoreOf.scope + PresentationStoreOf.scope PresentationView.body - Store.scope - Store.scope - Store.scope - Store.scope - Store, PresentationAction>.scope - Store, PresentationAction>.scope StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope StoreOf.scope StoreOf.scope """ @@ -118,23 +118,23 @@ final class PresentationTests: BaseIntegrationTests { self.app.buttons["Dismiss"].firstMatch.tap() self.assertLogs { """ + PresentationStoreOf.scope + PresentationStoreOf.scope PresentationView.body - Store.deinit - Store.deinit - Store.deinit - Store.deinit - Store.deinit - Store.init - Store.scope - Store.scope - Store.scope - Store.scope - Store.scope - Store, PresentationAction>.scope - Store, PresentationAction>.scope StoreOf.deinit StoreOf.deinit StoreOf.scope + StoreOf.deinit + StoreOf.deinit + StoreOf.deinit + StoreOf.deinit + StoreOf.deinit + StoreOf.init + StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope + StoreOf.scope StoreOf.scope StoreOf.scope StoreOf.scope diff --git a/Sources/ComposableArchitecture/Store.swift b/Sources/ComposableArchitecture/Store.swift index 896240a3b734..2443237b840d 100644 --- a/Sources/ComposableArchitecture/Store.swift +++ b/Sources/ComposableArchitecture/Store.swift @@ -889,12 +889,27 @@ private func typeName(of store: Store) -> String { let stateType = typeName(State.self, genericsAbbreviated: false) let actionType = typeName(Action.self, genericsAbbreviated: false) // TODO: `PresentationStoreOf`, `StackStoreOf`, `IdentifiedStoreOf`? - // `StoreOf` if stateType.hasSuffix(".State"), actionType.hasSuffix(".Action"), stateType.dropLast(6) == actionType.dropLast(7) { return "StoreOf<\(stateType.dropLast(6))>" + } else if stateType.hasSuffix(".State?"), + actionType.hasSuffix(".Action"), + stateType.dropLast(7) == actionType.dropLast(7) + { + return "StoreOf<\(stateType.dropLast(7))?>" + } else if stateType.hasPrefix("PresentationState<"), + actionType.hasPrefix("PresentationAction<"), + stateType.dropFirst(18).dropLast(7) == actionType.dropFirst(19).dropLast(8) + { + return "PresentationStoreOf<\(stateType.dropFirst(18).dropLast(7))>" + } else if stateType.hasPrefix("StackState<"), + actionType.hasPrefix("StackAction<"), + stateType.dropFirst(11).dropLast(7) + == actionType.dropFirst(12).prefix(while: { $0 != "," }).dropLast(6) + { + return "StackStoreOf<\(stateType.dropFirst(11).dropLast(7))>" } else { return "Store<\(stateType), \(actionType)>" }