I use 2 common cases where I want to cancel all effects including child action or own action triggered through another own action:
let mainReducer = Reducer { state, action, _ in
action {
...
case .child(id: id, action: .delete):
state.childStates.remove(id: id)
return .none
}
}
let childReducer = Reducer { state, action, _ in
struct Id: Hashable {}
struct AnotherId: Hashable {}
action {
...
case .cancel:
return Effect.cancel(id: AnotherId())
case .delete:
return Effect.concatenate(
Effect(value: .cancel), // Wont trigger
Effect(value: .child(.cancel)), // Wont trigger
Effect.cancel(id: Id()) // Works
)
}
}
Then if I trigger .delete
action by some listener or notification (example). In the console, I'll have something like
"child(.cancelSome)" was received by a "forEach" reducer at id "xxx-xxx-xxx" when its state contained no element at this id. This is considered an application logic error, and can happen for a few reasons..**
"child(.child(.cancel))" was received by a "forEach" reducer at id "xxx-xxx-xxx" when its state contained no element at this id. This is considered an application logic error, and can happen for a few reasons..**
How to solve this?