NetNewsWire/Multiplatform/Shared/Sidebar/SidebarExpandedContainers.s...

49 lines
1.0 KiB
Swift
Raw Normal View History

//
// SidebarExpandedContainers.swift
// NetNewsWire
//
// Created by Maurice Parker on 6/30/20.
// Copyright © 2020 Ranchero Software. All rights reserved.
//
import SwiftUI
import Combine
import Account
final class SidebarExpandedContainers: ObservableObject {
@Published var expandedTable = Set<ContainerIdentifier>()
var objectDidChange = PassthroughSubject<Void, Never>()
var data: Data {
get {
let encoder = PropertyListEncoder()
encoder.outputFormat = .binary
return (try? encoder.encode(expandedTable)) ?? Data()
}
set {
let decoder = PropertyListDecoder()
expandedTable = (try? decoder.decode(Set<ContainerIdentifier>.self, from: newValue)) ?? Set<ContainerIdentifier>()
}
}
subscript(_ containerID: ContainerIdentifier) -> Bool {
get {
if expandedTable.contains(containerID) {
return true
} else {
return false
}
}
set(newValue) {
if newValue {
expandedTable.insert(containerID)
} else {
expandedTable.remove(containerID)
}
objectDidChange.send()
}
}
}