Digital PCT265 story PCT-135: ContainerModel ModelComparisonProtocol conformance.
This commit is contained in:
parent
9ff5b58eb5
commit
cb659b63e9
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user