-
Reference: #1952 (comment) extension Child.State {
mutating func playCurrent() -> Effect<Child.Action> {
self.index = self.index + 1
return .run { send in
await send(.play) // **this code is not called. why?**
}.cancellable(id: SubtitleCore.CancelID.play, cancelInFlight: false)
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
mbrandonw
Sep 5, 2023
Replies: 1 comment 7 replies
-
The log "print("Child action is called")" is not called, why? struct Parent: Reducer{
struct State{
var child: Child.State
}
enum Action {
case triggerChildAction
case child(action: Child.Action)
}
var body: some Reducer<State, Action> {
Reduce { state, action in
switch action {
case .triggerChildAction:
// From Parent Reducer, call Child action by its playCurrent() function
state.child.playCurrent()
return .none
case .child(action: let action):
return .none
}
}
}
}
extension Child.State {
mutating func playCurrent() -> Effect<Child.Action> {
return .run { send in
await send(.play)
}
.cancellable(id: Child.CancelID.play, cancelInFlight: true)
}
}
struct Child: Reducer{
struct State{
}
enum Action {
case play
}
private enum CancelID { case play }
var body: some Reducer<State, Action> {
Reduce { state, action in
switch action {
case .play:
print("Child action is called")
return .none
}
}
}
} |
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you just want to affect the first, then you need to get the ID of the first element:
I recommend reading the docs for IdentifiedArray to better understand how to use that type.