Replies: 3 comments 1 reply
-
@captadoh The TCA analogue to your "services" is its dependency layer, which is powered by swift-dependencies. You should be able to model each of your services as a dependency that TCA features can access using the TCA features (reducers) are typically broken down per screen, so if you can share a more concrete example of how you are picturing using reducers we can maybe give more guidance.
Because reducers are typically broken down by screen, recursion is typically handled via stack navigation, which TCA ships tools for: https://pointfreeco.github.io/swift-composable-architecture/main/documentation/composablearchitecture/stackbasednavigation
A dependency can access another dependency, so this should work just fine, but let us know if you run in to concrete problems and we can help out. And if you haven't already, I'd check out the various demo apps in the repo to see how reducers can be designed, how they use dependencies, etc. |
Beta Was this translation helpful? Give feedback.
-
Hi Stephen - thanks for the prompt response! Before I dive into the rewrite one more quick question: has anyone used TCA for the backend and for some front end? Let me explain.
A user button tap would send a user action to the store... could I have TCA Feature A (not from a user tap / interaction) send an action to TCA Feature B's store? Maybe that is what you were talking about when you mentioned using dependencies? Im asking this because I have functionality / logic that happens behinds the scenes and isn't directly connected to a screen. For example the user can navigate to my settings screen, toggle ON voice control (which starts up speech recognition) and then they can leave to a different screen. The speech recognition is listening for keywords to then automatically take action. So my VoiceControlFeature/Service would recognize a keyword and then send an action to the NetworkingFeature/Service to do XYZ. In this case there is no user interaction (user tapping that is) but I need to send an action. I really like how you guys break things up into State, Action, Reducer and Store. Id love to use that structure for both screen related features and also for features / services that don't necessarily have a screen. |
Beta Was this translation helpful? Give feedback.
-
@stephencelis I've done more research on what I'm looking for and I believe it boils down to the following (let's assume I'm using MVVM for this): Terminology
Questions
An example is as follows: Setup
Scenario
In my mind having an event bus would be my silver bullet. I know this may be naive but it helps all the pieces fit together in my head. This event bus can be used by view models and services. If something happens in a service that is important to other services and or other view models then that service would just publish the event and everyone who cares would have subscribed to that event. To continue on this - I've been thinking of using https://github.com/pointfreeco/swift-sharing as a down and dirty event bus... I would have a StateService that has many I'd appreciate your insight on using swift-sharing as a type of event bus as well how TCA can meet my needs. Thank you. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
First off thanks for making TCA 🤙 - I'm existed to start rewriting my app in it.
Currently my app consists of many Services (ie UserService, NetworkOfflineService, NetworkingService ... etc) that talk to each other by me doing dependency injection either in the constructor or via each service's "injectDependencies" function.
Each service has some ephemeral state that clears when the app closes and some persisted state via UserDefaults.
Things were getting messy, confusing and complex... which led me to research a better way... enter TCA.
I have read a lot of your docs, watched a lot of your videos and believe I have a rough handle on how things work. I especially love the idea of sharing state backed by UserDefaults.
Questions:
In my UserService I have the following functionality:
In my NetworkOfflineService I have the following functionality:
In my NetworkingService I have the following functionality:
Generally - each Service has some persisted state and some ephemeral state and needs to talk to N number of other services.
Trying to translate that mental model / design over the TCA I see that I can achieve that by:
Question:
Regards,
Captadoh
Beta Was this translation helpful? Give feedback.
All reactions