Adds reset options

multistore
Laurent 2 years ago
parent bdcd3c7e08
commit e30d53bad0
  1. 19
      LeStorage/Store.swift
  2. 1
      LeStorage/StoredCollection.swift

@ -8,6 +8,11 @@
import Foundation import Foundation
import UIKit import UIKit
public enum ResetOption {
case all
case synchronizedOnly
}
enum StoreError: Error { enum StoreError: Error {
case missingService case missingService
case unexpectedCollectionType(name: String) case unexpectedCollectionType(name: String)
@ -133,18 +138,28 @@ public class Store {
} }
} }
public func disconnect(resetAll: Bool = false) { public func disconnect(resetOption: ResetOption? = nil) {
try? self.service().disconnect() try? self.service().disconnect()
self._settingsStorage.update { settings in self._settingsStorage.update { settings in
settings.username = nil settings.username = nil
settings.userId = nil settings.userId = nil
} }
if resetAll { switch resetOption {
case .all:
for collection in self._collections.values { for collection in self._collections.values {
collection.reset() collection.reset()
} }
case .synchronizedOnly:
for collection in self._collections.values {
if collection.synchronized {
collection.reset()
}
}
default:
break
} }
} }
public func hasToken() -> Bool { public func hasToken() -> Bool {

@ -19,6 +19,7 @@ protocol SomeCollection: Identifiable {
func deleteApiCallById(_ id: String) throws func deleteApiCallById(_ id: String) throws
func reset() func reset()
func loadDataFromServerIfAllowed() throws func loadDataFromServerIfAllowed() throws
var synchronized: Bool { get }
} }

Loading…
Cancel
Save