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 have sometimes found the need to derive Shared-State from an existing SwiftUI-Binding. For example, if I want to expose my feature to API-consumers that do not know about swift-sharing and just want to interact via a binding. I can bridge the two with onChange(of:), but this seems cumbersome and error-prone. It would be great if this hypothetical API would work:
I think this would be a useful addition to the library, especially for people who want to migrate an existing codebase stepwise to swift-sharing.
I took at stab at implementing it, but I'm not sure if this approach is sound and also I'm not sure if the id can somehow be derived automatically from the Binding. I know there were some past discussions about this topic, especially with bindings from computed properties in relation to those derived from keypaths. This is my current implementation:
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
Uh oh!
There was an error while loading. Please reload this page.
-
I have sometimes found the need to derive Shared-State from an existing SwiftUI-Binding. For example, if I want to expose my feature to API-consumers that do not know about swift-sharing and just want to interact via a binding. I can bridge the two with
onChange(of:), but this seems cumbersome and error-prone. It would be great if this hypothetical API would work:I think this would be a useful addition to the library, especially for people who want to migrate an existing codebase stepwise to swift-sharing.
I took at stab at implementing it, but I'm not sure if this approach is sound and also I'm not sure if the
idcan somehow be derived automatically from the Binding. I know there were some past discussions about this topic, especially with bindings from computed properties in relation to those derived from keypaths. This is my current implementation:Any feedback would be welcome.
Beta Was this translation helpful? Give feedback.
All reactions