Skip to content

Why is Parent reducer getting actions of its Child? #1563

Answered by mbrandonw
iMarti asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @iMarti, what you have is close. While you are correctly transforming stores by using the .scope operator, the key concept you are missing is reducer composition. You have a child reducer (AddSourceReducer) and a parent reducer (SourcesReducer) that contains the child reducer, and you need to express that fact by composing the reducers together.

You can do this using the Scope operator along with reducer builders. In your SourcesReducer you can implement its logic with a body property, which allows you to compose multiple reducers together:

struct SourcesReducer: ReducerProtocol {
  

  var body: some ReducerProtocol<State, Action> {
    Scope(state: \.sourceToAdd, action: /Action.add…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@iMarti
Comment options

@mbrandonw
Comment options

@iMarti
Comment options

Answer selected by iMarti
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants