baby steps in refactoring out methods

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2022-09-08 14:48:07 -05:00
parent 2148014664
commit f68a815680
5 changed files with 58 additions and 47 deletions

View File

@ -11,21 +11,38 @@ import UIKit
public class RadioBoxGroup: Control<DefaultRadioBoxGroupModel>, SelectorGroupSelectedModelHandlerable, Changable {
public typealias ModelHandlerType = RadioBox
public func didSelect(_ selectedControl: ModelHandlerType) {
//only changes local model in control,
//this is now disconnected from the parent model
for (index, control) in selectorViews.enumerated() {
//only change the old and new
if control == selectedControl {
let updated = model.selectors[index].copyWith {
$0.selected = true
}
model.selectors[index] = updated
} else if control.isSelected {
let updated = model.selectors[index].copyWith {
$0.selected = false
}
model.selectors[index] = updated
}
}
if hasError {
hasError = false
}
sendActions(for: .valueChanged)
}
//--------------------------------------------------
// MARK: - Public Properties
//--------------------------------------------------
public var selectorViews: [ModelHandlerType] = []
@Proxy(\.model.selectedInputId)
public var selectedInputId: String? {
didSet{
if hasError, selectedInputId != nil {
hasError = false
}
sendActions(for: .valueChanged)
}
}
public var hasError: Bool {
get { model.hasError }
set {

View File

@ -16,7 +16,6 @@ public struct DefaultRadioBoxGroupModel: RadioBoxGroupModel {
public var surface: Surface = .light
public var disabled: Bool = false
public var selectors: [SelectorModelType]
public var selectedInputId: String?
public var hasError: Bool = false
public var errorText: String?
public init() { selectors = [] }

View File

@ -11,26 +11,44 @@ import UIKit
public class RadioButtonGroup: Control<DefaultRadioButtonGroupModel>, SelectorGroupSelectedModelHandlerable, Changable {
public typealias ModelHandlerType = RadioButton
public func didSelect(_ selectedControl: ModelHandlerType) {
//only changes local model in control,
//this is now disconnected from the parent model
for (index, control) in selectorViews.enumerated() {
//only change the old and new
if control == selectedControl {
let updated = model.selectors[index].copyWith {
$0.selected = true
}
model.selectors[index] = updated
} else if control.isSelected {
let updated = model.selectors[index].copyWith {
$0.selected = false
}
model.selectors[index] = updated
}
}
if hasError {
hasError = false
}
sendActions(for: .valueChanged)
}
//--------------------------------------------------
// MARK: - Public Properties
//--------------------------------------------------
public var selectorViews: [ModelHandlerType] = []
@Proxy(\.model.selectedInputId)
public var selectedInputId: String? {
didSet{
if hasError, selectedInputId != nil {
hasError = false
}
sendActions(for: .valueChanged)
}
}
public var hasError: Bool {
get { model.hasError }
set {
var newHasError = newValue
if selectedInputId != nil, newHasError {
if selectedModel != nil, newHasError {
newHasError = false
}
let selectors = model.selectors.compactMap { existing in

View File

@ -14,7 +14,6 @@ extension RadioButtonGroupModel {
}
public struct DefaultRadioButtonGroupModel: RadioButtonGroupModel {
public var selectedInputId: String?
public typealias SelectorModelType = DefaultRadioButtonModel
public var inputId: String?
public var value: AnyHashable?

View File

@ -101,26 +101,4 @@ extension SelectorGroupSelectedModelHandlerable {
return newSelectorView
}
public func didSelect(_ selectedControl: ModelHandlerType) {
//only changes local model in control,
//this is now disconnected from the parent model
for (index, control) in selectorViews.enumerated() {
//only change the old and new
if control == selectedControl {
let updated = model.selectors[index].copyWith {
$0.selected = true
}
model.selectors[index] = updated
} else if control.isSelected {
let updated = model.selectors[index].copyWith {
$0.selected = false
}
model.selectors[index] = updated
}
}
}
}