sync2
Laurent 10 months ago
commit b993d920a0
  1. 9
      LeStorage/StoredCollection+Sync.swift

@ -30,8 +30,12 @@ extension StoredCollection: SomeSyncedCollection where T : SyncedStorable {
}
}
func loadDataFromServerIfAllowed() async throws {
try await self.loadDataFromServerIfAllowed(clear: false)
}
/// Retrieves the data from the server and loads it into the items array
public func loadDataFromServerIfAllowed() async throws {
public func loadDataFromServerIfAllowed(clear: Bool = false) async throws {
guard !(self is StoredSingleton<T>) else {
throw StoreError.cannotSyncCollection(name: self.resourceName)
}
@ -39,6 +43,9 @@ extension StoredCollection: SomeSyncedCollection where T : SyncedStorable {
let items: [T] = try await self.store.getItems()
if items.count > 0 {
DispatchQueue.main.async {
if clear {
self.clear()
}
self.addOrUpdateNoSync(contentOfs: items)
}
}

Loading…
Cancel
Save