Digital PCT265 story ONEAPP-7249 - isVisuallyEquivalent build out to work with stabilizing carousel refreshes.

This commit is contained in:
Hedden, Kyle Matthew 2024-05-08 20:34:21 -04:00
parent 62a5799312
commit 20d4d323e0
4 changed files with 24 additions and 23 deletions

View File

@ -65,9 +65,9 @@ public struct ActionActionsModel: ActionModelProtocol {
try container.encodeIfPresent(analyticsData, forKey: .analyticsData) try container.encodeIfPresent(analyticsData, forKey: .analyticsData)
} }
public func isEqual(to model: any ModelProtocol) -> Bool { public func isEqual(to model: any ModelComparisonProtocol) -> Bool {
guard let model = model as? Self else { return false } guard let model = model as? Self else { return false }
return actions.areEqual(to: model.actions) return actions.isEqual(to: model.actions)
&& concurrent == model.concurrent && concurrent == model.concurrent
&& extraParameters == model.extraParameters && extraParameters == model.extraParameters
&& analyticsData == model.analyticsData && analyticsData == model.analyticsData

View File

@ -116,7 +116,7 @@ public struct ActionOpenPageModel: ActionModelProtocol, ActionOpenPageProtocol,
try container.encodeIfPresent(fallbackResponse, forKey: .fallbackResponse) try container.encodeIfPresent(fallbackResponse, forKey: .fallbackResponse)
} }
public func isEqual(to model: any ModelProtocol) -> Bool { public func isEqual(to model: any ModelComparisonProtocol) -> Bool {
guard let model = model as? Self else { return false } guard let model = model as? Self else { return false }
return pageType == model.pageType return pageType == model.pageType
&& baseURL == model.baseURL && baseURL == model.baseURL

View File

@ -36,7 +36,7 @@ public class ClientParameterModel: Equatable, Codable {
} }
public static func == (lhs: ClientParameterModel, rhs: ClientParameterModel) -> Bool { public static func == (lhs: ClientParameterModel, rhs: ClientParameterModel) -> Bool {
return lhs.list.areEqual(to: rhs.list) return lhs.list.isEqual(to: rhs.list)
&& lhs.timeout == rhs.timeout && lhs.timeout == rhs.timeout
} }
} }

View File

@ -8,7 +8,7 @@
import Foundation import Foundation
public protocol ModelProtocol: Codable { public protocol ModelProtocol: ModelComparisonProtocol, Codable {
/// The key name of the molecule /// The key name of the molecule
static var identifier: String { get } static var identifier: String { get }
@ -30,9 +30,6 @@ public protocol ModelProtocol: Codable {
/// Convenience function to encode model using an unkeyed container. /// Convenience function to encode model using an unkeyed container.
func encode(unkeyedContainer: inout UnkeyedEncodingContainer) throws func encode(unkeyedContainer: inout UnkeyedEncodingContainer) throws
/// Deep checks if the curent model is equal to another model. Defaults to false unless implemented otherwise.
func isEqual(to model: ModelProtocol) -> Bool
} }
extension ModelProtocol { extension ModelProtocol {
@ -52,17 +49,23 @@ extension ModelProtocol {
public func encode(unkeyedContainer: inout UnkeyedEncodingContainer) throws { public func encode(unkeyedContainer: inout UnkeyedEncodingContainer) throws {
try unkeyedContainer.encode(self) try unkeyedContainer.encode(self)
} }
}
public func isEqual(to model: ModelProtocol) -> Bool { public protocol ModelComparisonProtocol {
/// Deep checks if the curent model is equal to another model. Defaults to false unless implemented otherwise.
func isEqual(to model: ModelComparisonProtocol) -> Bool
}
extension ModelComparisonProtocol {
public func isEqual(to model: ModelComparisonProtocol) -> Bool {
return false return false
} }
} }
public extension Optional { public extension Optional {
/// Checks if the curent model is equal to another model. /// Checks if the curent model is equal to another model.
func isEqual(to model: ModelProtocol?) -> Bool { func isEqual(to model: ModelComparisonProtocol?) -> Bool {
guard let self = self as? ModelProtocol else { guard let self = self as? ModelComparisonProtocol else {
return model == nil return model == nil
} }
guard let model = model else { guard let model = model else {
@ -72,11 +75,10 @@ public extension Optional {
} }
} }
public extension Collection {
public extension Array /*where Element == ModelProtocol*/ { /// Checks if all the models in the given collection match another given collection.
/// Checks if all the models in the given array match another given array of models. func isEqual(to models: [ModelComparisonProtocol]) -> Bool {
func areEqual(to models: [ModelProtocol]) -> Bool { guard count == models.count, let self = self as? [ModelComparisonProtocol] else { return false }
guard count == models.count, let self = self as? [ModelProtocol] else { return false }
return models.indices.allSatisfy { index in return models.indices.allSatisfy { index in
self[index].isEqual(to: models[index]) self[index].isEqual(to: models[index])
} }
@ -84,15 +86,14 @@ public extension Array /*where Element == ModelProtocol*/ {
} }
public extension Optional where Wrapped: Collection { public extension Optional where Wrapped: Collection {
/// Checks if the curent model is equal to another model.
func areEqual(to models: [ModelProtocol]?) -> Bool { func isEqual(to models: [ModelComparisonProtocol]?) -> Bool {
guard let self = self as? [ModelProtocol] else { guard let self = self as? [ModelComparisonProtocol] else {
return models == nil return models == nil
} }
guard let models = models else { guard let models = models else {
return false return false
} }
return self.areEqual(to: models) return self.isEqual(to: models)
} }
} }