Adds load state

sync
Laurent 1 year ago
parent f94b3d604b
commit db0602dcf7
  1. 4
      LeStorage/Store.swift
  2. 10
      LeStorage/StoredCollection.swift

@ -253,6 +253,10 @@ open class Store {
}
}
public func collectionsAllLoaded() -> Bool {
return self._collections.values.allSatisfy { $0.hasLoadedLocally }
}
fileprivate var _validIds: [String] = []
fileprivate func _migrate<T : Storable>(_ collection: StoredCollection<T>, identifier: StoreIdentifier, type: T.Type) {

@ -23,6 +23,7 @@ protocol CollectionHolder {
protocol SomeCollection: CollectionHolder, Identifiable {
var resourceName: String { get }
var synchronized: Bool { get }
var hasLoadedLocally: Bool { get }
func allItems() -> [any Storable]
@ -72,7 +73,10 @@ public class StoredCollection<T: Storable>: RandomAccessCollection, SomeCollecti
/// Denotes a collection that loads and writes asynchronously
fileprivate var asynchronousIO: Bool = true
/// Indicates if the collection has loaded locally, with or without a file
fileprivate(set) public var hasLoadedLocally: Bool = false
/// Indicates if the collection has loaded objects from the server
fileprivate(set) public var hasLoadedFromServer: Bool = false
@ -136,6 +140,9 @@ public class StoredCollection<T: Storable>: RandomAccessCollection, SomeCollecti
/// Decodes the json file into the items array
fileprivate func _decodeJSONFile() throws {
defer { self.hasLoadedLocally = true }
let fileURL = try self._store.fileURL(type: T.self)
if FileManager.default.fileExists(atPath: fileURL.path()) {
@ -228,6 +235,7 @@ public class StoredCollection<T: Storable>: RandomAccessCollection, SomeCollecti
}
/// Sends a POST request for the instance, and changes the collection to perform a write
public func writeChangeAndInsertOnServer(instance: T) {
defer {
self._hasChanged = true

Loading…
Cancel
Save