From cb659b63e9898fb01cf4f183edf94a87f0fe683b Mon Sep 17 00:00:00 2001 From: "Hedden, Kyle Matthew" Date: Wed, 22 May 2024 18:00:59 -0400 Subject: [PATCH] Digital PCT265 story PCT-135: ContainerModel ModelComparisonProtocol conformance. --- .../Molecules/Items/ListItemModel.swift | 6 +++--- .../Molecules/Items/StackItemModel.swift | 2 +- .../MoleculeContainerModel.swift | 8 ++++---- MVMCoreUI/Atomic/Organisms/StackModel.swift | 2 +- .../Containers/Views/ContainerModel.swift | 19 ++++++++++++++++--- 5 files changed, 25 insertions(+), 12 deletions(-) diff --git a/MVMCoreUI/Atomic/Molecules/Items/ListItemModel.swift b/MVMCoreUI/Atomic/Molecules/Items/ListItemModel.swift index 0128c41e..3ac37b49 100644 --- a/MVMCoreUI/Atomic/Molecules/Items/ListItemModel.swift +++ b/MVMCoreUI/Atomic/Molecules/Items/ListItemModel.swift @@ -8,7 +8,7 @@ // A base class that has common list item boilerplate model stuffs. import MVMCore -@objcMembers open class ListItemModel: ContainerModel, ListItemModelProtocol, ModelComparisonProtocol, MoleculeModelComparisonProtocol { +@objcMembers open class ListItemModel: ContainerModel, ListItemModelProtocol, MoleculeModelComparisonProtocol { //-------------------------------------------------- // MARK: - Properties @@ -131,8 +131,8 @@ import MVMCore try container.encodeIfPresent(accessibilityText, forKey: .accessibilityText) } - public func isEqual(to model: any ModelComparisonProtocol) -> Bool { - guard let model = model as? Self else { return false } + public override func isEqual(to model: any ModelComparisonProtocol) -> Bool { + guard super.isEqual(to: model), let model = model as? Self else { return false } return backgroundColor == model.backgroundColor && hideArrow == model.hideArrow && style == model.style diff --git a/MVMCoreUI/Atomic/Molecules/Items/StackItemModel.swift b/MVMCoreUI/Atomic/Molecules/Items/StackItemModel.swift index 85c4cf86..edb31463 100644 --- a/MVMCoreUI/Atomic/Molecules/Items/StackItemModel.swift +++ b/MVMCoreUI/Atomic/Molecules/Items/StackItemModel.swift @@ -37,7 +37,7 @@ fatalError("init(from:) has not been implemented") } - public func isEqual(to model: any ModelComparisonProtocol) -> Bool { + public override func isEqual(to model: any ModelComparisonProtocol) -> Bool { guard let model = model as? Self else { return false } return backgroundColor == model.backgroundColor && spacing == model.spacing diff --git a/MVMCoreUI/Atomic/Molecules/OtherContainers/MoleculeContainerModel.swift b/MVMCoreUI/Atomic/Molecules/OtherContainers/MoleculeContainerModel.swift index a97f4af6..140435ad 100644 --- a/MVMCoreUI/Atomic/Molecules/OtherContainers/MoleculeContainerModel.swift +++ b/MVMCoreUI/Atomic/Molecules/OtherContainers/MoleculeContainerModel.swift @@ -62,13 +62,13 @@ open class MoleculeContainerModel: ContainerModel, MoleculeContainerModelProtoco try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) } - public func isEqual(to model: any ModelComparisonProtocol) -> Bool { - guard let model = model as? Self else { return false } + public override func isEqual(to model: any ModelComparisonProtocol) -> Bool { + guard super.isEqual(to: model), let model = model as? Self else { return false } return backgroundColor == model.backgroundColor } + // Declare for overrides. public func isVisuallyEquivalent(to model: any MoleculeModelComparisonProtocol) -> Bool { - guard let model = model as? Self else { return false } - return backgroundColor == model.backgroundColor + return isEqual(to: model) } } diff --git a/MVMCoreUI/Atomic/Organisms/StackModel.swift b/MVMCoreUI/Atomic/Organisms/StackModel.swift index 3b687c18..bffe460b 100644 --- a/MVMCoreUI/Atomic/Organisms/StackModel.swift +++ b/MVMCoreUI/Atomic/Organisms/StackModel.swift @@ -79,7 +79,7 @@ try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) } - public func isEqual(to model: any ModelComparisonProtocol) -> Bool { + public override func isEqual(to model: any ModelComparisonProtocol) -> Bool { guard let model = model as? Self else { return false } return backgroundColor == model.backgroundColor && axis == model.axis diff --git a/MVMCoreUI/Containers/Views/ContainerModel.swift b/MVMCoreUI/Containers/Views/ContainerModel.swift index 81b7c769..b9549bf8 100644 --- a/MVMCoreUI/Containers/Views/ContainerModel.swift +++ b/MVMCoreUI/Containers/Views/ContainerModel.swift @@ -7,7 +7,7 @@ // -open class ContainerModel: ContainerModelProtocol, Codable { +open class ContainerModel: ContainerModelProtocol, Codable, ModelComparisonProtocol { //-------------------------------------------------- // MARK: - Properties @@ -75,7 +75,7 @@ open class ContainerModel: ContainerModelProtocol, Codable { //-------------------------------------------------- // MARK: - Codec //-------------------------------------------------- - + required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) @@ -99,7 +99,7 @@ open class ContainerModel: ContainerModelProtocol, Codable { cornerRadius = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .cornerRadius) setDefaults() } - + open func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(id, forKey: .id) @@ -113,4 +113,17 @@ open class ContainerModel: ContainerModelProtocol, Codable { try container.encodeIfPresent(bottomPadding, forKey: .bottomPadding) try container.encodeIfPresent(cornerRadius, forKey: .cornerRadius) } + + public func isEqual(to model: any ModelComparisonProtocol) -> Bool { + guard let model = model as? Self else { return false } + return horizontalAlignment == model.horizontalAlignment + && useHorizontalMargins == model.useHorizontalMargins + && leftPadding == model.leftPadding + && rightPadding == model.rightPadding + && verticalAlignment == model.verticalAlignment + && useVerticalMargins == model.useVerticalMargins + && topPadding == model.topPadding + && bottomPadding == model.bottomPadding + && cornerRadius == model.cornerRadius + } }