From 3ccf06f4e02cf1bbc726a5052d9f90b67503671f Mon Sep 17 00:00:00 2001 From: Zev Eisenberg Date: Tue, 2 Nov 2021 16:47:53 -0400 Subject: [PATCH 1/2] Use @BindableState and BindableAction to modernize composable architecture usage. --- Example/Example/Home Screen/HomeView.swift | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Example/Example/Home Screen/HomeView.swift b/Example/Example/Home Screen/HomeView.swift index 78b9266..efa1563 100644 --- a/Example/Example/Home Screen/HomeView.swift +++ b/Example/Example/Home Screen/HomeView.swift @@ -5,10 +5,11 @@ import SwiftUI struct HomeState: Equatable { var elements: [String] + @BindableState var selectedDetail: DetailState? } -enum HomeAction: Equatable { +enum HomeAction: Equatable, BindableAction { case viewAppeared case selected(element: String, on: ScreenID) case openSettings(for: String, on: ScreenID) @@ -144,7 +145,7 @@ struct HomeScreen: Screen { let viewStore = ViewStore(homeStore) // Only if the current detail state represents the dismissed screen, set the state to nil. if viewStore.state.selectedDetail?.id == screen.detailID { - ViewStore(homeStore).send(.binding(.set(\.selectedDetail, nil))) + ViewStore(homeStore).send(.set(\.$selectedDetail, nil)) } } } @@ -154,7 +155,7 @@ struct HomeScreen: Screen { // we do not navigate to invalid navigation paths (i.e. example://detail?id=123) if viewStore.elements.contains(screen.detailID), viewStore.state.selectedDetail?.id != screen.detailID { - viewStore.send(.binding(.set(\.selectedDetail, DetailState(id: screen.detailID)))) + viewStore.send(.set(\.$selectedDetail, DetailState(id: screen.detailID))) } } } @@ -218,7 +219,7 @@ let homeReducer = Reducer< environment: \.detail ) ) -.binding(action: /HomeAction.binding) +.binding() struct HomeView_Previews: PreviewProvider { static var previews: some View { From 09f9899fb75493add10da49ccb01d8e0d41f853f Mon Sep 17 00:00:00 2001 From: Zev Eisenberg Date: Wed, 3 Nov 2021 10:04:32 -0400 Subject: [PATCH 2/2] Bump TCA to 0.28.0+. --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index a8bc788..25e105f 100644 --- a/Package.swift +++ b/Package.swift @@ -43,7 +43,7 @@ let package = Package( .package( name: "swift-composable-architecture", url: "https://github.com/pointfreeco/swift-composable-architecture", - from: "0.7.0" + from: "0.28.0" ), .package(url: "https://github.com/shibapm/Rocket", from: "1.1.0"), // dev .package(name: "SnapshotTesting", url: "https://github.com/pointfreeco/swift-snapshot-testing.git", from: "1.8.2"), // dev