Created
July 28, 2023 07:38
-
-
Save saroar/5dc08306b7dbc99a17740fb69db9032c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import ComposableArchitecture | |
public struct AppFeature: ReducerProtocol { | |
public struct State: Equatable { | |
var path = StackState<Path.State>() | |
var articlesList = ArticleListReducer.State() | |
} | |
public enum Action: Equatable { | |
case path(StackAction<Path.State, Path.Action>) | |
case articlesList(ArticleListReducer.Action) | |
} | |
public init() {} | |
public var body: some ReducerProtocolOf<Self> { | |
Scope(state: \.articlesList, action: /Action.articlesList) { | |
ArticleListReducer() | |
} | |
Reduce<State, Action> { state, action in | |
switch action { | |
case .path: | |
return .none | |
case .articlesList: | |
return .none | |
} | |
} | |
.forEach(\.path, action: /Action.path) { | |
Path() | |
} | |
} | |
public struct Path: ReducerProtocol { | |
public enum State: Equatable { | |
case detail(ArticleDetail.State) | |
} | |
public enum Action: Equatable { | |
case detail(ArticleDetail.Action) | |
} | |
public init() {} | |
public var body: some ReducerProtocolOf<Self> { | |
Scope(state: /State.detail, action: /Action.detail) { | |
ArticleDetail() | |
} | |
} | |
} | |
} | |
import SwiftUI | |
public struct AppFeatureView: View { | |
let store: StoreOf<AppFeature> | |
public init(store: StoreOf<AppFeature>) { | |
self.store = store | |
} | |
public var body: some View { | |
NavigationStackStore( | |
self.store.scope( | |
state: \.path, | |
action: { .path($0) } | |
) | |
) { | |
ArticleListView( | |
store: self.store.scope(state: \.articlesList, action: { .articlesList($0) }) | |
) | |
} destination: { state in | |
switch state { | |
case .detail: | |
CaseLet( | |
state: /AppFeature.Path.State.detail, | |
action: AppFeature.Path.Action.detail, | |
then: ArticleRowView.init(store:) | |
) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment