You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've recently started using the @DependencyClient and @DependencyEndpoint macros to avoid having to write a lot of boilerplate in my dependencies. However I find myself wishing for more control over the endpoint methods that are created.
So far the main things I wish I could influence the macro over are:
Make an endpoint a property rather than a function:
Eg, given:
@DependencyClientpublicstructRegionService:Sendable{
/// Access to the currently chosen region.
publicvarregion:@Sendable()->Region={.global }
/// Changes the currently chosen region.
publicvarsetRegion:@Sendable(Region)->Void
/// Publishes changes to the chosen region.
publicvarregionPublisher:@Sendable()->AnyPublisher<Region,Never>={Just(.global).eraseToAnyPublisher()}}
It would be great to be able to somehow specify that these endpoints where the get and set side of a property. Or even just to make the regionPublisher endpoint a property. At the moment there is no easy way of doing this without writing out all the code myself. Maybe this is intentional but it does mean when I convert existing code to use @DependencyClient I'm having to modify a lot of call sites to include ().
I see that control over properties has been previously requested: #270
Add additional attributes to an endpoint. In particular @discardableResult.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I've recently started using the
@DependencyClient
and@DependencyEndpoint
macros to avoid having to write a lot of boilerplate in my dependencies. However I find myself wishing for more control over the endpoint methods that are created.So far the main things I wish I could influence the macro over are:
Make an endpoint a property rather than a function:
Eg, given:
It would be great to be able to somehow specify that these endpoints where the get and set side of a property. Or even just to make the
regionPublisher
endpoint a property. At the moment there is no easy way of doing this without writing out all the code myself. Maybe this is intentional but it does mean when I convert existing code to use@DependencyClient
I'm having to modify a lot of call sites to include()
.I see that control over properties has been previously requested: #270
Add additional attributes to an endpoint. In particular
@discardableResult
.Eg, given:
What I'd like is for the generated endpoint method to be:
But at the moment I can't do this. Anyway, maybe I'm just "holding it wrong" but I feel like more control over the generated endpoints would be nice.
Beta Was this translation helpful? Give feedback.
All reactions