Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use @DependencyClient #195

Merged
merged 18 commits into from
Dec 8, 2023
Merged
4 changes: 2 additions & 2 deletions App/iOS/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ struct IsowordsApp: App {
WindowGroup {
AppView(store: self.appDelegate.store)
}
.onChange(of: self.scenePhase) {
self.appDelegate.store.send(.didChangeScenePhase($0))
.onChange(of: self.scenePhase) { _, newPhase in
self.appDelegate.store.send(.didChangeScenePhase(newPhase))
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions App/isowords.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1339,7 +1339,6 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
MACOSX_DEPLOYMENT_TARGET = 10.15;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
Expand Down Expand Up @@ -1826,7 +1825,6 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
MACOSX_DEPLOYMENT_TARGET = 10.15;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
Expand Down Expand Up @@ -1884,7 +1882,6 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
MACOSX_DEPLOYMENT_TARGET = 10.15;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-case-paths",
"state" : {
"revision" : "ed7facdd4a361514b46e3bbc6238cd41c84be4ec",
"version" : "1.1.1"
"revision" : "a5521dde99570789d8cb7c43e51418d7cd1a87ca",
"version" : "1.1.2"
}
},
{
"identity" : "swift-clocks",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-clocks",
"state" : {
"revision" : "d1fd837326aa719bee979bdde1f53cd5797443eb",
"version" : "1.0.0"
"revision" : "a8421d68068d8f45fbceb418fbf22c5dad4afd33",
"version" : "1.0.2"
}
},
{
Expand All @@ -113,8 +113,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-composable-architecture",
"state" : {
"branch" : "main",
"revision" : "af5ae21f65553d5bb39d55d9b4f80182a0c4fcb5"
"revision" : "d8f81ca2d43026641c5c60729d01f245ccc32370",
"version" : "1.5.3"
}
},
{
Expand All @@ -140,17 +140,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-custom-dump",
"state" : {
"revision" : "65fc9e2b62727cacfab9fc60d580c284a4b9308c",
"version" : "1.1.1"
"revision" : "aedcf6f4cd486ccef5b312ccac85d4b3f6e58605",
"version" : "1.1.2"
}
},
{
"identity" : "swift-dependencies",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-dependencies",
"state" : {
"revision" : "63301f4a181ed9aefb46dccef2dfb66466798341",
"version" : "1.1.1"
"revision" : "9783b58167f7618cb86011156e741cbc6f4cc864",
"version" : "1.1.2"
}
},
{
Expand All @@ -176,8 +176,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-http-types",
"state" : {
"revision" : "99d066e29effa8845e4761dd3f2f831edfdf8925",
"version" : "1.0.0"
"revision" : "1827dc94bdab2eb5f2fc804e9b0cb43574282566",
"version" : "1.0.2"
}
},
{
Expand Down Expand Up @@ -293,8 +293,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-snapshot-testing",
"state" : {
"revision" : "4862d48562483d274a2ac7522d905c9237a31a48",
"version" : "1.15.0"
"revision" : "59b663f68e69f27a87b45de48cb63264b8194605",
"version" : "1.15.1"
}
},
{
Expand Down
33 changes: 17 additions & 16 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.7
// swift-tools-version:5.9

import Foundation
import PackageDescription
Expand All @@ -7,10 +7,10 @@ import PackageDescription
var package = Package(
name: "isowords",
platforms: [
.iOS(.v16),
.macOS(.v13),
.tvOS(.v16),
.watchOS(.v9),
.iOS(.v17),
.macOS(.v14),
.tvOS(.v17),
.watchOS(.v10),
],
products: [
.library(name: "Build", targets: ["Build"]),
Expand All @@ -28,11 +28,9 @@ var package = Package(
dependencies: [
.package(url: "https://github.com/apple/swift-crypto", from: "1.1.6"),
.package(url: "https://github.com/pointfreeco/swift-case-paths", from: "1.1.0"),
.package(
url: "https://github.com/pointfreeco/swift-composable-architecture", branch: "main"
),
.package(url: "https://github.com/pointfreeco/swift-composable-architecture", from: "1.5.3" ),
.package(url: "https://github.com/pointfreeco/swift-custom-dump", from: "1.0.0"),
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.0.0"),
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.1.0"),
.package(url: "https://github.com/pointfreeco/swift-gen", from: "0.3.0"),
.package(url: "https://github.com/pointfreeco/swift-parsing", from: "0.12.0"),
.package(url: "https://github.com/pointfreeco/swift-tagged", from: "0.6.0"),
Expand All @@ -45,7 +43,8 @@ var package = Package(
.target(
name: "Build",
dependencies: [
.product(name: "Dependencies", package: "swift-composable-architecture"),
.product(name: "Dependencies", package: "swift-dependencies"),
.product(name: "DependenciesMacros", package: "swift-dependencies"),
.product(name: "Tagged", package: "swift-tagged"),
.product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay"),
]
Expand All @@ -61,7 +60,8 @@ var package = Package(
name: "DictionaryClient",
dependencies: [
"SharedModels",
.product(name: "Dependencies", package: "swift-composable-architecture"),
.product(name: "Dependencies", package: "swift-dependencies"),
.product(name: "DependenciesMacros", package: "swift-dependencies"),
.product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay"),
]
),
Expand Down Expand Up @@ -254,7 +254,8 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
"SharedModels",
"XCTestDebugSupport",
.product(name: "CasePaths", package: "swift-case-paths"),
.product(name: "Dependencies", package: "swift-composable-architecture"),
.product(name: "Dependencies", package: "swift-dependencies"),
.product(name: "DependenciesMacros", package: "swift-dependencies"),
.product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay"),
]
),
Expand All @@ -265,7 +266,7 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
"ServerRouter",
"SharedModels",
"TcaHelpers",
.product(name: "Dependencies", package: "swift-composable-architecture"),
.product(name: "Dependencies", package: "swift-dependencies"),
],
exclude: ["Secrets.swift.example"]
),
Expand Down Expand Up @@ -525,7 +526,8 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
.target(
name: "DeviceId",
dependencies: [
.product(name: "Dependencies", package: "swift-composable-architecture"),
.product(name: "Dependencies", package: "swift-dependencies"),
.product(name: "DependenciesMacros", package: "swift-dependencies"),
.product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay"),
]
),
Expand Down Expand Up @@ -935,7 +937,6 @@ if ProcessInfo.processInfo.environment["TEST_SERVER"] == nil {
name: "UIApplicationClient",
dependencies: [
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
.product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay"),
]
),
.target(
Expand Down Expand Up @@ -1301,9 +1302,9 @@ package.targets.append(contentsOf: [
"ShareGameMiddleware",
"SnsClient",
"VerifyReceiptMiddleware",
.product(name: "DependenciesMacros", package: "swift-dependencies"),
.product(name: "HttpPipeline", package: "swift-web"),
.product(name: "Overture", package: "swift-overture"),
.product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay"),
],
resources: [.process("Resources/")]
),
Expand Down
25 changes: 3 additions & 22 deletions Sources/ApiClient/Client.swift
Original file line number Diff line number Diff line change
@@ -1,38 +1,19 @@
import DependenciesMacros
import Foundation
import SharedModels

@DependencyClient
public struct ApiClient {
public var apiRequest: @Sendable (ServerRoute.Api.Route) async throws -> (Data, URLResponse)
public var authenticate:
@Sendable (ServerRoute.AuthenticateRequest) async throws -> CurrentPlayerEnvelope
public var baseUrl: @Sendable () -> URL
public var baseUrl: @Sendable () -> URL = { URL(string: "/")! }
public var currentPlayer: @Sendable () -> CurrentPlayerEnvelope?
public var logout: @Sendable () async -> Void
public var refreshCurrentPlayer: @Sendable () async throws -> CurrentPlayerEnvelope
public var request: @Sendable (ServerRoute) async throws -> (Data, URLResponse)
public var setBaseUrl: @Sendable (URL) async -> Void

public init(
apiRequest: @escaping @Sendable (ServerRoute.Api.Route) async throws -> (Data, URLResponse),
authenticate: @escaping @Sendable (ServerRoute.AuthenticateRequest) async throws ->
CurrentPlayerEnvelope,
baseUrl: @escaping @Sendable () -> URL,
currentPlayer: @escaping @Sendable () -> CurrentPlayerEnvelope?,
logout: @escaping @Sendable () async -> Void,
refreshCurrentPlayer: @escaping @Sendable () async throws -> CurrentPlayerEnvelope,
request: @escaping @Sendable (ServerRoute) async throws -> (Data, URLResponse),
setBaseUrl: @escaping @Sendable (URL) async -> Void
) {
self.apiRequest = apiRequest
self.authenticate = authenticate
self.baseUrl = baseUrl
self.currentPlayer = currentPlayer
self.logout = logout
self.refreshCurrentPlayer = refreshCurrentPlayer
self.request = request
self.setBaseUrl = setBaseUrl
}

public func apiRequest(
route: ServerRoute.Api.Route,
file: StaticString = #file,
Expand Down
13 changes: 1 addition & 12 deletions Sources/ApiClient/TestKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import Dependencies
import Foundation
import SharedModels
import XCTestDebugSupport
import XCTestDynamicOverlay

extension DependencyValues {
public var apiClient: ApiClient {
Expand All @@ -14,17 +13,7 @@ extension DependencyValues {

extension ApiClient: TestDependencyKey {
public static let previewValue = Self.noop

public static let testValue = Self(
apiRequest: unimplemented("\(Self.self).apiRequest"),
authenticate: unimplemented("\(Self.self).authenticate"),
baseUrl: unimplemented("\(Self.self).baseUrl", placeholder: URL(string: "/")!),
currentPlayer: unimplemented("\(Self.self).currentPlayer"),
logout: unimplemented("\(Self.self).logout"),
refreshCurrentPlayer: unimplemented("\(Self.self).refreshCurrentPlayer"),
request: unimplemented("\(Self.self).request"),
setBaseUrl: unimplemented("\(Self.self).setBaseUrl")
)
public static let testValue = Self()
}

extension ApiClient {
Expand Down
5 changes: 4 additions & 1 deletion Sources/AudioPlayerClient/Client.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import DependenciesMacros

@DependencyClient
public struct AudioPlayerClient {
public var load: @Sendable ([Sound]) async -> Void
public var loop: @Sendable (Sound) async -> Void
public var play: @Sendable (Sound) async -> Void
public var secondaryAudioShouldBeSilencedHint: @Sendable () async -> Bool
public var secondaryAudioShouldBeSilencedHint: @Sendable () async -> Bool = { false }
public var setGlobalVolumeForMusic: @Sendable (Float) async -> Void
public var setGlobalVolumeForSoundEffects: @Sendable (Float) async -> Void
public var setVolume: @Sendable (Sound, Float) async -> Void
Expand Down
17 changes: 1 addition & 16 deletions Sources/AudioPlayerClient/TestKey.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Dependencies
import XCTestDynamicOverlay

extension DependencyValues {
public var audioPlayer: AudioPlayerClient {
Expand All @@ -10,21 +9,7 @@ extension DependencyValues {

extension AudioPlayerClient: TestDependencyKey {
public static let previewValue = Self.noop

public static let testValue = Self(
load: unimplemented("\(Self.self).load"),
loop: unimplemented("\(Self.self).loop"),
play: unimplemented("\(Self.self).play"),
secondaryAudioShouldBeSilencedHint: unimplemented(
"\(Self.self).secondaryAudioShouldBeSilencedHint", placeholder: false
),
setGlobalVolumeForMusic: unimplemented("\(Self.self).setGlobalVolumeForMusic"),
setGlobalVolumeForSoundEffects: unimplemented(
"\(Self.self).setGlobalVolumeForSoundEffects"
),
setVolume: unimplemented("\(Self.self).setVolume"),
stop: unimplemented("\(Self.self).stop")
)
public static let testValue = Self()
}

extension AudioPlayerClient {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Bloom/BloomBackground.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public struct BloomBackground: View {

public var body: some View {
Blooms(blooms: self.blooms)
.onChange(of: self.viewStore.bloomCount) { count in
.onChange(of: self.viewStore.bloomCount) { _, count in
withAnimation(.easeOut(duration: 1)) {
self.renderBlooms(count: count)
}
Expand Down
21 changes: 5 additions & 16 deletions Sources/Build/Build.swift
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
import Dependencies
import DependenciesMacros
import Foundation
import Tagged
import XCTestDynamicOverlay

@DependencyClient
public struct Build {
public var gitSha: () -> String
public var number: () -> Number
public var gitSha: () -> String = { "deadbeef" }
public var number: () -> Number = { 0 }

public typealias Number = Tagged<((), number: ()), Int>

public init(
gitSha: @escaping () -> String,
number: @escaping () -> Number
) {
self.gitSha = gitSha
self.number = number
}
}

extension DependencyValues {
Expand All @@ -27,11 +20,7 @@ extension DependencyValues {

extension Build: TestDependencyKey {
public static let previewValue = Self.noop

public static let testValue = Self(
gitSha: unimplemented("\(Self.self).gitSha", placeholder: "deadbeef"),
number: unimplemented("\(Self.self).number", placeholder: 0)
)
public static let testValue = Self()
}

extension Build: DependencyKey {
Expand Down
Loading
Loading