hmlongco / Factory

A new approach to Container-Based Dependency Injection for Swift and SwiftUI.
MIT License
1.7k stars 107 forks source link

Support @Bindable with @Injected property wrappers #175

Closed cneuwirt closed 5 months ago

cneuwirt commented 6 months ago

Are there any plans to support @Bindable attribute on @Injected properties. I need the ability to access these bindings so use Combine publisher combinators.

e.g.

I have the following @Bindable @Injected(.stateController) private(set) var stateController

However, I get an error "Type annotation missing in pattern"

I need to access it like Publishers.CombineLatest4(stateController.$schedules, ...

hmlongco commented 6 months ago

You probably need to insert the bindable object in the view body, similar to how you need to handle using observation with environment.

cneuwirt commented 6 months ago

Ok, I'll investigate. I actually think it is a current consequence (limitation) of using the new @Observable macro. The removal of @Binding requirement on properties requires creating explicit Publishers if needed for Combine subscriptions.

hmlongco commented 5 months ago

Just forgo the onReceive handler and use onChange(of:).