diff --git a/VDS/Components/RadioButton/RadioButtonGroup.swift b/VDS/Components/RadioButton/RadioButtonGroup.swift index 0e7a2acc..45cc56a9 100644 --- a/VDS/Components/RadioButton/RadioButtonGroup.swift +++ b/VDS/Components/RadioButton/RadioButtonGroup.swift @@ -11,9 +11,9 @@ public class RadioButtonGroup: RadioButtonGroupBase>: SelectorGroupBase { - public override func didSelect(selected: RadioButtonGroupModelType.SelectorType) { + public override func didSelect(selected: RadioButtonGroupModelType.SelectorType) { for selectorModel in model.selectors { - print("Pre Cached Selector: \(selectorModel.inputId): \(selectorModel.selected)") + print("Pre Cached Selector: \(selectorModel.id): \(selectorModel.selected)") } if var oldSelectedModel = selectedModel { @@ -26,9 +26,9 @@ public class RadioButtonGroupBase>: View, Changable where SelectorType == SelectorGroupType.SelectorType { public var selectorViews: [SelectorHandlerType] = [] + + @Proxy(\.model.selectedModel) public var selectedModel: SelectorType? + public var onChange: Blocks.ActionBlock? //-------------------------------------------------- @@ -88,11 +91,12 @@ open class SelectorGroupBase 0 else { return } self?.didSelect(selected: model) }.store(in: &cancellables) //add model update to the subscribers - newSelectorView.$model.sink { [weak self] model in + newSelectorView.$model.debounce(for: .seconds(Constants.ModelStateDebounce), scheduler: RunLoop.main).sink { [weak self] model in if let cached = self?.getCachedSelector(viewModel: model), newSelectorView.shouldUpdateView(viewModel: cached) { self?.replace(viewModel: model) } diff --git a/VDS/Components/Selector/SelectorGroupModel.swift b/VDS/Components/Selector/SelectorGroupModel.swift index e52dfa7c..9caae3ca 100644 --- a/VDS/Components/Selector/SelectorGroupModel.swift +++ b/VDS/Components/Selector/SelectorGroupModel.swift @@ -9,6 +9,7 @@ import Foundation public protocol SelectorGroupModel: Modelable, FormFieldable { associatedtype SelectorType: SelectorModel + var selectedModel: SelectorType? { get set } var selectors: [SelectorType] { get set } } @@ -18,6 +19,7 @@ public struct DefaultSelectorGroupModel: SelectorGr public var value: AnyHashable? public var surface: Surface = .light public var disabled: Bool = false + public var selectedModel: SelectorType? public var selectors: [SelectorType] public init() { selectors = [] } public init(selectors: [SelectorType]){