|
6 | 6 |
|
7 | 7 | This library brings an API similar to SwiftUI's `Environment` to derive and compose `Environment`'s in [The Composable Architecture](https://github.com/pointfreeco/swift-composable-architecture) (TCA). |
8 | 8 |
|
| 9 | +**TCA is moving toward protocol reducers. This simplifies greatly the way dependencies are passed around between features. It is encouraged to migrate toward this approach. TCA will also use a `@Dependency` property wrapper, and a `DependencyKey` protocol, so [you will need to perform a few actions](#migrating-to-tcas-protocol-reducers) to have both systems working at the same time while you transition out from this library.** |
| 10 | + |
9 | 11 | By `Environment`, one understands a type that vends *dependencies*. This library eases this process by standardizing these dependencies, and the way they are passed from one environment type to another when composing domains using TCA. Like in SwiftUI, this library allows passing values (in this case dependencies) down a tree of values (in this case the reducers) without having to specify them at each step. You don't need to provide initial values for dependencies in your `Environment`'s, you don't need to inject dependencies from a parent environment to a child environment, and in many cases, you don't even need to instantiate the child environment. |
10 | 12 |
|
11 | 13 | This library comes with two mutually exclusive modules, `ComposableEnvironment` and `GlobalEnvironment`, which are providing different functionalities for different tradeoffs. |
@@ -192,3 +194,26 @@ to your Package dependencies in `Package.swift`, and then |
192 | 194 | .product(name: "GlobalEnvironment", package: "swift-composable-environment") |
193 | 195 | ``` |
194 | 196 | to your target's dependencies, depending on the module you want to use. |
| 197 | + |
| 198 | +## Migrating to TCA's protocol reducers |
| 199 | + |
| 200 | +When importing the latest versions of TCA, there will likely be ambiguities when using the `@Dependency` property wrapper, or the `DependencyKey` protocol. As this library will give way to TCA, the preferred approach is the following: |
| 201 | + |
| 202 | +- Define a typealias to both TCA's types in a module you own (or in you're application if you're not using modules): |
| 203 | +```swift |
| 204 | +import ComposableArchitecture |
| 205 | +public typealias DependencyKey = ComposableArchitecture.DependencyKey |
| 206 | +public typealias Dependency = ComposableArchitecture.Dependency |
| 207 | +``` |
| 208 | +Because these typeliases are defined in modules you own, they will be preferred to external definitions when resolving types. |
| 209 | +- Replace all occurences of `DependencyKey` by `Compatible.DependencyKey` and `@Dependency` by `@Compatible.Dependency`. You can use Xcode search/replace in all files for this purpose. |
| 210 | + |
| 211 | +In this state, your project should build without ambiguities. |
| 212 | +```swift |
| 213 | +DependencyKey: TCA's DependencyKey |
| 214 | +@Dependency: TCA's @Dependency |
| 215 | +--- |
| 216 | +Compatible.DependencyKey: Composable Environment's DependencyKey |
| 217 | +@Compatible.Dependency: Composable Environment's @Dependency |
| 218 | +``` |
| 219 | +You can then migrate at your rythm to protocol reducers. Once the migration is complete, you can remove the dependency to this library. I hope it served you well! |
0 commit comments