This would be really great – now that we're able to use property wrappers in function and closure parameters, this would go even further in improving the model. For instance, this could become a really valuable feature for @mbrandonw's and @stephencelis 's Composable Architecture which is becoming increasingly popular (and for good reason!). For SwiftUI views, in TCA you pass down the store as a property, and then at each view create a "view store" which chisels away the store and the store's state to the bare essentials a view needs to do the job, for both ergonomics and performance. You can either do this using WithViewStore
, or by using an @ObservedObject var viewStore
and custom initialisation logic.
However, both of these methods have their own issues, which are talked about in this thread. If we were able to defer initialization like proposed here, a new and really expressive syntax could be enabled:
@ViewStore(state: ViewState.init) var store: Store<AppState, AppAction>
or
@ViewStore(state: \.someState, action: AppAction.someAction) var store: Store<AppState, AppAction>
while being able to pass down the store from the parent view.
As @hborla specified, this hopefully should be straightforward to implement, and could enable some really great APIs.
Big +1