added Identifiable

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2022-09-15 13:56:58 -05:00
parent 78443263ba
commit e07f855eb6
17 changed files with 34 additions and 14 deletions

View File

@ -34,15 +34,15 @@ public class SelectorGroupHandlerBase<GroupModelType: SelectorGroupModelable, Mo
} }
} }
public func findSelectorView(inputId: String?) -> ModelHandlerType? { public func findSelectorView(id: UUID?) -> ModelHandlerType? {
return selectorViews.first(where: { existingSelectorView in return selectorViews.first(where: { existingSelectorView in
return existingSelectorView.model.inputId == inputId return existingSelectorView.model.id == id
}) })
} }
public func getCachedSelector(viewModel: ModelHandlerType.ModelType) -> ModelHandlerType.ModelType? { public func getCachedSelector(viewModel: ModelHandlerType.ModelType) -> ModelHandlerType.ModelType? {
if let index = model.selectors.firstIndex(where: { element in if let index = model.selectors.firstIndex(where: { element in
return element.inputId == viewModel.inputId return element.id == viewModel.id
}) { }) {
return model.selectors[index] return model.selectors[index]
} else { } else {
@ -52,7 +52,7 @@ public class SelectorGroupHandlerBase<GroupModelType: SelectorGroupModelable, Mo
public func replace(viewModel: ModelHandlerType.ModelType){ public func replace(viewModel: ModelHandlerType.ModelType){
if let index = model.selectors.firstIndex(where: { element in if let index = model.selectors.firstIndex(where: { element in
return element.inputId == viewModel.inputId return element.id == viewModel.id
}) { }) {
model.selectors[index] = viewModel model.selectors[index] = viewModel
} }

View File

@ -79,7 +79,7 @@ public class CheckboxGroupBase<GroupModelType: CheckboxGroupModel, ModelHandlerT
open override func updateView(viewModel: ModelType) { open override func updateView(viewModel: ModelType) {
for selectorModel in viewModel.selectors { for selectorModel in viewModel.selectors {
//see if view is there for the model //see if view is there for the model
if let foundSelectorView = findSelectorView(inputId: selectorModel.inputId) { if let foundSelectorView = findSelectorView(id: selectorModel.id) {
foundSelectorView.set(with: selectorModel) foundSelectorView.set(with: selectorModel)
} else { } else {

View File

@ -13,6 +13,7 @@ public protocol CheckboxGroupModel: SelectorGroupModelable, Errorable where Sele
public struct DefaultCheckboxGroupModel: CheckboxGroupModel { public struct DefaultCheckboxGroupModel: CheckboxGroupModel {
public typealias SelectorModelType = DefaultCheckboxModel public typealias SelectorModelType = DefaultCheckboxModel
public var id = UUID()
public var inputId: String? public var inputId: String?
public var value: AnyHashable? public var value: AnyHashable?
public var surface: Surface = .light public var surface: Surface = .light
@ -24,4 +25,5 @@ public struct DefaultCheckboxGroupModel: CheckboxGroupModel {
public init(selectors: [SelectorModelType]){ public init(selectors: [SelectorModelType]){
self.selectors = selectors self.selectors = selectors
} }
} }

View File

@ -64,8 +64,8 @@ extension CheckboxModel {
} }
public struct DefaultCheckboxModel: CheckboxModel { public struct DefaultCheckboxModel: CheckboxModel {
public var id = UUID()
public var selected: Bool = false public var selected: Bool = false
public var labelText: String? public var labelText: String?
public var labelTextAttributes: [LabelAttributeModel]? public var labelTextAttributes: [LabelAttributeModel]?
public var childText: String? public var childText: String?

View File

@ -14,6 +14,7 @@ public protocol LabelModel: Modelable, Labelable {
} }
public struct DefaultLabelModel: LabelModel { public struct DefaultLabelModel: LabelModel {
public var id = UUID()
public var text: String? public var text: String?
public var attributes: [LabelAttributeModel]? public var attributes: [LabelAttributeModel]?
public var typograpicalStyle: TypographicalStyle = .BodySmall public var typograpicalStyle: TypographicalStyle = .BodySmall

View File

@ -80,7 +80,7 @@ public class RadioBoxGroupBase<GroupModelType: RadioBoxGroupModel, ModelHandlerT
open override func updateView(viewModel: ModelType) { open override func updateView(viewModel: ModelType) {
for selectorModel in viewModel.selectors { for selectorModel in viewModel.selectors {
//see if view is there for the model //see if view is there for the model
if let foundSelectorView = findSelectorView(inputId: selectorModel.inputId) { if let foundSelectorView = findSelectorView(id: selectorModel.id) {
foundSelectorView.set(with: selectorModel) foundSelectorView.set(with: selectorModel)
} else { } else {

View File

@ -11,6 +11,7 @@ public protocol RadioBoxGroupModel: SelectorGroupSelectedModelable where Selecto
public struct DefaultRadioBoxGroupModel: RadioBoxGroupModel { public struct DefaultRadioBoxGroupModel: RadioBoxGroupModel {
public typealias SelectorModelType = DefaultRadioBoxModel public typealias SelectorModelType = DefaultRadioBoxModel
public var id = UUID()
public var inputId: String? public var inputId: String?
public var value: AnyHashable? public var value: AnyHashable?
public var surface: Surface = .light public var surface: Surface = .light

View File

@ -58,9 +58,8 @@ extension RadioBoxModel {
} }
public struct DefaultRadioBoxModel: RadioBoxModel { public struct DefaultRadioBoxModel: RadioBoxModel {
public var id = UUID()
public var selected: Bool = false public var selected: Bool = false
public var text: String = "Default Text" public var text: String = "Default Text"
public var textAttributes: [LabelAttributeModel]? public var textAttributes: [LabelAttributeModel]?
public var subText: String? public var subText: String?

View File

@ -81,7 +81,7 @@ public class RadioButtonGroupBase<GroupModelType: RadioButtonGroupModel, ModelHa
open override func updateView(viewModel: ModelType) { open override func updateView(viewModel: ModelType) {
for selectorModel in viewModel.selectors { for selectorModel in viewModel.selectors {
//see if view is there for the model //see if view is there for the model
if let foundSelectorView = findSelectorView(inputId: selectorModel.inputId) { if let foundSelectorView = findSelectorView(id: selectorModel.id) {
foundSelectorView.set(with: selectorModel) foundSelectorView.set(with: selectorModel)
} else { } else {

View File

@ -15,6 +15,7 @@ extension RadioButtonGroupModel {
public struct DefaultRadioButtonGroupModel: RadioButtonGroupModel { public struct DefaultRadioButtonGroupModel: RadioButtonGroupModel {
public typealias SelectorModelType = DefaultRadioButtonModel public typealias SelectorModelType = DefaultRadioButtonModel
public var id = UUID()
public var inputId: String? public var inputId: String?
public var value: AnyHashable? public var value: AnyHashable?
public var surface: Surface = .light public var surface: Surface = .light

View File

@ -64,6 +64,7 @@ extension RadioButtonModel {
} }
public struct DefaultRadioButtonModel: RadioButtonModel { public struct DefaultRadioButtonModel: RadioButtonModel {
public var id = UUID()
public var selected: Bool = false public var selected: Bool = false
public var labelText: String? public var labelText: String?

View File

@ -153,7 +153,7 @@ public class RadioSwatchGroupBase<GroupModelType: RadioSwatchGroupModel, ModelHa
public func replace(viewModel: ModelHandlerType.ModelType){ public func replace(viewModel: ModelHandlerType.ModelType){
if let index = model.selectors.firstIndex(where: { element in if let index = model.selectors.firstIndex(where: { element in
return element.inputId == viewModel.inputId return element.id == viewModel.id
}) { }) {
model.selectors[index] = viewModel model.selectors[index] = viewModel
} }

View File

@ -23,6 +23,7 @@ extension RadioSwatchGroupModel {
public struct DefaultRadioSwatchGroupModel: RadioSwatchGroupModel { public struct DefaultRadioSwatchGroupModel: RadioSwatchGroupModel {
public typealias SelectorModelType = DefaultRadioSwatchModel public typealias SelectorModelType = DefaultRadioSwatchModel
public var id = UUID()
public var inputId: String? public var inputId: String?
public var value: AnyHashable? public var value: AnyHashable?
public var surface: Surface = .light public var surface: Surface = .light

View File

@ -17,7 +17,8 @@ public protocol RadioSwatchModel: Modelable, FormFieldable, DataTrackable, Acces
} }
public func == (lhs: any RadioSwatchModel, rhs: any RadioSwatchModel) -> Bool { public func == (lhs: any RadioSwatchModel, rhs: any RadioSwatchModel) -> Bool {
return lhs.selected == rhs.selected && return lhs.id == rhs.id &&
lhs.selected == rhs.selected &&
lhs.fillImage == rhs.fillImage && lhs.fillImage == rhs.fillImage &&
lhs.primaryColor == rhs.primaryColor && lhs.primaryColor == rhs.primaryColor &&
lhs.secondaryColor == rhs.secondaryColor && lhs.secondaryColor == rhs.secondaryColor &&
@ -38,7 +39,7 @@ public func == (lhs: any RadioSwatchModel, rhs: any RadioSwatchModel) -> Bool {
} }
public struct DefaultRadioSwatchModel: RadioSwatchModel { public struct DefaultRadioSwatchModel: RadioSwatchModel {
public var id = UUID()
public var selected: Bool = false public var selected: Bool = false
public var fillImage: UIImage? public var fillImage: UIImage?

View File

@ -30,6 +30,7 @@ extension ToggleModel {
} }
public struct DefaultToggleModel: ToggleModel { public struct DefaultToggleModel: ToggleModel {
public var id = UUID()
public var on: Bool = false public var on: Bool = false
public var showText: Bool = false public var showText: Bool = false
public var offText: String = "Off" public var offText: String = "Off"

View File

@ -7,6 +7,12 @@
import Foundation import Foundation
public protocol Modelable: Surfaceable, Disabling, Initable, Withable { public protocol Modelable: Surfaceable, Disabling, Initable, Withable, Identifiable, CustomDebugStringConvertible where ID == UUID {
} }
extension Modelable {
public var debugDescription: String {
return "\(id.uuidString)"
}
}

View File

@ -13,6 +13,12 @@ public protocol SelectorGroupModelable: Modelable, FormFieldable {
var selectors: [SelectorModelType] { get set } var selectors: [SelectorModelType] { get set }
} }
extension SelectorGroupModelable {
public var debugDescription: String {
"group id: \(id.uuidString)\r\(selectors.compactMap{"id: \($0.debugDescription) \($0.selected ? "*" : "")"}.joined(separator: "\r"))"
}
}
///MARK: Groups that allow single selections ///MARK: Groups that allow single selections
public protocol SelectorGroupSelectedModelable: SelectorGroupModelable { public protocol SelectorGroupSelectedModelable: SelectorGroupModelable {
var selectedModel: SelectorModelType? { get } var selectedModel: SelectorModelType? { get }