Static check for liveValue
?
#123
Replies: 3 comments 15 replies
-
One thing to note is that while we advertise the new dependencies system, nothing is stopping folks from manually passing dependencies to reducers. That system still works just fine, but instead of a generic
Are you sure this works? Doesn't As for your other questions, we're not sure there's a way to address it since dependencies and modular and extensible from the outside. Maybe there's a way to dynamically crash on app launch if a dependency exists and there is no |
Beta Was this translation helpful? Give feedback.
-
I wrote a script to scan a binary to check if every Script:
Xcode build phase:
|
Beta Was this translation helpful? Give feedback.
-
To my understanding, the purpose of the swift-dependencies library is to provide a guided way to insert dependencies into a service locator like pattern using a single point of entry system. With this being noted, there's trade offs to approaching a service locator in a way that deters runtime dependency swap outs versus static dependency definitions. It's been noted on a few occasions that it's encouraged to fail default dependency implementations in tests to ensure they're explicit in use-age. This is a tradeoff point for the library where we're clearly requiring an up-front definition (typically a protocol witness like structure) with unimplemented functions to ensure we're failing at call sites for dependency interaction, but not at the call site for fetching the dependency itself. Service locators encourage runtime dependency manipulation and swapping, hence leaning into Sacrificing some level of runtime awareness and allowing teams to implement their own checks/rules is a good approach for something that isn't necessarily an issue trying to be solved. For our team, |
Beta Was this translation helpful? Give feedback.
-
We recently migrated from a very old version of TCA to 1.x. One thing that has been scaring me about the new dependencies system is the fact that you can build (and potentially distribute) an app without having a live implementation of a dependency, since the requirement of subscripting
DependencyValues
is conforming toTestDependencyKey
and not toDependencyKey
. This, in a way, makes the newer version less safe in this aspect, which is a bit surprising. Especially with our huge project, it's pretty hard to make such a guarantee. Our codebase is huge, and we support many different platforms, so the dependencies are kinda scattered everywhere.Having said that, I cannot even describe how convenient the ergonomics of Dependencies are, compared to manually passing down the whole Environment, which can get very messy when having nested domains. So, I get it. I also get the problem that sometimes you cannot (or even don't want to) implement the live version in the same module. Having that as a hard requirement will basically prevent you from building, so again, I completely understand the reasons behind the decision.
I've been thinking about ways to make it safer, and one idea that came to my mind is to introduce this restriction only for
RELEASE
. One quick way to implement that is to add an#else if RELEASE
here and use#error("/*whatever*/")
to stop the build. My goal is to make it impossible to ship an app without implementingliveValue
, but also keep the flexibility of being able to build during development.One argument is that we cannot break building for RELEASE either for the same reasons above, in case you chose to implement
liveValue
outside. I don't claim to have a good answer to that, but here are some ideas:Curious what others think about this?
Beta Was this translation helpful? Give feedback.
All reactions