Replies: 1 comment 2 replies
-
|
Hey @Jeehut! As an alternative, there is a
Please also note that you can define the |
Beta Was this translation helpful? Give feedback.
2 replies
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.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm in the middle of cleaning up my project and migrating over to the
Reducerprotocol & modern navigation (TCA 1.0). While doing that, I found myself in a situation where I extracted some SwiftUI code into a helper function which needed to be able to send back actions, but that doesn't need to observe any state.In particular, the situation was the
.commandsmodifier on aWindowGrouplike this:I wasn't sure how to specify in the
observe:parameter that I don't need any state at all. Also, I need to specify aViewStoretype for the parameter passed to my helper function, but it wasn't clear what to use there:Returning
()didn't work (as it's not Equatable), so I figured I'd need to provide an empty state type and initialize it here. Then I thought, this might be useful in other places as well, basically whenever aViewStoreis created for the sole purpose of providing a way tosendactions into the system, such as an extracted view with only buttons.So I created a
NoStatetype and also some convenience along it to make specifying a type for the parameter easy, too:With this code, specifying and calling an extracted helper function is as easy as:
What do you think? Did I overlook a much easier solution to my problem? If not, is there any interest in including this into TCA directly and shipping it as built-in types? If yes, I'd be available to add more documentation and send a PR. Else, feel free to copy & paste if you need it as well.
P.S. I considered
noStatefor the name of the computed property instead ofnothing, which might be confusing when available on allEquatabletypes. If you know a better way to provide it only in the context of states, I could restrict it that way. If there's no better idea, we should maybe rename the property tonoStatewhen shipped as part of the lib.Beta Was this translation helpful? Give feedback.
All reactions