Change ID default initializer, DecodableDefault for implicit decoding models. Add missing id encodes and decodes.

This commit is contained in:
Hedden, Kyle Matthew 2023-09-07 09:20:44 -04:00
parent 94defaa6bc
commit b6c3159b52
63 changed files with 108 additions and 61 deletions

View File

@ -18,7 +18,7 @@ open class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWat
//--------------------------------------------------
//Making static property as class property so that subclasses can override getter function of the property
open class var identifier: String { "button" }
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
public var accessibilityIdentifier: String?
public var accessibilityText: String?

View File

@ -16,7 +16,7 @@ public class CaretLinkModel: ButtonModelProtocol, MoleculeModelProtocol, Enablea
//--------------------------------------------------
public static var identifier: String = "caretLink"
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
public var backgroundColor: Color?
public var accessibilityIdentifier: String?
public var title: String

View File

@ -14,7 +14,7 @@ open class ImageButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGro
//--------------------------------------------------
public static var identifier: String = "imageButton"
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
public var backgroundColor: Color?
public var image: ImageViewModel?
@ -54,6 +54,7 @@ open class ImageButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGro
required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
id = try typeContainer.decodeIfPresent(String.self, forKey: .id) ?? UUID().uuidString
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
image = try typeContainer.decodeIfPresent(ImageViewModel.self, forKey: .image)
accessibilityText = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityText)
@ -79,6 +80,7 @@ open class ImageButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGro
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(id, forKey: .id)
try container.encode(moleculeName, forKey: .moleculeName)
try container.encodeIfPresent(image, forKey: .image)
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)

View File

@ -15,7 +15,7 @@ open class LinkModel: ButtonModelProtocol, MoleculeModelProtocol, EnableableMode
//--------------------------------------------------
public class var identifier: String { "link" }
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
public var backgroundColor: Color?
public var accessibilityIdentifier: String?

View File

