baby steps in refactoring out methods
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
2148014664
commit
f68a815680
@ -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 {
|
||||
|
||||
@ -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 = [] }
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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?
|
||||
|
||||
@ -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
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user