Skip to content

Creating a list view with sections #907

Answered by tgrapperon
corysullivan asked this question in Q&A
Discussion options

You must be logged in to vote

There are several ways to solve your problem, but I would go with the simplest when using TCA: composing features.

I would introduce an intermediary "categorized products" feature, with CategorizedProducts as a state, a CategorizedProductsAction, a CategorizedProductsEnvironment and a categorizedProductsReducer. You can also define a SwiftUI CategorizedProductsView that presents the flat list of products it contains1.

You embed the productReducer in categorizedProductsReducer using forEach. Because the "product" feature has no knowledge of its outside world, it doesn't have to change its internals when it is embedded in a "categorized products" feature.

Each "categorized products" feature…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@corysullivan
Comment options

Answer selected by corysullivan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants