Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ dependencies rather than letting them control you.
But, controlling a dependency is only the beginning. Once you have controlled your dependencies,
you are faced with a whole set of new problems:

* How can you **propagate dependencies** throughout your entire application that is more ergonomic
than explicitly passing them around everywhere, but safer than having a global dependency?
* How can you **propagate dependencies** throughout your entire application in a way that is more
ergonomic than explicitly passing them around everywhere, but safer than having a global
dependency?

* How can you **override dependencies** for just one portion of your application? This can be
handy for overriding dependencies for tests and SwiftUI previews, as well as specific user
Expand Down
11 changes: 6 additions & 5 deletions Sources/Dependencies/Documentation.docc/Articles/QuickStart.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,20 @@ final class FeatureModel: ObservableObject {
}
```

Once your dependencies are declared, rather than reaching out to the `Date()`, `UUID()`, etc.
directly, you can use the dependency that is defined directly on your feature's model:
Once your dependencies are declared, rather than reaching out to the `Date()`, `UUID()`, etc.,
directly, you can use the dependency that is defined on your feature's model:

```swift
final class FeatureModel: ObservableObject {
// ...

func addButtonTapped() async throws {
try await self.clock.sleep(for: .seconds(1)) // 👈 Don't use Task.sleep
try await self.clock.sleep(for: .seconds(1)) // 👈 Don't use 'Task.sleep'
self.items.append(
Item(
id: self.uuid(), // 👈 Don't use UUID()
id: self.uuid(), // 👈 Don't use 'UUID()'
name: "",
createdAt: self.now // 👈 Don't use Date()
createdAt: self.now // 👈 Don't use 'Date()'
)
)
}
Expand Down Expand Up @@ -94,6 +94,7 @@ func testAdd() async throws {
id: UUID(uuidString: "00000000-0000-0000-0000-000000000000")!,
name: "",
createdAt: Date(timeIntervalSinceReferenceDate: 1234567890)
)
]
)
}
Expand Down
7 changes: 4 additions & 3 deletions Sources/Dependencies/Documentation.docc/Dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ dependencies rather than letting them control you.
But, controlling a dependency is only the beginning. Once you have controlled your dependencies,
you are faced with a whole set of new problems:

* How can you **propagate dependencies** throughout your entire application that is more ergonomic
than explicitly passing them around everywhere, but safer than having a global dependency?

* How can you **propagate dependencies** throughout your entire application in a way that is more
ergonomic than explicitly passing them around everywhere, but safer than having a global
dependency?

* How can you **override dependencies** for just one portion of your application? This can be
handy for overriding dependencies for tests and SwiftUI previews, as well as specific user
flows such as onboarding experiences.
Expand Down
40 changes: 18 additions & 22 deletions Tests/DependenciesTests/AsyncStreamTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,34 @@
import SwiftUI

@available(iOS 15, *)
private let sendable: @Sendable () -> AsyncStream<Void> = {
AsyncStream {
await NotificationCenter.default
.notifications(named: UIApplication.userDidTakeScreenshotNotification)
.map { _ in }
}
private let sendable: @Sendable () async -> AsyncStream<Void> = {
await NotificationCenter.default
.notifications(named: UIApplication.userDidTakeScreenshotNotification)
.map { _ in }
.eraseToStream()
}

@available(iOS 15, *)
private let mainActor: @MainActor () -> AsyncStream<Void> = {
AsyncStream {
NotificationCenter.default
.notifications(named: UIApplication.userDidTakeScreenshotNotification)
.map { _ in }
}
NotificationCenter.default
.notifications(named: UIApplication.userDidTakeScreenshotNotification)
.map { _ in }
.eraseToStream()
}

@available(iOS 15, *)
private let sendableThrowing: @Sendable () -> AsyncThrowingStream<Void, Error> = {
AsyncThrowingStream {
await NotificationCenter.default
.notifications(named: UIApplication.userDidTakeScreenshotNotification)
.map { _ in }
}
private let sendableThrowing: @Sendable () async -> AsyncThrowingStream<Void, Error> = {
await NotificationCenter.default
.notifications(named: UIApplication.userDidTakeScreenshotNotification)
.map { _ in }
.eraseToThrowingStream()
}

@available(iOS 15, *)
private let mainActorThrowing: @MainActor () -> AsyncThrowingStream<Void, Error> = {
AsyncThrowingStream {
NotificationCenter.default
.notifications(named: UIApplication.userDidTakeScreenshotNotification)
.map { _ in }
}
NotificationCenter.default
.notifications(named: UIApplication.userDidTakeScreenshotNotification)
.map { _ in }
.eraseToThrowingStream()
}
#endif