Removes api calls from deleted dependencies

multistore
Laurent 1 year ago
parent 164e63363c
commit 59f85f998b
  1. 8
      LeStorage/Codables/ApiCall.swift
  2. 2
      LeStorage/Store.swift
  3. 7
      LeStorage/StoredCollection.swift

@ -8,7 +8,6 @@
import Foundation
protocol SomeCall: Storable {
// func execute() throws
var lastAttemptDate: Date { get }
}
@ -44,11 +43,4 @@ class ApiCall<T: Storable>: ModelObject, Storable, SomeCall {
self.body = body
}
/// Executes the api call
// func execute() throws {
// Task {
// try await Store.main.execute(apiCall: self)
// }
// }
}

@ -255,7 +255,7 @@ public class Store {
}
public func hasPendingAPICalls() -> Bool {
return self._collections.values.allSatisfy { $0.hasPendingAPICalls() }
return self._collections.values.contains(where: { $0.hasPendingAPICalls() })
}
}

@ -294,13 +294,20 @@ public class StoredCollection<T: Storable>: RandomAccessCollection, SomeCollecti
}
/// Proceeds to "hard" delete the items without synchronizing them
/// Also removes related API calls
public func deleteDependencies(_ items: any Sequence<T>) {
defer {
self._hasChanged = true
}
for item in items {
self.items.removeAll(where: { $0.id == item.id })
/// remove related API call if existing
if let apiCallIndex = self.apiCallsCollection?.firstIndex(where: { $0.dataId == item.id }) {
self.apiCallsCollection?.items.remove(at: apiCallIndex)
}
}
}
public func deleteAll() throws {

Loading…
Cancel
Save