Observable Raw types in Presentation States in TCA – Can We Simplify with a Generic OptionalReducer? #3598
OguzYuuksel
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm exploring a design where certain features are optional, same as presentation states. For instance, in the code below, I have an optional state property along with a corresponding action wrapped in a presentation-specific type:
The Issue
The challenge arises when trying to bind an optional substate via a scoped store. The binding requirements (
_StoreBindable_SwiftUI<State: ObservableState, Action, Value>
) aren’t met because:Binding
type doesn't havesending
method and we can't scope toBindable
protocol.String
isn’t treated as anObservableState
.This forces us into writing extra boilerplate—wrapping each optional state in a sub-reducer—to get the bindings to work correctly. In a codebase with many such optional features, this can quickly lead to an overwhelming amount of repetitive code.
Proposed Discussion Points
Generic OptionalReducer:
Would it be feasible to introduce a generic solution (e.g.,
OptionalReducer<V>
) within TCA that could automatically handle the nuances of optional presentation states? This could help reduce boilerplate significantly.Alternative Patterns:
Are there any existing patterns or best practices in TCA that can elegantly manage optional state bindings without resorting to manually creating numerous sub-reducers?
I'm eager to hear insights from others who may have encountered similar challenges or have suggestions on how to approach this issue more elegantly within the TCA. Any feedback, alternative solutions, or discussions on potential impacts would be greatly appreciated!
Beta Was this translation helpful? Give feedback.
All reactions