Questions about Nested State usage #2984
-
The SceneView A contains View B, when View A's The Reducer looks likeViewBFeat.swift@Reducer
struct ViewBFeat {
@ObservableState
struct State: Equatable {
var y: Float = 0
}
enum Action {
case reset
}
var body: some ReducerOf<Self> {
Reduce { state, action in
switch action {
case .reset:
state.y = 0
return .none
}
}
}
ViewAFeat.swift@Reducer
struct ViewAFeat {
@ObservableState
struct State: Equatable {
var viewB: ViewBFeat.State = .init()
var x: Float = 0
}
enum Action {
case viewB(ViewBFeat.Action)
case reset
}
var body: some ReducerOf<Self> {
Scope(state: \.viewB, action: \.viewB) {
ViewBFeat()
}
Reduce { state, action in
switch action {
case .reset:
state.x = 0
// Can we trigger ViewBFeat's reset action here? how?
return .none
default:
return .none
}
}
}
My question isCan we trigger ViewBFeat's reset action inside ViewAFeat? how? Wish you a good day! |
Beta Was this translation helpful? Give feedback.
Answered by
kevinanderson7
Apr 12, 2024
Replies: 1 comment 6 replies
-
Currently, I am proceeding in this manner, which seems somewhat inelegant. store.send(.reset)
store.scope(state: \.viewB, action: \.viewB).send(.reset) |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That's one way to go about it. Or you could declare a mutating func as part of ViewBFeat.State and then call it from ViewAFeat. Something like this: