chore: core 多模块骨架
This commit is contained in:
40
IosClientKit/Sources/CoreRepository/FakeHomeRepository.swift
Normal file
40
IosClientKit/Sources/CoreRepository/FakeHomeRepository.swift
Normal file
@@ -0,0 +1,40 @@
|
||||
import CoreCommon
|
||||
import CoreDomain
|
||||
import CoreModel
|
||||
|
||||
/// Fake 仓库实现(骨架阶段返回假数据,后续替换为 OfflineFirst 实现)。
|
||||
public struct FakeHomeRepository: HomeRepository {
|
||||
public init() {}
|
||||
|
||||
public func observeHome() -> AsyncThrowingStream<HomeData, Error> {
|
||||
AsyncThrowingStream { continuation in
|
||||
let task = Task {
|
||||
do {
|
||||
// 模拟网络延迟。
|
||||
try await Task.sleep(for: .milliseconds(400))
|
||||
try Task.checkCancellation()
|
||||
Logger.info("FakeHomeRepository 返回假数据")
|
||||
continuation.yield(Self.fakeData)
|
||||
continuation.finish()
|
||||
} catch {
|
||||
continuation.finish(throwing: error)
|
||||
}
|
||||
}
|
||||
continuation.onTermination = { _ in
|
||||
task.cancel()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static let fakeData = HomeData(
|
||||
id: "home-1",
|
||||
greeting: "早上好,Andy",
|
||||
summary: "今日已完成 2 / 4",
|
||||
habits: [
|
||||
Habit(id: "habit-1", title: "晨跑 5 公里", detail: "保持运动习惯", isCheckedInToday: true, streakDays: 12),
|
||||
Habit(id: "habit-2", title: "阅读 30 分钟", detail: "每天进步一点", isCheckedInToday: true, streakDays: 8),
|
||||
Habit(id: "habit-3", title: "喝水 8 杯", detail: "健康补水", isCheckedInToday: false, streakDays: 0),
|
||||
Habit(id: "habit-4", title: "写日记", detail: "记录今日所思", isCheckedInToday: false, streakDays: 3),
|
||||
]
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user