Store action, state and environment type declaration #397
-
Hi @stephencelis @mbrandonw 👋 I see that you declare struct FooState {}
struct Foo: View {
let store: Store<FooState, ...>
} What is the motivation behind this? What about declaring them instead inside the extension Foo {
struct State {}
}
struct Foo: View {
let store: Store<State, ...> // <- Foo prefix is implicit
} The pros of this approach are:
And the potential cons can be:
Following up on the reducer point:
Last but not least, what is the performance tradeoff in global vs scoped extension declarations? I think your current approach works really well and is consistent, but sometimes the Thanks 🙌 |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 10 replies
-
You can get the same results but without nesting in extensions by using a module per screen which is easily achieved with SPM. In you feature you can then use State, Action, reducer, Environment and Screen (instead of view to avoir conflicts with SwiftUI). One nice addition to this is you can import only what you need like import enum Feature.Action which can be convenient. |
Beta Was this translation helpful? Give feedback.
-
Without debating about pros and cons of the "extension" setup, in my TCA Views, I generally use typealiases for State and Action: struct FeatureView: View {
typealias State = FeatureState
typealias Action = FeatureAction
let store: Store<State, Action>
…
It is then very convenient to use |
Beta Was this translation helpful? Give feedback.
-
There are a few reasons we like defining the domain of a feature outside of its view:
We still like to define reducers at the module-level for apps/features. We occasionally define reducers in extensions of the
I think Swift uses a "dispatch once"-like mechanism for both when they are constants.
I'm not aware of any 😄 We go into these particular concepts in further depth in some of the Point-Free episodes, particularly the sections on modularity and adaptation. And I'm sure we'll dive deeper into things in the future! |
Beta Was this translation helpful? Give feedback.
There are a few reasons we like defining the domain of a feature outside of its view: