feat: Breaking out more dependencies.
This commit is contained in:
33
Sources/CodersClient/Coders.swift
Normal file
33
Sources/CodersClient/Coders.swift
Normal file
@@ -0,0 +1,33 @@
|
||||
import Dependencies
|
||||
import DependenciesMacros
|
||||
import Foundation
|
||||
import TOMLKit
|
||||
|
||||
public extension DependencyValues {
|
||||
var coders: Coders {
|
||||
get { self[Coders.self] }
|
||||
set { self[Coders.self] = newValue }
|
||||
}
|
||||
}
|
||||
|
||||
@DependencyClient
|
||||
public struct Coders: Sendable {
|
||||
public var jsonDecoder: @Sendable () -> JSONDecoder = { .init() }
|
||||
public var jsonEncoder: @Sendable () -> JSONEncoder = { .init() }
|
||||
public var tomlDecoder: @Sendable () -> TOMLDecoder = { .init() }
|
||||
public var tomlEncoder: @Sendable () -> TOMLEncoder = { .init() }
|
||||
}
|
||||
|
||||
extension Coders: DependencyKey {
|
||||
|
||||
public static var testValue: Self { Self() }
|
||||
|
||||
public static var liveValue: Self {
|
||||
.init(
|
||||
jsonDecoder: { JSONDecoder() },
|
||||
jsonEncoder: { JSONEncoder() },
|
||||
tomlDecoder: { TOMLDecoder() },
|
||||
tomlEncoder: { TOMLEncoder() }
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user