Replies: 3 comments 2 replies
-
Great idea, just beware of a Swift bug causing the runtime crash when accessing the associated value of enum accesses through the protocol: https://bugs.swift.org/browse/SR-14071. I’ve been hit by this one when doing similar refactor. |
Beta Was this translation helpful? Give feedback.
-
This is definitely cool! I think we probably want to err on the side of not including protocols like these in the main library, but it definitely is handy enough that people might be interested in a micro-library or blog post. If you end up fleshing something out please do share with us! Originally we sketched out a text: viewStore.binding(\.displayName) But in practice view stores do more than simple form actions, so it didn't seem practical enough to ship with TCA. What we think this points to is the deficiency in Swift not having a "dynamic member lookup" for enum cases. If it did we could potentially leverage it here. Edit: I think we will at the very least kick the tires a bit and see how such a protocol feels. We're usually cautious to use protocols in this way but it may prove fruitful. |
Beta Was this translation helpful? Give feedback.
-
Just wanted to throw in that someone tweeted about this exact idea, and they also encountered the Swift bug that @siejkowski linked to :( https://twitter.com/monadic_nomad/status/1356762575023792128 |
Beta Was this translation helpful? Give feedback.
-
Awesome work on the latest form-handling release! I always love removing boilerplate. :D
I realized that every time a binding is used with the new FormAction,
LocalAction.form
is passed in. I wonder if we can add a protocol the get rid of this boilerplate?Then, any action that handles forms can conform to this, and
case form(FormAction<State>)
would fulfill the protocol requirements. Then, a conditional extension onViewStore
could be made that removes the extra action argumentwhere Action: FormActionHandling
. This would remove the need to typeLocalAction.form
all over, but you would still be handling mutation explicitly in the reducer. You could also add an override onReducer.form()
where theAction
conforms toFormActionHandling
.Thoughts? I'd be more than happy to draw up a PR for this if it seems like something that could be useful.
Beta Was this translation helpful? Give feedback.
All reactions