Defining Properties on the Feature/Reducer #1706
jagreenwood
started this conversation in
General
Replies: 1 comment 1 reply
-
I have found this pattern important/needed in order to utilize dependencies that are needing to use protocols. This is my example client: public protocol JwtClient {
func decode<T: Codable>(_ token: String) async throws -> Result<T, JwtFailure>
} This client needs to be defined as a protocol otherwise it would need to implement every concrete type individually which would loose a TON of usability. This is because Swift properties cannot be generic but functions can be. The feature would require the initializer with this injection: struct SomeFeature: ReducerProtocol {
let jwtClient: JwtClient
init(jwtClient: JwtClient) {
self.jwtClient = jwtClient
}
} I think this should only be used for dependencies that cannot be included using |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
With the introduction of a top level type which conforms to
ReducerProtocol
, I'm curious about thoughts related to defining properties on this type itself.Take for instance this simplified feature:
detailID
doesn't need to be tested or exposed to the view via theViewStore
. Taken too far I can see this as an anti-pattern, but with smaller intentional uses, is it a valid pattern?Beta Was this translation helpful? Give feedback.
All reactions