diff --git a/VDS/Components/Buttons/Button/ButtonBase.swift b/VDS/Components/Buttons/Button/ButtonBase.swift index 41633216..cafd5cd8 100644 --- a/VDS/Components/Buttons/Button/ButtonBase.swift +++ b/VDS/Components/Buttons/Button/ButtonBase.swift @@ -121,7 +121,7 @@ open class ButtonBase: UIButton, Buttonable, Handlerable, ViewProtocol, Resettab translatesAutoresizingMaskIntoConstraints = false accessibilityCustomActions = [] setup() - setupDidChangeEvent() + setupDidChangeEvent(true) updateView() } } diff --git a/VDS/Components/Label/Label.swift b/VDS/Components/Label/Label.swift index 5f347634..db15ce0d 100644 --- a/VDS/Components/Label/Label.swift +++ b/VDS/Components/Label/Label.swift @@ -94,7 +94,7 @@ public class Label: UILabel, Handlerable, ViewProtocol, Resettable, UserInfoable accessibilityCustomActions = [] accessibilityTraits = .staticText setup() - setupDidChangeEvent() + setupDidChangeEvent(true) updateView() } } diff --git a/VDS/Protocols/Handlerable.swift b/VDS/Protocols/Handlerable.swift index 41ef01b5..cefb150f 100644 --- a/VDS/Protocols/Handlerable.swift +++ b/VDS/Protocols/Handlerable.swift @@ -17,15 +17,22 @@ public protocol Handlerable: AnyObject, Initable, Disabling, Surfaceable { extension Handlerable { - public func setupDidChangeEvent() { - handlerPublisher().sink { [weak self] _ in - self?.updateView() + public func setupDidChangeEvent(_ debounce: Bool = false) { + handlerPublisher(debounce) + .sink { [weak self] _ in + self?.updateView() }.store(in: &subscribers) } - public func handlerPublisher() -> AnyPublisher { - subject - .eraseToAnyPublisher() + public func handlerPublisher(_ debounce: Bool = false) -> AnyPublisher { + if debounce { + return subject + .debounce(for: .seconds(Constants.StateDebounce), scheduler: RunLoop.main) + .eraseToAnyPublisher() + } else { + return subject + .eraseToAnyPublisher() + } } }