1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-12 21:30:32 +05:30
yattee/Model/Store.swift
Toni Förster 13382270d5
Revert "fixed some potential crashes"
This reverts commit bde9aade11.
2024-08-31 02:50:56 +02:00

30 lines
614 B
Swift

import Foundation
import Siesta
final class Store<Data>: ResourceObserver, ObservableObject {
@Published private var all: Data?
var collection: Data { all ?? ([item].compactMap { $0 } 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
}
func clear() {
all = nil
}
}