Skip to content

Commit

Permalink
Keep a ref to store in AnyStore classes (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
omaralbeik authored Jul 30, 2023
1 parent b835f7e commit 6382917
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Sources/Blueprints/AnyMultiObjectStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public final class AnyMultiObjectStore<
public init<Store: MultiObjectStore>(
_ store: Store
) where Store.Object == Object {
_store = store
_save = { try store.save($0) }
_saveOptional = { try store.save($0) }
_saveObjects = { try store.save($0) }
Expand All @@ -20,6 +21,7 @@ public final class AnyMultiObjectStore<
_removeAll = { try store.removeAll() }
}

private let _store: any MultiObjectStore
private let _save: (Object) throws -> Void
private let _saveOptional: (Object?) throws -> Void
private let _saveObjects: ([Object]) throws -> Void
Expand Down
2 changes: 2 additions & 0 deletions Sources/Blueprints/AnySingleObjectStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ public final class AnySingleObjectStore<Object: Codable>: SingleObjectStore {
public init<Store: SingleObjectStore>(
_ store: Store
) where Store.Object == Object {
_store = store
_save = { try store.save($0) }
_saveOptional = { try store.save($0) }
_object = { store.object() }
_remove = { try store.remove() }
}

private let _store: any SingleObjectStore
private let _save: (Object) throws -> Void
private let _saveOptional: (Object?) throws -> Void
private let _object: () -> Object?
Expand Down

0 comments on commit 6382917

Please sign in to comment.