Skip to content

Commit 757dd90

Browse files
authored
Update README.md
1 parent bf65cee commit 757dd90

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
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).
88

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+
911
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.
1012

1113
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
192194
.product(name: "GlobalEnvironment", package: "swift-composable-environment")
193195
```
194196
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

Comments
 (0)