Skip to content

How to differentiate and pin-point a deep-embedded reducer's @Dependency and override it? #1589

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

You must be logged in to vote

Hi @ylorn, we mention this briefly in our Reducer Protocol in Practice episode (~42:58), but it seems like reusable components don't necessarily need to leverage the @Dependency system. And sometimes probably shouldn't.

Instead, the ReusableDualTextFields should probably take its two validation dependencies explicitly, like in the old days of environment:

struct ReusableDualTextFields: ReducerProtocol {
  let validator1: Validator
  let validator2: Validator}

And then at the moment of creating ReusableDualTextFields you can specify which validator to use:

ReusableDualTextFields(
  validator1: { $0.count > 5 },
  validator2: { $0.count < 3 }
)

There's a chance that Validator doesn't …

Replies: 3 comments 5 replies

Comment options

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

Comment options

You must be logged in to vote
4 replies
@ylorn
Comment options

@mbrandonw
Comment options

@mbrandonw
Comment options

@ylorn
Comment options

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