Open royhsu opened 6 years ago
protocol Storage: Collection { var changes: Observable<Changes> { get } var isLoaded: Bool { get } subscript(key: Key) -> Value? func load() } protocol AsyncStorage: Storage { func value( forKey key: Key, completion: (Result<Value>) -> Void ) } protocol MutableStorage: Storage { func merge(_ other: Sequence) } concrete SyncStorage: MutableStorage { func addChild(_ storage: Storage) { storage.changes.observe { child in self.merge(child) } } subscript(key: Key) -> Value? { for child in childStorages { if let value = child[key] { return value } } asynchronouslyGettingValueFromChildStoragesIfNeeded() } }
The updating strategy is like how CoreData does.