Merge branch 'bugfix/same_json_equatable' into 'develop'
Bugfix/same json equatable See merge request BPHV_MIPS/mvm_core_ui!752
This commit is contained in:
commit
ee574adc8c
@ -8,7 +8,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct ImageHeadlineBodyModel: MoleculeModelProtocol {
|
||||
public class ImageHeadlineBodyModel: MoleculeModelProtocol {
|
||||
//--------------------------------------------------
|
||||
// MARK: - Properties
|
||||
//--------------------------------------------------
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct ActionDetailWithImageModel: MoleculeModelProtocol {
|
||||
public class ActionDetailWithImageModel: MoleculeModelProtocol {
|
||||
public static var identifier: String = "actionDetailWithImage"
|
||||
public var moleculeName: String = ActionDetailWithImageModel.identifier
|
||||
public var backgroundColor: Color?
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
public struct HeadlineBodyLinkToggleModel: MoleculeModelProtocol {
|
||||
public class HeadlineBodyLinkToggleModel: MoleculeModelProtocol {
|
||||
public static var identifier: String = "headlineBodyLinkToggle"
|
||||
public var moleculeName: String = HeadlineBodyLinkToggleModel.identifier
|
||||
public var backgroundColor: Color?
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
import Foundation
|
||||
|
||||
|
||||
public struct HeadlineBodyLinkModel: MoleculeModelProtocol {
|
||||
public class HeadlineBodyLinkModel: MoleculeModelProtocol {
|
||||
//--------------------------------------------------
|
||||
// MARK: - Properties
|
||||
//--------------------------------------------------
|
||||
|
||||
@ -188,10 +188,8 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol
|
||||
|
||||
open func newData(for molecule: MoleculeModelProtocol) {
|
||||
//TODO: expand for header, navigation, etc
|
||||
let json = molecule.toJSON()
|
||||
guard let index = moleculesInfo?.firstIndex(where: { (moleculeInfo) -> Bool in
|
||||
//TODO: check for molecule protocol eqaulity
|
||||
if json == moleculeInfo.molecule.toJSON() {
|
||||
if equal(moleculeA: molecule, moleculeB: moleculeInfo.molecule) {
|
||||
return true
|
||||
} else if let parent = moleculeInfo.molecule as? ParentMoleculeModelProtocol {
|
||||
// Get all molecules of the same type for faster check.
|
||||
@ -201,8 +199,8 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol
|
||||
}
|
||||
return accumulator
|
||||
}
|
||||
for molecule in molecules {
|
||||
if json == molecule.toJSON() {
|
||||
for moleculeB in molecules {
|
||||
if equal(moleculeA: molecule, moleculeB: moleculeB) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@ -283,6 +281,18 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol
|
||||
|
||||
return modules
|
||||
}
|
||||
|
||||
/// Checks if the two molecules are equal
|
||||
private func equal(moleculeA: MoleculeModelProtocol, moleculeB: MoleculeModelProtocol) -> Bool {
|
||||
// TODO: move this to a better approach, maybe a UUID for each model.
|
||||
// Do instance check
|
||||
if let classMoleculeA = moleculeA as? NSObjectProtocol,
|
||||
let classMoleculeB = moleculeB as? NSObjectProtocol {
|
||||
return classMoleculeA === classMoleculeB
|
||||
}
|
||||
// Do json check
|
||||
return moleculeA.toJSON() == moleculeB.toJSON()
|
||||
}
|
||||
}
|
||||
|
||||
extension MoleculeListTemplate: MoleculeListProtocol {
|
||||
@ -320,9 +330,7 @@ extension MoleculeListTemplate: MoleculeListProtocol {
|
||||
|
||||
open func getIndexPath(for molecule: ListItemModelProtocol & MoleculeModelProtocol) -> IndexPath? {
|
||||
guard let index = moleculesInfo?.firstIndex(where: { (moleculeInfo) -> Bool in
|
||||
//TODO: check for molecule protocol eqaulity
|
||||
let json = moleculeInfo.molecule.toJSON()
|
||||
return json == molecule.toJSON()
|
||||
return equal(moleculeA: molecule, moleculeB: moleculeInfo.molecule)
|
||||
}) else { return nil }
|
||||
|
||||
return IndexPath(row: index, section: 0)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user