refactored CarouselItemModelProtocol to inherit FormFieldProtocol

update CarouselItemModel with FormFieldProtocol requirements

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2021-12-16 17:33:28 -06:00
parent 0ec10715c6
commit 27bca4e436
2 changed files with 13 additions and 6 deletions

View File

@ -7,7 +7,8 @@
//
@objcMembers open class CarouselItemModel: MoleculeCollectionItemModel, CarouselItemModelProtocol, EnableableModelProtocol {
@objcMembers open class CarouselItemModel: MoleculeCollectionItemModel, CarouselItemModelProtocol {
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------
@ -19,6 +20,9 @@
public var analyticsData: JSONValueDictionary?
public var fieldValue: String?
public var enabled: Bool = true
public var fieldKey: String?
public var groupName: String = FormValidator.defaultGroupName
public var baseValue: AnyHashable?
public func formFieldValue() -> AnyHashable? {
guard enabled else { return nil }
@ -34,6 +38,8 @@
case peakingArrowColor
case analyticsData
case fieldValue
case fieldKey
case groupName
}
//--------------------------------------------------
@ -46,6 +52,11 @@
peakingArrowColor = try typeContainer.decodeIfPresent(Color.self, forKey: .peakingArrowColor)
analyticsData = try typeContainer.decodeIfPresent(JSONValueDictionary.self, forKey: .analyticsData)
fieldValue = try typeContainer.decodeIfPresent(String.self, forKey: .fieldValue)
fieldKey = try typeContainer.decodeIfPresent(String.self, forKey: .fieldKey)
if let groupName = try typeContainer.decodeIfPresent(String.self, forKey: .groupName) {
self.groupName = groupName
}
baseValue = fieldValue
try super.init(from: decoder)
}

View File

@ -7,17 +7,13 @@
//
public protocol CarouselItemModelProtocol: ContainerModelProtocol {
public protocol CarouselItemModelProtocol: FormFieldProtocol, ContainerModelProtocol {
var analyticsData: JSONValueDictionary? { get set }
func formFieldValue() -> AnyHashable?
}
public extension CarouselItemModelProtocol {
var analyticsData: JSONValueDictionary? {
get { nil }
set { analyticsData = newValue }
}
func formFieldValue() -> AnyHashable? { nil }
}