feat: Working on mocks and mock storage.
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
|
||||
private var storage: [Model.ID: Model]
|
||||
|
||||
private let modelFromCreate: @Sendable (Create) -> Model
|
||||
private let modelFromCreate: @Sendable (Create) async throws -> Model
|
||||
private let fetchToPredicate: @Sendable (Fetch) -> ((Model) -> Bool)
|
||||
private let fetchExtras: @Sendable (Fetch, [Model]) async throws -> [Model]
|
||||
private let applyUpdates: @Sendable (inout Model, Update, Get?) async throws -> Void
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
init(
|
||||
_ mocks: [Model] = [],
|
||||
create modelFromCreate: @Sendable @escaping (Create) -> Model,
|
||||
create modelFromCreate: @Sendable @escaping (Create) async throws -> Model,
|
||||
fetch fetchToPredicate: @Sendable @escaping (Fetch) -> ((Model) -> Bool),
|
||||
fetchExtras: @Sendable @escaping (Fetch, [Model]) async throws -> [Model] = { $1 },
|
||||
get getExtras: @Sendable @escaping (Get?, Model) async throws -> Model,
|
||||
@@ -41,7 +41,7 @@
|
||||
}
|
||||
|
||||
func create(_ create: Create) async throws -> Model {
|
||||
let model = modelFromCreate(create)
|
||||
let model = try await modelFromCreate(create)
|
||||
storage[model.id] = model
|
||||
return model
|
||||
}
|
||||
@@ -75,7 +75,7 @@
|
||||
extension MockStorage where Get == Void {
|
||||
init(
|
||||
_ mocks: [Model] = [],
|
||||
create modelFromCreate: @Sendable @escaping (Create) -> Model,
|
||||
create modelFromCreate: @Sendable @escaping (Create) async throws -> Model,
|
||||
fetch fetchToPredicate: @Sendable @escaping (Fetch) -> ((Model) -> Bool),
|
||||
fetchExtras: @Sendable @escaping (Fetch, [Model]) async throws -> [Model] = { $1 },
|
||||
update applyUpdates: @Sendable @escaping (inout Model, Update) async throws -> Void
|
||||
@@ -103,7 +103,7 @@
|
||||
extension MockStorage where Fetch == Void {
|
||||
init(
|
||||
_ mocks: [Model] = [],
|
||||
create modelFromCreate: @Sendable @escaping (Create) -> Model,
|
||||
create modelFromCreate: @Sendable @escaping (Create) async throws -> Model,
|
||||
fetchExtras: @Sendable @escaping (Fetch, [Model]) async throws -> [Model] = { $1 },
|
||||
get getExtras: @Sendable @escaping (Get?, Model) async throws -> Model,
|
||||
update applyUpdates: @Sendable @escaping (inout Model, Update, Get?) async throws -> Void
|
||||
@@ -126,7 +126,7 @@
|
||||
extension MockStorage where Fetch == Void, Get == Void {
|
||||
init(
|
||||
_ mocks: [Model] = [],
|
||||
create modelFromCreate: @Sendable @escaping (Create) -> Model,
|
||||
create modelFromCreate: @Sendable @escaping (Create) async throws -> Model,
|
||||
fetchExtras: @Sendable @escaping (Fetch, [Model]) async throws -> [Model] = { $1 },
|
||||
update applyUpdates: @Sendable @escaping (inout Model, Update) async throws -> Void
|
||||
) {
|
||||
@@ -138,6 +138,5 @@
|
||||
update: { model, updates, _ in try await applyUpdates(&model, updates) }
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user