added back subject into the flow

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-07-14 08:17:38 -05:00
parent 270bf89b9f
commit 1934da2543
5 changed files with 38 additions and 16 deletions

View File

@ -16,6 +16,7 @@ open class Control: UIControl, Handlerable, ViewProtocol, Resettable, UserInfoab
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Combine Properties // MARK: - Combine Properties
//-------------------------------------------------- //--------------------------------------------------
public var subject = PassthroughSubject<Void, Never>()
/// Set of Subscribers for any Publishers for this Control /// Set of Subscribers for any Publishers for this Control
public var subscribers = Set<AnyCancellable>() public var subscribers = Set<AnyCancellable>()
@ -84,18 +85,18 @@ open class Control: UIControl, Handlerable, ViewProtocol, Resettable, UserInfoab
} }
} }
// /// Override to deal with setNeedsUpdate() /// Override to deal with setNeedsUpdate()
// open override var isEnabled: Bool { open override var isEnabled: Bool {
// get { !disabled } get { !disabled }
// set { set {
// if disabled != !newValue { if disabled != !newValue {
// disabled = !newValue disabled = !newValue
// } }
// isUserInteractionEnabled = isEnabled isUserInteractionEnabled = isEnabled
// setNeedsUpdate() setNeedsUpdate()
// } }
// } }
//
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Initializers // MARK: - Initializers
//-------------------------------------------------- //--------------------------------------------------
@ -123,7 +124,8 @@ open class Control: UIControl, Handlerable, ViewProtocol, Resettable, UserInfoab
if !initialSetupPerformed { if !initialSetupPerformed {
initialSetupPerformed = true initialSetupPerformed = true
setup() setup()
setNeedsUpdate() setupNeedsUpdateEvent()
updateView()
} }
} }

View File

@ -17,6 +17,7 @@ open class View: UIView, Handlerable, ViewProtocol, Resettable, UserInfoable {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Combine Properties // MARK: - Combine Properties
//-------------------------------------------------- //--------------------------------------------------
public var subject = PassthroughSubject<Void, Never>()
public var subscribers = Set<AnyCancellable>() public var subscribers = Set<AnyCancellable>()
//-------------------------------------------------- //--------------------------------------------------
@ -63,7 +64,8 @@ open class View: UIView, Handlerable, ViewProtocol, Resettable, UserInfoable {
if !initialSetupPerformed { if !initialSetupPerformed {
initialSetupPerformed = true initialSetupPerformed = true
setup() setup()
setNeedsUpdate() setupNeedsUpdateEvent()
updateView()
} }
} }

View File

@ -28,6 +28,7 @@ open class ButtonBase: UIButton, Buttonable, Handlerable, ViewProtocol, Resettab
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Combine Properties // MARK: - Combine Properties
//-------------------------------------------------- //--------------------------------------------------
public var subject = PassthroughSubject<Void, Never>()
public var subscribers = Set<AnyCancellable>() public var subscribers = Set<AnyCancellable>()
public var onClickSubscriber: AnyCancellable? { public var onClickSubscriber: AnyCancellable? {
willSet { willSet {
@ -123,7 +124,8 @@ open class ButtonBase: UIButton, Buttonable, Handlerable, ViewProtocol, Resettab
translatesAutoresizingMaskIntoConstraints = false translatesAutoresizingMaskIntoConstraints = false
accessibilityCustomActions = [] accessibilityCustomActions = []
setup() setup()
setNeedsUpdate() setupNeedsUpdateEvent()
updateView()
} }
} }

View File

@ -16,6 +16,7 @@ open class Label: UILabel, Handlerable, ViewProtocol, Resettable, UserInfoable {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Combine Properties // MARK: - Combine Properties
//-------------------------------------------------- //--------------------------------------------------
public var subject = PassthroughSubject<Void, Never>()
public var subscribers = Set<AnyCancellable>() public var subscribers = Set<AnyCancellable>()
//-------------------------------------------------- //--------------------------------------------------
@ -84,7 +85,8 @@ open class Label: UILabel, Handlerable, ViewProtocol, Resettable, UserInfoable {
accessibilityCustomActions = [] accessibilityCustomActions = []
accessibilityTraits = .staticText accessibilityTraits = .staticText
setup() setup()
setNeedsUpdate() setupNeedsUpdateEvent()
updateView()
} }
} }

View File

@ -10,12 +10,26 @@ import Combine
import UIKit import UIKit
public protocol Handlerable: AnyObject, Initable, Disabling, Surfaceable { public protocol Handlerable: AnyObject, Initable, Disabling, Surfaceable {
var subject: PassthroughSubject<Void, Never> { get set }
var subscribers: Set<AnyCancellable> { get set } var subscribers: Set<AnyCancellable> { get set }
var shouldUpdateView: Bool { get set } var shouldUpdateView: Bool { get set }
func updateView() func updateView()
} }
extension Handlerable { extension Handlerable {
public func setupNeedsUpdateEvent() {
handlerPublisher().sink { [weak self] _ in
self?.updateView()
}.store(in: &subscribers)
}
public func handlerPublisher() -> AnyPublisher<Void, Never> {
subject
.eraseToAnyPublisher()
.debounce(for: .milliseconds(50), scheduler: RunLoop.main)
.eraseToAnyPublisher()
}
public func setNeedsUpdate() { public func setNeedsUpdate() {
if shouldUpdateView { if shouldUpdateView {
shouldUpdateView = false shouldUpdateView = false