-
I have a few questions about how to use TCA's new support for For example, enum Feature: Equatable {
case first(FirstFeature)
case second(SecondFeature)
}
struct Root: Equatable {
var feature: Feature = .first(FirstFeature())
// Other properties
}
enum RootAction: Equatable {
...
case firstFeature(action: FirstFeatureAction)
case secondFeature(action: SecondFeatureAction)
}
struct Environment { ... }
struct FirstFeature: Equatable { ... }
enum FirstFeatureAction: Equatable { ... }
struct SecondFeature: Equatable { ... }
enum SecondFeatureAction: Equatable { ... }
let firstFeatureReducer = Reducer<FirstFeature, FirstFeatureAction, Environment> { ... }
let secondFeatureReducer = Reducer<FirstFeature, FirstFeatureAction, Environment> { ... }
let rootReducer = Reducer<Root, RootAction, Environment>.combine(
firstFeatureReducer.pullback(
state: ???,
action: /Root.firstFeature,
environment: { $0 }
),
secondFeatureReducer.pullback(
state: ???,
action: /Root.secondFeature,
environment: { $0 }
),
Reducer { ... }
) I asked on Twitter and your suggestion was to use two pullbacks, which I believe means I should do the following: firstFeatureReducer
.pullback(
state: /Feature.first,
action: /RootAction.firstFeature,
environment: { $0 }
)
.pullback(
state: \.feature,
action: /.`self`,
environment: { $0 }
) This seems to accomplish what I want, so thank you.
Please let me know if you'd like anything clarifying. Thank you |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Yeah this is exactly right. In a future release of TCA and swift-case-paths you will be able to collapse that into a single
Ah yes, one option is to open a closure to do the extraction of the case: .onChange(of: { (/Feature.first).extract(from: $0.feature) }) { ... } That's a bit intense, but it should work. Alternatively you could define a getter computed property
We don't have much information out there about this yet unfortunately. We will have more to say about it soon. |
Beta Was this translation helpful? Give feedback.
Yeah this is exactly right. In a future release of TCA and swift-case-paths you will be able to collapse that into a single
pullback
by appending a case path to a key path.Ah yes, one option is to open a closure to do the extraction of the case:
That's a bit intense, but it should work. Alternatively you could define a getter computed property
var first: FirstFeature?
onFeature
to do the extraction.