I assume this is how "pullback" is done in the new Reducer Protocol, please correct me if I'm wrong.
This is the ProductDomain (Parent) and its SwiftUI View which takes the StoreOf property of type ProductDomain.
struct ProductDomain: ReducerProtocol {
struct State: Equatable {
var addToCartDomainState: AddToCartDomain.State
}
enum Action {
case addToCartDomain(AddToCartDomain.Action)
}
var body: some ReducerProtocol<State, Action> {
๐[๐คจ: Is this how scope is done in Swift?]
Scope(
state: \.addToCartDomainState,
action: /Action.addToCartDomain) {
AddToCartDomain()
}
}
}
This is ProductCard SwiftUI View
struct ProductCard: View {
let store: StoreOf<ProductDomain>
var body: some View {
WithViewStore(store, observe: { $0 }, content: { viewStore in
HStack(alignment: .center) {
AddToCart(
store: store.scope(state: \.addToCartDomainState)
)
๐[โ๏ธ: this gives an Error]
๐[๐คจ: Is this how scope is done in SwiftUI?]
}
}
}
}
Hint: Error description
Cannot convert value of type 'Store<AddToCartDomain.State, ProductDomain.Action>' to expected argument type 'StoreOf' (aka 'Store<AddToCartDomain.State, AddToCartDomain.Action>')
This is AddToCart SwiftUI view (Child View)
struct AddToCart: View {
let store: StoreOf<AddToCartDomain>
var body: some View {
WithViewStore(store, observe: { $0 }, content: { viewStore in
...
}
}
}
This is AddToCartDomain (Child Domain)
struct AddToCartDomain: ReducerProtocol {
struct State: Equatable {
...
}
enum Action: Equatable {
case didTapAddToCartButton
case didTapPlusButton
case didTapMinusButton
}
func reduce(into state: inout State, action: Action) -> EffectTask<Action> {
switch action {
...
}
}
}