vds_ios/VDS/Protocols/Handlerable.swift
Matt Bruce e82a94304c refactored to remove combine for local updater, replaced with setNeedsUpdate
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2023-05-08 11:51:10 -05:00

36 lines
794 B
Swift

//
// Handlerable.swift
// VDS
//
// Created by Matt Bruce on 7/22/22.
//
import Foundation
import Combine
import UIKit
public protocol Handlerable: AnyObject, Initable, Disabling, Surfaceable {
var subscribers: Set<AnyCancellable> { get set }
var shouldUpdateView: Bool { get set }
func updateView()
}
extension Handlerable {
public func setNeedsUpdate() {
if shouldUpdateView {
shouldUpdateView = false
updateView()
shouldUpdateView = true
}
}
}
extension Handlerable where Self: UIControl {
public func addEvent(event: UIControl.Event, block: @escaping (Self)->()) {
publisher(for: event)
.sink(receiveValue: { c in
block(c)
}).store(in: &subscribers)
}
}