From 5c816e0e0dabb65bd3217608ebf2eb87af4dd81e Mon Sep 17 00:00:00 2001 From: Stephen Celis Date: Mon, 9 Jan 2023 13:58:26 -0500 Subject: [PATCH] Assorted fixes --- README.md | 5 ++- .../Documentation.docc/Articles/QuickStart.md | 11 ++--- .../Documentation.docc/Dependencies.md | 7 ++-- .../DependenciesTests/AsyncStreamTests.swift | 40 +++++++++---------- 4 files changed, 31 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 27285ade..2aca90c9 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/Sources/Dependencies/Documentation.docc/Articles/QuickStart.md b/Sources/Dependencies/Documentation.docc/Articles/QuickStart.md index d4048882..30481afb 100644 --- a/Sources/Dependencies/Documentation.docc/Articles/QuickStart.md +++ b/Sources/Dependencies/Documentation.docc/Articles/QuickStart.md @@ -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()' ) ) } @@ -94,6 +94,7 @@ func testAdd() async throws { id: UUID(uuidString: "00000000-0000-0000-0000-000000000000")!, name: "", createdAt: Date(timeIntervalSinceReferenceDate: 1234567890) + ) ] ) } diff --git a/Sources/Dependencies/Documentation.docc/Dependencies.md b/Sources/Dependencies/Documentation.docc/Dependencies.md index 9eb4066c..6331c804 100644 --- a/Sources/Dependencies/Documentation.docc/Dependencies.md +++ b/Sources/Dependencies/Documentation.docc/Dependencies.md @@ -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. diff --git a/Tests/DependenciesTests/AsyncStreamTests.swift b/Tests/DependenciesTests/AsyncStreamTests.swift index 9ba85df8..35e28609 100644 --- a/Tests/DependenciesTests/AsyncStreamTests.swift +++ b/Tests/DependenciesTests/AsyncStreamTests.swift @@ -2,38 +2,34 @@ import SwiftUI @available(iOS 15, *) - private let sendable: @Sendable () -> AsyncStream = { - AsyncStream { - await NotificationCenter.default - .notifications(named: UIApplication.userDidTakeScreenshotNotification) - .map { _ in } - } + private let sendable: @Sendable () async -> AsyncStream = { + await NotificationCenter.default + .notifications(named: UIApplication.userDidTakeScreenshotNotification) + .map { _ in } + .eraseToStream() } @available(iOS 15, *) private let mainActor: @MainActor () -> AsyncStream = { - 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 = { - AsyncThrowingStream { - await NotificationCenter.default - .notifications(named: UIApplication.userDidTakeScreenshotNotification) - .map { _ in } - } + private let sendableThrowing: @Sendable () async -> AsyncThrowingStream = { + await NotificationCenter.default + .notifications(named: UIApplication.userDidTakeScreenshotNotification) + .map { _ in } + .eraseToThrowingStream() } @available(iOS 15, *) private let mainActorThrowing: @MainActor () -> AsyncThrowingStream = { - AsyncThrowingStream { - NotificationCenter.default - .notifications(named: UIApplication.userDidTakeScreenshotNotification) - .map { _ in } - } + NotificationCenter.default + .notifications(named: UIApplication.userDidTakeScreenshotNotification) + .map { _ in } + .eraseToThrowingStream() } #endif