mirror of
https://github.com/yattee/yattee.git
synced 2024-12-22 21:43:41 +00:00
20 lines
447 B
Swift
20 lines
447 B
Swift
|
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 }
|
||
|
|
||
|
func resourceChanged(_ resource: Resource, event _: ResourceEvent) {
|
||
|
if let items: Data = resource.typedContent() {
|
||
|
replace(items)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func replace(_ items: Data) {
|
||
|
all = items
|
||
|
}
|
||
|
}
|