Skip to content
Discussion options

You must be logged in to vote

Hi @mrackwitz, I think I'm a little confused with this definition of the reducer:

struct BarFeature: Reducer {
  typealias State = BarState
  var id: BarId}

Why does BarFeature need an ID when state.id is available? Doesn't this even open up the possibilities of invalid data where self.id != state.id?

If you got rid of the id on BarFeature then you would just use the dependency by accessing the ID directly on state:

case .baz:
  return .run { [id = state.id] send in
    let x = await baz.getX(for: id)
    send(.setX(x))
  }

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@mrackwitz
Comment options

Answer selected by mrackwitz
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