Optional paths? #1309
Replies: 1 comment 2 replies
-
Good question! While we're open to introducing optional paths to the Case Paths library, we aren't really happy with the current API, which is simple and works, but is also inflexible compared to Swift's native key paths (no ability to erase, loss of reference-writability, etc.). We also think that ideally case paths and optional paths work their way into the language natively.
We think that some of the APIs we've sketched out will make optional paths much less needed, particularly around navigation. The primary uses of optional paths in isowords were for navigation, where we have layers of optional enum state that need to be unwrapped. If navigation is the primary use for optional paths, we think it might be better to design navigation APIs explicitly around this nested shape. In fact, this is a learning we employed in SwiftUI Navigation, where we separate the optional route endpoint from routing case path: These We're designing TCA navigation APIs with this same consideration in mind, and so we do think we can hold off on shipping optional paths. How are you using optional paths in your application? Is it primarily around navigation or have you found other uses? |
Beta Was this translation helpful? Give feedback.
-
We've been using the OptionalPaths helper for a while and I was wondering if there was any plans to ship with support for this with the final protocol reducers release or if the need for this is made redundant somehow by newer APIs?
If it helps anyone, this is what I came up with to add support for OptionalPaths using a pre-beta branch of protocol reducers when I experimented with it. It will likely need some tweaking and renaming to make it fit with the beta:
Beta Was this translation helpful? Give feedback.
All reactions