1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-15 14:50:32 +05:30
yattee/Model/Store.swift
2021-07-30 00:45:24 +02:00

26 lines
548 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 }
init(_ data: Data? = nil) {
if data != nil {
replace(data!)
}
}
func resourceChanged(_ resource: Resource, event _: ResourceEvent) {
if let items: Data = resource.typedContent() {
replace(items)
}
}
func replace(_ items: Data) {
all = items
}
}