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)
}
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 }
return actions.areEqual(to: model.actions)
return actions.isEqual(to: model.actions)
&& concurrent == model.concurrent
&& extraParameters == model.extraParameters
&& analyticsData == model.analyticsData

View File

@ -116,7 +116,7 @@ public struct ActionOpenPageModel: ActionModelProtocol, ActionOpenPageProtocol,
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 }
return pageType == model.pageType
&& baseURL == model.baseURL

View File

@ -36,7 +36,7 @@ public class ClientParameterModel: Equatable, Codable {
}
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
}
}

View File

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