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

SwiftDataStore #4

Open
wants to merge 15 commits into
base: work/swift-data-repo-tim
Choose a base branch
from
2 changes: 1 addition & 1 deletion Sources/Core/Error/AppError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import Foundation

public protocol AppError: Error {
public protocol AppError: Error, Equatable {
associatedtype UIErrorType = UIError

/// Optional error data to present to the user
Expand Down
5 changes: 3 additions & 2 deletions Sources/Core/Error/DefaultError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public struct DefaultError<UIErrorType: UIError>: AppError {
intent: ErrorIntent = .indispensable
) {
self.uiError = uiError
self.error = error
self.error = error as? NSError
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're going to do this, the initializer should specify NSError rather than Error so that other error types don't slip through the cracks. But ideally this would work with any Error. Remind me why we need Equatable?

self.isNotable = isNotable
self.isRetryable = isRetryable
self.intent = intent
Expand All @@ -35,7 +35,8 @@ public struct DefaultError<UIErrorType: UIError>: AppError {

public var intent: ErrorIntent

public let error: Error?
// Using `NSError` allows us to be `Equatable`
public let error: NSError?

public var localizedDescription: String {
if let error {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Core/Error/UIError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import SwiftUI
///
/// Use `DefaultUIError` or implement your own to have more rich
/// data types including images, titles, etc.
public protocol UIError: Error, Identifiable {
public protocol UIError: Error, Identifiable, Hashable {
var message: String { get }
var isRetryable: Bool { get }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public protocol ConstantQueryRepository<Variables, Value>: HasValueResult {
/// - willGet: a callback that is invoked if the query is performed.
///
/// When using a loading controller, the function `loadingController.loading` should be passed to the `willGet` parameter.
@MainActor
func get(errorIntent: ErrorIntent, queryStrategy: QueryStrategy?, willGet: @escaping Query.WillGet) async

/// Publishes results. The publisher's first element will be the currently stored value, if any, at the time of the `publisher()` call.
Expand All @@ -43,6 +44,7 @@ public protocol ConstantQueryRepository<Variables, Value>: HasValueResult {

public extension ConstantQueryRepository {

@MainActor
func get(
errorIntent: ErrorIntent,
queryStrategy: QueryStrategy? = nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public protocol QueryRepository<QueryId, Variables, Key, Value>: HasValueResult
/// - willGet: a callback that is invoked if the query is performed.
///
/// When using a loading controller, the function `loadingController.loading` should be passed to the `willGet` parameter.
@MainActor
func get(
queryId: QueryId,
variables: Variables,
Expand Down Expand Up @@ -63,6 +64,7 @@ public protocol QueryRepository<QueryId, Variables, Key, Value>: HasValueResult

public extension QueryRepository {

@MainActor
func get(
queryId: QueryId,
variables: Variables,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public protocol VariableQueryRepository<Variables, Value>: HasValueResult {
/// - willGet: a callback that is invoked if the query is performed.
///
/// When using a loading controller, the function `loadingController.loading` should be passed to the `willGet` parameter.
@MainActor
func get(
variables: Variables,
errorIntent: ErrorIntent,
Expand All @@ -49,6 +50,7 @@ public protocol VariableQueryRepository<Variables, Value>: HasValueResult {

public extension VariableQueryRepository {

@MainActor
func get(
variables: Variables,
errorIntent: ErrorIntent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public final class DefaultConstantQueryRepository<Variables, Value>: ConstantQue

// MARK: - ConstantQueryRepository

@MainActor
public func get(
errorIntent: ErrorIntent,
queryStrategy: QueryStrategy?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ where QueryId: Hashable, Variables: Hashable, Key: Hashable {

// MARK: - QueryRepository

@MainActor
public func get(
queryId: QueryId,
variables: Variables,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public final class DefaultVariableQueryRepository<Variables, Value>: VariableQue

// MARK: - VariableQueryRepository

@MainActor
public func get(
variables: Variables,
errorIntent: ErrorIntent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public final class PagedQueryRepository<QueryId, Variables, Key, Value>: QueryRe

public typealias ValueVariablesFactory = (_ queryId: QueryId, _ variables: Variables, _ value: Value) -> Variables

@MainActor
public func get(
queryId: QueryId,
variables: Variables,
Expand Down
Loading