Replies: 1 comment
-
Hello!
The first case correspond roughly to your solution, where you pass the information through The other option is to try to see if you can extract struct CView<Content: View>: View {
let content: Content
let store: Store<C>
init(store: Store<C>, @ViewBuilder () -> Content) {
self.store = store
self.content = content()
}
var body: some View {
VStack {
WithViewStore(store) { viewStore in
Text(store.localizedAgreement)
Button {
viewStore.send(.readMore) }
} label: {
Text("Read more…")
}
}
content
}
}
} Coming from struct C_B {
var c: C
var d: D?
} In struct C_BView: View {
let store: Store<C_B>
var body: some View {
CView(store.scope(C)) {
WithViewStore(store) { viewStore in
NavigationLink(isActive: viewStore.dIsNotNilBinding) {
IfLetStore(store.scope(D)) { dStore in
DView(store: dStore)
}
}
label: {
Text("Agree and go to D")
}
}
}
}
} If You can also maybe use the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I use optional paths + route pattern in my project.
Navigation paths are A-B-C-D and A-E-F-C-G.
C is common state and view(Agreement) and used in many paths.
D and G need many state to make a request to a server.
Necessary information comes from A, but to generate D and G in reducerC, C need to have unnecessary state. (B and E too)
in reducerC )
case .goD:
state.route = .d(DState(
param1: state.param1,
param2, state.param2
))
So CState goes messy over time.
To avoid this, I captured the action from Ancestor. and pass parameter via action.
in reducerA )
case .b(.c(.goD)):
return Effect(value: .b(.c(.goDFromAncestor(state.param1, state.param2)):
in reducerC)
case .goDFromAncestore(param1, param2)):
state.route = .d(DState(
param1: param1,
param2: param2
))
By using the pattern, CState can be keep clearly.
Is it right approach?
This patters can only work in TCA, not a vanilla SwiftUI. So I confused.
Beta Was this translation helpful? Give feedback.
All reactions