-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add dependency clients for kmp (#33)
- Loading branch information
Showing
3 changed files
with
80 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,37 @@ | ||
import DependenciesMacros | ||
import Dependencies | ||
import shared | ||
|
||
extension DependencyValues { | ||
public var timetableClient: TimetableClient { | ||
get { self[TimetableClient.self] } | ||
set { self[TimetableClient.self] = newValue } | ||
} | ||
|
||
public var staffClient: StaffClient { | ||
get { self[StaffClient.self] } | ||
set { self[StaffClient.self] = newValue } | ||
} | ||
|
||
public var sponsorsClient: SponsorsClient { | ||
get { self[SponsorsClient.self] } | ||
set { self[SponsorsClient.self] = newValue } | ||
} | ||
} | ||
|
||
@DependencyClient | ||
public struct TimetableClient: Sendable { | ||
public var streamTimetable: @Sendable () throws -> AsyncThrowingStream<Timetable, any Error> | ||
public var streamTimetableItemWithFavorite: @Sendable (_ id: TimetableItemId) throws -> AsyncThrowingStream<(TimetableItem, Bool), any Error> | ||
public var toggleBookmark: @Sendable (_ id: TimetableItemId) async throws -> Void | ||
} | ||
|
||
@DependencyClient | ||
public struct StaffClient: Sendable { | ||
public var streamStaffs: @Sendable () throws -> AsyncThrowingStream<[Staff], any Error> | ||
} | ||
|
||
@DependencyClient | ||
public struct KMPClient: Sendable { | ||
public let fetchTimetable: @Sendable () -> AsyncThrowingStream<Timetable, any Error> | ||
public struct SponsorsClient: Sendable { | ||
public var streamSponsors: @Sendable () throws -> AsyncThrowingStream<[Sponsor], any Error> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,16 @@ | ||
import Dependencies | ||
|
||
extension DependencyValues { | ||
public var kmpClient: KMPClient { | ||
get { self[KMPClient.self] } | ||
set { self[KMPClient.self] = newValue } | ||
} | ||
extension TimetableClient: TestDependencyKey { | ||
public static let previewValue: Self = Self() | ||
public static let testValue: Self = Self() | ||
} | ||
|
||
extension KMPClient: TestDependencyKey { | ||
public static let previewValue: KMPClient = .noop | ||
extension StaffClient: TestDependencyKey { | ||
public static let previewValue: Self = Self() | ||
public static let testValue: Self = Self() | ||
} | ||
|
||
extension KMPClient { | ||
public static let noop = Self( | ||
fetchTimetable: { | ||
.never | ||
} | ||
) | ||
extension SponsorsClient: TestDependencyKey { | ||
public static let previewValue: Self = Self() | ||
public static let testValue: Self = Self() | ||
} |