@ -11,7 +11,7 @@ import MVMCore
@objcMembers public class TagModel: MoleculeModelProtocol {
public static var identifier: String = "tag"
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
public var label: LabelModel
public var action: ActionModelProtocol?
@ -41,6 +41,7 @@ import MVMCore
required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
id = try typeContainer.decodeIfPresent(String.self, forKey: .id) ?? UUID().uuidString
label = try typeContainer.decode(LabelModel.self, forKey: .label)
action = try typeContainer.decodeModelIfPresent(codingKey: .action)
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
@ -48,6 +49,7 @@ import MVMCore
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(id, forKey: .id)
try container.encode(moleculeName, forKey: .moleculeName)
try container.encode(label, forKey: .label)
try container.encodeModelIfPresent(action, forKey: .action)

View File

@ -11,7 +11,7 @@ import MVMCore
@objcMembers public class TagsModel: MoleculeModelProtocol {
public static var identifier: String = "tags"
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
public var backgroundColor: Color?
public var tags: [TagModel]

View File

@ -16,7 +16,7 @@ import Foundation
//--------------------------------------------------
public class var identifier: String { "" }
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
public var backgroundColor: Color?
public var accessibilityIdentifier: String?

View File

@ -20,7 +20,7 @@
//--------------------------------------------------
public static var identifier: String = "checkbox"
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
public var backgroundColor: Color?
public var accessibilityIdentifier: String?
public var selected: Bool = false
@ -109,6 +109,8 @@
required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
id = try typeContainer.decodeIfPresent(String.self, forKey: .id) ?? UUID().uuidString
accessibilityIdentifier = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityIdentifier)
if let borderWidth = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .borderWidth) {
@ -182,6 +184,7 @@
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(id, forKey: .id)
try container.encode(moleculeName, forKey: .moleculeName)
try container.encodeIfPresent(groupName, forKey: .groupName)
try container.encodeIfPresent(fieldKey, forKey: .fieldKey)

View File

@ -14,7 +14,7 @@ open class HeartModel: MoleculeModelProtocol, EnableableModelProtocol {
//--------------------------------------------------
public static var identifier: String = "heart"
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
public var backgroundColor: Color?
public var accessibilityIdentifier: String?
@ -80,6 +80,7 @@ open class HeartModel: MoleculeModelProtocol, EnableableModelProtocol {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
try container.encodeIfPresent(accessibilityIdentifier, forKey: .accessibilityIdentifier)
try container.encode(id, forKey: .id)
try container.encode(moleculeName, forKey: .moleculeName)
try container.encode(isActive, forKey: .isActive)
try container.encode(activeColor, forKey: .activeColor)

View File

@ -13,7 +13,7 @@ import MVMCore
//--------------------------------------------------
public static var identifier: String = "radioBox"
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
public var text: String
public var subText: String?

View File

@ -13,7 +13,7 @@ import MVMCore
//--------------------------------------------------
public static var identifier: String = "radioBoxes"
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
public var boxes: [RadioBoxModel]
public var backgroundColor: Color?
@ -78,6 +78,7 @@ import MVMCore
required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
id = try typeContainer.decodeIfPresent(String.self, forKey: .id) ?? UUID().uuidString
selectedAccentColor = try typeContainer.decodeIfPresent(Color.self, forKey: .selectedAccentColor)
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
accessibilityIdentifier = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityIdentifier)
@ -94,6 +95,7 @@ import MVMCore
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(id, forKey: .id)
try container.encode(moleculeName, forKey: .moleculeName)
try container.encode(boxes, forKey: .boxes)
try container.encodeIfPresent(selectedAccentColor, forKey: .selectedAccentColor)

View File

@ -15,7 +15,7 @@ open class RadioButtonModel: MoleculeModelProtocol, FormFieldProtocol {
//--------------------------------------------------
public static var identifier: String = "radioButton"
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
public var backgroundColor: Color?
public var accessibilityIdentifier: String?
@ -110,6 +110,7 @@ open class RadioButtonModel: MoleculeModelProtocol, FormFieldProtocol {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
try container.encodeIfPresent(accessibilityIdentifier, forKey: .accessibilityIdentifier)
try container.encode(id, forKey: .id)
try container.encode(moleculeName, forKey: .moleculeName)
try container.encode(state, forKey: .state)
try container.encode(enabled, forKey: .enabled)

View File

@ -13,7 +13,7 @@ import MVMCore
//--------------------------------------------------
public static var identifier: String = "radioSwatch"
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
public var backgroundColor: Color?
public var accessibilityIdentifier: String?

View File

@ -13,7 +13,7 @@ import MVMCore
//--------------------------------------------------
public static var identifier: String = "radioSwatches"
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
public var backgroundColor: Color?
public var accessibilityIdentifier: String?

View File

@ -13,7 +13,7 @@ public class ToggleModel: MoleculeModelProtocol, FormFieldProtocol {
//--------------------------------------------------
public static var identifier: String = "toggle"
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
public var accessibilityIdentifier: String?
public var backgroundColor: Color?

View File

@ -18,7 +18,7 @@ open class ArrowModel: MoleculeModelProtocol, EnableableModelProtocol {
return "arrow"
}
public var moleculeName: String?
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
public var backgroundColor: Color?
public var disabledColor: Color = Color(uiColor: .mvmCoolGray3)

View File

@ -15,7 +15,7 @@ import MVMCore
//--------------------------------------------------
public static var identifier: String = "caretView"
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
public var backgroundColor: Color?
public var strokeColor: Color = Color(uiColor: .mvmBlack)
public var strokeColor_inverted: Color = Color(uiColor: .mvmWhite)
@ -53,6 +53,8 @@ import MVMCore
required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
id = try typeContainer.decodeIfPresent(String.self, forKey: .id) ?? UUID().uuidString
if let strokeColor = try typeContainer.decodeIfPresent(Color.self, forKey: .strokeColor) {
self.strokeColor = strokeColor
}
@ -80,6 +82,7 @@ import MVMCore
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(id, forKey: .id)
try container.encode(moleculeName, forKey: .moleculeName)
try container.encode(strokeColor, forKey: .strokeColor)
try container.encode(strokeColor_inverted, forKey: .strokeColor_inverted)

View File

@ -18,7 +18,7 @@ open class CarouselIndicatorModel: CarouselPagingModelProtocol, MoleculeModelPro
return ""
}
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
public var backgroundColor: Color?
public var moleculeName: String?
public var numberOfPages: Int = 0
@ -68,6 +68,7 @@ open class CarouselIndicatorModel: CarouselPagingModelProtocol, MoleculeModelPro
required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
id = try typeContainer.decodeIfPresent(String.self, forKey: .id) ?? UUID().uuidString
moleculeName = try typeContainer.decodeIfPresent(String.self, forKey: .moleculeName)
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
@ -114,6 +115,7 @@ open class CarouselIndicatorModel: CarouselPagingModelProtocol, MoleculeModelPro
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(id, forKey: .id)
try container.encodeIfPresent(moleculeName, forKey: .moleculeName)
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
try container.encode(numberOfPages, forKey: .numberOfPages)

View File

@ -18,7 +18,7 @@ public enum CheckboxPosition: String, Codable {
@objcMembers open class CheckboxLabelModel: MoleculeModelProtocol {
open class var identifier: String { "checkboxLabel" }
public var moleculeName: String = CheckboxLabelModel.identifier
public var id: String = { return UUID().uuidString }()
@DecodableDefault.UUID public var id: String
public var backgroundColor: Color?
public var checkboxAlignment: CheckboxPosition?

View File

@ -15,7 +15,7 @@ import MVMCore
//--------------------------------------------------
public static var identifier: String = "dashLine"
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
public var backgroundColor: Color?
public var accessibilityIdentifier: String?

View File

@ -13,7 +13,7 @@
//--------------------------------------------------
open class var identifier: String { "image" }
public var id: String = { return UUID().uuidString }()
@DecodableDefault.UUID public var id: String
public var backgroundColor: Color?
public var moleculeName: String = ImageViewModel.identifier

View File

@ -15,7 +15,7 @@ import UIKit
public static var identifier: String = "leftRightLabelView"
public var moleculeName: String = LeftRightLabelModel.identifier
public var id: String = { return UUID().uuidString }()
@DecodableDefault.UUID public var id: String
public var backgroundColor: Color?
public var leftText: LabelModel

View File

@ -53,7 +53,7 @@ import VDSColorTokens
//--------------------------------------------------
public static var identifier: String = "line"
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
public var type: Style = .secondary
public var frequency: Frequency? = .allExceptTop

View File

@ -14,7 +14,7 @@ open class LoadingSpinnerModel: MoleculeModelProtocol {
// MARK: - Properties
//--------------------------------------------------
public static var identifier: String = "loadingSpinner"
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
public var backgroundColor: Color?
public var strokeColor = Color(uiColor: .mvmBlack)

View File

@ -21,7 +21,7 @@ import Foundation
@objcMembers public class MultiProgressBarModel: MoleculeModelProtocol {
public static var identifier: String = "multiProgressBar"
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
public var progressList: [SingleProgressBarModel]
public var backgroundColor: Color?

View File

@ -10,7 +10,7 @@ import Foundation
@objcMembers public class ProgressBarModel: MoleculeModelProtocol {
public static var identifier: String = "progressBar"
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
@Percent public var percent: CGFloat
public var color: Color = Color(uiColor: .mfCerulean())

View File

@ -13,7 +13,7 @@ open class StarModel: MoleculeModelProtocol {
// MARK: - Properties
//--------------------------------------------------
public static var identifier: String = "star"
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
public var backgroundColor: Color?
@Percent public var percent: CGFloat = 0

View File

@ -13,7 +13,7 @@ import MVMCore
// MARK: - Properties
//--------------------------------------------------
public static var identifier: String = "stars"
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
public var backgroundColor: Color?
public var starBackgroundColor: Color?
@ -52,6 +52,7 @@ import MVMCore
required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
id = try typeContainer.decodeIfPresent(String.self, forKey: .id) ?? UUID().uuidString
stars = try typeContainer.decode([StarModel].self, forKey: .stars)
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
starBackgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .starBackgroundColor)
@ -67,6 +68,7 @@ import MVMCore
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(id, forKey: .id)
try container.encode(moleculeName, forKey: .moleculeName)
try container.encode(stars, forKey: .stars)
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)

View File

@ -15,7 +15,7 @@ open class TileletModel: MoleculeModelProtocol {
// MARK: - Properties
//--------------------------------------------------
public static var identifier: String = "tilelet"
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
public var backgroundColor: Color?
public var color: TileContainer.BackgroundColor
public var padding: TileContainer.Padding
@ -31,6 +31,7 @@ open class TileletModel: MoleculeModelProtocol {
public var action: ActionModelProtocol?
private enum CodingKeys: String, CodingKey {
case id
case moleculeName
case backgroundColor
case color
@ -48,6 +49,7 @@ open class TileletModel: MoleculeModelProtocol {
}
required public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.id = try container.decodeIfPresent(String.self, forKey: .id) ?? UUID().uuidString
self.backgroundColor = try container.decodeIfPresent(Color.self, forKey: .backgroundColor)
self.color = try container.decodeIfPresent(TileContainer.BackgroundColor.self, forKey: .color) ?? TileContainer.BackgroundColor.black
self.padding = try container.decodeIfPresent(TileContainer.Padding.self, forKey: .padding) ?? TileContainer.Padding.padding4X
@ -87,6 +89,7 @@ open class TileletModel: MoleculeModelProtocol {
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(id, forKey: .id)
try container.encode(moleculeName, forKey: .moleculeName)
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
try container.encodeIfPresent(color, forKey: .color)

View File

@ -10,7 +10,7 @@ import Foundation
open class VideoModel: MoleculeModelProtocol, PageBehaviorProtocolRequirer {
public static var identifier = "video"
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
public var backgroundColor: Color?
public var video: String
public var showControls = false
@ -59,6 +59,7 @@ open class VideoModel: MoleculeModelProtocol, PageBehaviorProtocolRequirer {
required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
id = try typeContainer.decodeIfPresent(String.self, forKey: .id) ?? UUID().uuidString
video = try typeContainer.decode(String.self, forKey:.video)
if let showControls = try typeContainer.decodeIfPresent(Bool.self, forKey: .showControls) {
self.showControls = showControls
@ -74,6 +75,7 @@ open class VideoModel: MoleculeModelProtocol, PageBehaviorProtocolRequirer {
open func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(id, forKey: .id)
try container.encode(moleculeName, forKey: .moleculeName)
try container.encode(video, forKey: .video)
try container.encode(showControls, forKey: .showControls)

View File

@ -12,7 +12,7 @@ import MVMCore
@objcMembers public class WebViewModel: MoleculeModelProtocol {
public static var identifier: String = "webview"
public var moleculeName: String = WebViewModel.identifier
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
public var backgroundColor: Color?
public var url: URL?

View File

@ -19,7 +19,7 @@ public enum GraphStyle: String, Codable {
public class WheelModel: MoleculeModelProtocol {
public static var identifier: String = "wheel"
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
public var style: GraphStyle = .unlimited {
didSet {

View File

@ -13,7 +13,7 @@ public class LockUpsPlanNamesModel: MoleculeModelProtocol {
// MARK: - Properties
//--------------------------------------------------
public static var identifier: String = "planNamesLockup"
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
public var backgroundColor: Color?
public var headline: LabelModel

View File

@ -14,7 +14,7 @@ public class LockupsPlanSMLXLModel: MoleculeModelProtocol {
//--------------------------------------------------
public static var identifier: String = "planLockup"
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
public var backgroundColor: Color?
public var planLabel : LabelModel

View File

@ -16,7 +16,7 @@ public class TitleLockupModel: MoleculeModelProtocol, ParentMoleculeModelProtoco
public static var identifier: String = "titleLockup"
public var moleculeName: String = TitleLockupModel.identifier
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
public var eyebrow: LabelModel?
public var title: LabelModel

View File

@ -16,7 +16,7 @@ import Foundation
public static var identifier: String = "doughnutChartItem"
public var moleculeName: String = DoughnutChartItemModel.identifier
public var id: String = { return UUID().uuidString }()
@DecodableDefault.UUID public var id: String
public var backgroundColor: Color?
public var label: LabelModel

View File

@ -16,7 +16,7 @@ import Foundation
public static var identifier: String = "doughnutChart"
public var moleculeName: String = DoughnutChartModel.identifier
public var id: String = { return UUID().uuidString }()
@DecodableDefault.UUID public var id: String
public var backgroundColor: Color?
public var title: LabelModel?

View File

@ -15,7 +15,7 @@ public class ImageHeadlineBodyModel: MoleculeModelProtocol {
public static var identifier: String = "imageHeadlineBody"
public var moleculeName: String = ImageHeadlineBodyModel.identifier
public var id: String = { return UUID().uuidString }()
@DecodableDefault.UUID public var id: String
public var backgroundColor: Color?
public var image: ImageViewModel

View File

@ -15,7 +15,7 @@ import MVMCore
//--------------------------------------------------
public static var identifier: String = "radioButtonLabel"
public var id: String = { return UUID().uuidString }()
@DecodableDefault.UUID public var id: String
public var backgroundColor: Color?
public var moleculeName: String = RadioButtonLabelModel.identifier

View File

@ -11,7 +11,7 @@ import VDSColorTokens
open class TabBarModel: MoleculeModelProtocol {
public static var identifier: String = "tabBar"
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
open var tabs: [TabBarItemModel]

View File

@ -11,7 +11,7 @@ import VDSColorTokens
open class TabsModel: MoleculeModelProtocol {
public static var identifier: String = "tabs"
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
open var tabs: [TabItemModel]

View File

@ -15,7 +15,7 @@ public class TwoButtonViewModel: ParentMoleculeModelProtocol {
//--------------------------------------------------
public static var identifier: String = "twoButtonView"
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
public var backgroundColor: Color?
public var primaryButton: ButtonModel?
public var secondaryButton: ButtonModel?
@ -29,6 +29,7 @@ public class TwoButtonViewModel: ParentMoleculeModelProtocol {
//--------------------------------------------------
private enum CodingKeys: String, CodingKey {
case id
case moleculeName
case backgroundColor
case primaryButton
@ -50,6 +51,7 @@ public class TwoButtonViewModel: ParentMoleculeModelProtocol {
required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
id = try typeContainer.decodeIfPresent(String.self, forKey: .id) ?? UUID().uuidString
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
//set context value for 'primary' style to be set for the primaryButton in case the
@ -67,6 +69,7 @@ public class TwoButtonViewModel: ParentMoleculeModelProtocol {
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(id, forKey: .id)
try container.encode(moleculeName, forKey: .moleculeName)
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
try container.encodeIfPresent(primaryButton, forKey: .primaryButton)

View File

@ -10,7 +10,7 @@ import Foundation
public class TwoLinkViewModel: MoleculeModelProtocol {
public static var identifier: String = "twoLinkView"
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
public var backgroundColor: Color?
public var rightLink: LinkModel?

View File

@ -11,7 +11,7 @@ import Foundation
public class ActionDetailWithImageModel: MoleculeModelProtocol {
public static var identifier: String = "actionDetailWithImage"
public var moleculeName: String = ActionDetailWithImageModel.identifier
public var id: String = { return UUID().uuidString }()
@DecodableDefault.UUID public var id: String
public var backgroundColor: Color?
public var headlineBodyButton: HeadlineBodyButtonModel

View File

@ -11,7 +11,7 @@ import MVMCore
public class CornerLabelsModel: ParentMoleculeModelProtocol {
public static var identifier: String = "cornerLabels"
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
public var backgroundColor: Color?
public var topLeftLabel: LabelModel?
public var topRightLabel: LabelModel?
@ -27,6 +27,7 @@ public class CornerLabelsModel: ParentMoleculeModelProtocol {
}
private enum CodingKeys: String, CodingKey {
case id
case backgroundColor
case topLeftLabel
case topRightLabel
@ -38,6 +39,7 @@ public class CornerLabelsModel: ParentMoleculeModelProtocol {
required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
id = try typeContainer.decodeIfPresent(String.self, forKey: .id) ?? UUID().uuidString
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
molecule = try typeContainer.decodeModelIfPresent(codingKey: .molecule)
topLeftLabel = try typeContainer.decodeMoleculeIfPresent(codingKey: .topLeftLabel)
@ -48,6 +50,7 @@ public class CornerLabelsModel: ParentMoleculeModelProtocol {
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(id, forKey: .id)
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
try container.encodeModelIfPresent(molecule, forKey: .molecule)
try container.encodeModelIfPresent(topLeftLabel, forKey: .topLeftLabel)

View File

@ -10,7 +10,7 @@ import Foundation
public class HeadlineBodyLinkToggleModel: MoleculeModelProtocol {
public static var identifier: String = "headlineBodyLinkToggle"
public var moleculeName: String = HeadlineBodyLinkToggleModel.identifier
public var id: String = { return UUID().uuidString }()
@DecodableDefault.UUID public var id: String
public var backgroundColor: Color?
public var headlineBodyLink: HeadlineBodyLinkModel
public var toggle: ToggleModel

View File

@ -12,7 +12,7 @@ import Foundation
open class HeadlineBodyToggleModel: MoleculeModelProtocol {
public static var identifier: String = "headlineBodyToggle"
public var moleculeName: String = HeadlineBodyToggleModel.identifier
public var id: String = { return UUID().uuidString }()
@DecodableDefault.UUID public var id: String
open var backgroundColor: Color?
open var headlineBody: HeadlineBodyModel
open var toggle: ToggleModel

View File

@ -12,7 +12,7 @@ import MVMCore
public class LabelToggleModel: MoleculeModelProtocol {
public static var identifier: String = "labelToggle"
public var moleculeName: String = LabelToggleModel.identifier
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
public var backgroundColor: Color?
public var label: LabelModel

View File

@ -14,7 +14,7 @@ public class NavigationImageButtonModel: NavigationButtonModelProtocol, Molecule
//--------------------------------------------------
public static var identifier: String = "navigationImageButton"
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
public var backgroundColor: Color?
public var accessibilityIdentifier: String?
@ -52,6 +52,7 @@ public class NavigationImageButtonModel: NavigationButtonModelProtocol, Molecule
required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
id = try typeContainer.decodeIfPresent(String.self, forKey: .id) ?? UUID().uuidString
accessibilityIdentifier = try typeContainer.decodeIfPresent(String.self, forKey: .accessibilityIdentifier)
image = try typeContainer.decode(String.self, forKey: .image)
action = try typeContainer.decodeModel(codingKey: .action)

View File

@ -13,7 +13,7 @@ open class NavigationLabelButtonModel: NavigationButtonModelProtocol, MoleculeMo
//--------------------------------------------------
open class var identifier: String { "navigationLabelButton" }
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
open var backgroundColor: Color?
open var accessibilityIdentifier: String?

View File

@ -19,7 +19,7 @@ open class NavigationItemModel: NavigationItemModelProtocol, MoleculeModelProtoc
//--------------------------------------------------
open class var identifier: String { "navigationBar" }
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
private let defaultHidesSystemBackButton = true

View File

@ -11,7 +11,7 @@ import Foundation
open class ModuleMoleculeModel: MoleculeModelProtocol {
public static var identifier: String = "moduleMolecule"
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
public var backgroundColor: Color?
public var moduleName: String

View File

@ -12,7 +12,7 @@ import MVMCore
public class NotificationXButtonModel: ButtonModelProtocol, MoleculeModelProtocol {
public static var identifier: String = "notificationXButton"
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
public var backgroundColor: Color?
public var color: Color?

View File

@ -13,7 +13,7 @@ public class EyebrowHeadlineBodyLinkModel: MoleculeModelProtocol, ParentMolecule
//--------------------------------------------------
public static var identifier: String = "eyebrowHeadlineBodyLink"
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
public var moleculeName: String = EyebrowHeadlineBodyLinkModel.identifier
public var backgroundColor: Color?
public var eyebrow: LabelModel?

View File

@ -14,7 +14,7 @@ public class HeadlineBodyButtonModel: MoleculeModelProtocol {
public static var identifier: String = "headlineBodyButton"
public var moleculeName: String = HeadlineBodyButtonModel.identifier
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
public var backgroundColor: Color?

View File

@ -16,7 +16,7 @@ public class HeadlineBodyLinkModel: MoleculeModelProtocol {
public static var identifier: String = "headlineBodyLink"
public var moleculeName: String = HeadlineBodyLinkModel.identifier
public var id: String = { return UUID().uuidString }()
@DecodableDefault.UUID public var id: String
public var headlineBody: HeadlineBodyModel
public var link: LinkModel

View File

@ -14,7 +14,7 @@
public static var identifier: String = "headlineBody"
public var moleculeName: String = HeadlineBodyModel.identifier
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
public var headline: LabelModel?
public var body: LabelModel?
public var style: Style?

View File

@ -13,7 +13,7 @@ public class StringAndMoleculeModel: MoleculeModelProtocol {
//--------------------------------------------------
public static var identifier: String = "stringAndMoleculeModel"
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
public var backgroundColor: Color?
public var string: String

View File

@ -16,7 +16,7 @@ public class ThreeHeadlineBodyLinkModel: MoleculeModelProtocol {
public static var identifier: String = "threeHeadlineBodyLink"
public var moleculeName: String = ThreeHeadlineBodyLinkModel.identifier
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
public var backgroundColor: Color?

View File

@ -19,7 +19,7 @@ import UIKit
return "carousel"
}
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
public var backgroundColor: Color?
public var molecules: [MoleculeModelProtocol & CarouselItemModelProtocol]

View File

@ -25,6 +25,15 @@
return molecules
}
public func replaceChildMolecule(with replacementMolecule: MoleculeModelProtocol) -> Bool {
guard let replacementMolecule = replacementMolecule as? StackItemModelProtocol & MoleculeModelProtocol else { return false }
guard let matchingIndex = molecules.firstIndex(where: { molecule in
molecule.id == replacementMolecule.id
}) else { return false }
molecules[matchingIndex] = replacementMolecule
return true
}
//--------------------------------------------------
// MARK: - Initializer
//--------------------------------------------------

View File

@ -68,4 +68,12 @@ public extension ParentMoleculeModelProtocol {
}
return false
}
func replaceChildMolecule<P: ParentMoleculeModelProtocol, T: MoleculeModelProtocol>(on target: P, keyPath: ReferenceWritableKeyPath<P, T>, replacementMolecule: MoleculeModelProtocol) -> Bool {
if target[keyPath: keyPath].id == replacementMolecule.id, let newHeadline = replacementMolecule as? T {
target[keyPath: keyPath] = newHeadline
return true
}
return false
}
}

View File

@ -13,7 +13,7 @@ open class ContainerModel: ContainerModelProtocol, Codable {
// MARK: - Properties
//--------------------------------------------------
public var id: String = { return UUID().uuidString }()
public var id: String = UUID().uuidString
public var horizontalAlignment: UIStackView.Alignment?
public var useHorizontalMargins: Bool?