Skip to content

Commit 1a168e2

Browse files
Add note to reducer protocol dependency section (#1873)
* Add note to reducer protocol dependency section The discussion #1870 noted that our migration guide could include more of a breadcrumb that migrating to the Dependencies library isn't a simple matter of changing every environment property to a `@Dependency` property. * wip Co-authored-by: Brandon Williams <[email protected]>
1 parent 71bab05 commit 1a168e2

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

Sources/ComposableArchitecture/Documentation.docc/Articles/MigratingToTheReducerProtocol.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -492,10 +492,11 @@ But this means that you must explicitly thread all dependencies from the root of
492492
through to every child feature. This can be arduous and make it difficult to add, remove or change
493493
dependencies.
494494

495-
The library comes with a tool for managing dependencies in a more ergonomic manner, and even comes
496-
with some common dependencies pre-integrated allowing you to access them with no additional work.
497-
For example, the `date` dependency ships with the library so that you can declare your feature's
498-
dependence on that functionality in the following way:
495+
The Composable Architecture now uses the [Dependencies][swift-dependencies] library to manage
496+
dependencies in a more ergonomic manner, and even comes with some common dependencies pre-integrated
497+
allowing you to access them with no additional work. For example, the `date` dependency ships with
498+
the library so that you can declare your feature's dependence on that functionality in the following
499+
way:
499500

500501
```swift
501502
struct Feature: ReducerProtocol {
@@ -508,6 +509,17 @@ struct Feature: ReducerProtocol {
508509
With that one declaration you can stop explicitly passing the date dependency through every layer
509510
of your application. A date function will be automatically provided to your feature's reducer.
510511

512+
> Important: [Dependencies][swift-dependencies] is powered by Swift task locals and is intended to
513+
> be used in structured contexts. If your reducer's effects make use of escaping closures, then
514+
> you must do additional work to propagate the dependencies to that context. For example, using
515+
> a dependency from within a Combine operator such as `.map`, `.flatMap` and even `.filter` will
516+
> use the default dependency value.
517+
>
518+
> See the [Dependencies documentation][swift-dependencies-docs] on
519+
> [Dependency lifetimes][swift-dependencies-docs-lifetimes] for more information, and how to
520+
> integrate the `@Dependency` property wrapper into pre-structured concurrency using the
521+
> `withEscapedDependencies` function.
522+
511523
For domain-specific dependencies you can perform a little bit of upfront work to register your
512524
dependency with the system, and then it will be automatically available to every layer in your
513525
application:
@@ -538,6 +550,10 @@ struct Feature: ReducerProtocol {
538550
For more information on designing your dependencies and providing live and test dependencies, see
539551
our <doc:Testing> article.
540552

553+
[swift-dependencies]: https://github.com/pointfreeco/swift-dependencies
554+
[swift-dependencies-docs]: https://pointfreeco.github.io/swift-dependencies/main/documentation/dependencies/
555+
[swift-dependencies-docs-lifetimes]: https://pointfreeco.github.io/swift-dependencies/main/documentation/dependencies/lifetimes
556+
541557
## Stores
542558

543559
Stores can be initialized from an initial state and an instance of a type conforming to

0 commit comments

Comments
 (0)