So this is pretty incredible.
We have vastly overhauled how dependencies are handled in the library, as long as you are using the new ReducerProtocol
style of building your features. You can declare that a reducer wants a dependency by just using the @Dependency
property wrapper, and you don’t even have to explicitly pass that dependency when constructing the reducer. It is automatically provided to the reducer behind the scenes.
This means you no longer need to provide an initializer for your reducers or environment just to pass dependencies from the parent layer down to the child, and you can even add, remove or change dependencies in a deep, leaf node of your application, and you won’t have to make a single change in any of the parent layers.
Further, it is also possible to make tweaks to the dependencies a reducer uses from the outside. We saw this a moment ago in previews where we wanted to preview our feature in a more controlled environment, one that did not actually interact with AVFoundation. But you can apply this idea also to running a portion of your application in a different execution environment. For example, if you have an onboarding experience for teaching people how to use a feature, you can run that feature with altered dependencies so that they don’t interact with the real world, like save data to disk, make database requests, or hit the network.
That allows you to run your feature in a kind of sandbox, so that you can fully control what your user experiences during onboarding.
So, this all seems great, but can you believe it even gets better?
We’ve now had multiple episodes about reducer protocols and we haven’t talked about testing once. Testing is a top priority for the library. We never want to make changes or introduce features that can hurt testability. It turns out that our move towards reducer protocols and this new style of dependencies only improves the testing story for the library. It allows us to codify a pattern directly into the library that makes your tests stronger and more exhaustive.