yattee/Model/Store.swift

26 lines
548 B
Swift
Raw Normal View History

2021-06-28 10:43:07 +00:00
import Foundation
import Siesta
final class Store<Data>: ResourceObserver, ObservableObject {
@Published private var all: Data?
var collection: Data { all ?? ([] as! Data) }
var item: Data? { all }
2021-07-29 22:34:13 +00:00
init(_ data: Data? = nil) {
if data != nil {
replace(data!)
}
}
2021-06-28 10:43:07 +00:00
func resourceChanged(_ resource: Resource, event _: ResourceEvent) {
if let items: Data = resource.typedContent() {
replace(items)
}
}
func replace(_ items: Data) {
all = items
}
}