Replies: 2 comments 4 replies
-
Because you mention "previous state of the library", I assume that you are talking about using Dependencies in TCA. I tried to experiment with similar situation and could not find any solution which is not clunky. Therefore my conclusion was that |
Beta Was this translation helpful? Give feedback.
-
I approached this by keeping my shared tracker using freeform data:
I can then implement this client using my analytics engine of choice in a separate impl module. Then, to get type safety I create a protocol to structure the data:
and an extension on
Now I can define my events local to each module without any need to override the environment. |
Beta Was this translation helpful? Give feedback.
-
I have a question regarding a limitation of shared dependencies.
Usually, if you have a dependency that is used by multiple features, you can move it to a proper module so that each feature just need to import that module and you can pretty easily add the dependency because you know they key.
For example the apiClient you defined in isowords it's a separate module and each feature can use it.
There may be two cases where I don't wanna move this dependency in a shared module but still I would like to reuse it in multiple features:
I m gonna focus in the point 2 because is the complex one and most interesting.
I have library that define a
Tracker
:this is basically a witness to be able to track metrics or logs and the live implementation can be a network call that is sending data to your backend or just a print on the console.
This model is generic over the Event, so that I can reuse it across different apps.
The main event is defined in the main target as:
Ideally I would like that my main target is working with a dependency of
Tracker<AppEvent>
and scope this dependency in each single feature, for example FeatureA will hasTracker<FeatureAEvent>
, FeatureB will hasTracker<FeatureBEvent>
etc.This is something I was already doing before the new dependency management system.
The huge problem is that my feature doesn't know anything about the
AppEvent
and I don't want that it knows it.So I was forced to define a new dependency key in my FeatureA to make it compile:
(notice that live implementation is not handled because it will be provided by the main target).
Then in the main target I define the main Tracker dependency
and I made the feature A tracker depending on the main one only at a live implementation level
This approach works but it has 2 issues:
single line
change, every time I had to use a new key because it's not aware of key of the main trackerDo you have any suggestion on how to solve this? I think it's a big limitation compared to the previous state of the library, because it's forcing me to move things in separate module when I don't want to or I may not be able to do (e.g. the generic Event may contain a lots of models, due to legacy reasons that I would like to avoid to expose to all feature that use the dependency).
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions