1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-12 21:30:32 +05:30
yattee/Model/Store.swift

30 lines
614 B
Swift
Raw Permalink Normal View History

2021-06-28 16:13:07 +05:30
import Foundation
import Siesta
final class Store<Data>: ResourceObserver, ObservableObject {
@Published private var all: Data?
2023-06-17 17:39:51 +05:30
var collection: Data { all ?? ([item].compactMap { $0 } as! Data) }
2021-06-28 16:13:07 +05:30
var item: Data? { all }
2021-07-30 04:04:13 +05:30
init(_ data: Data? = nil) {
if data != nil {
replace(data!)
}
}
2021-06-28 16:13:07 +05:30
func resourceChanged(_ resource: Resource, event _: ResourceEvent) {
if let items: Data = resource.typedContent() {
replace(items)
}
}
func replace(_ items: Data) {
all = items
}
2022-05-30 01:42:59 +05:30
func clear() {
all = nil
}
2021-06-28 16:13:07 +05:30
}