Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modernize composable architecture syntax #77

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Example/Example/Home Screen/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))
}
}
}
Expand All @@ -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)))
}
}
}
Expand Down Expand Up @@ -218,7 +219,7 @@ let homeReducer = Reducer<
environment: \.detail
)
)
.binding(action: /HomeAction.binding)
.binding()

struct HomeView_Previews: PreviewProvider {
static var previews: some View {
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down