diff --git a/MVMCoreUI/Atomic/Templates/MoleculeListTemplate.swift b/MVMCoreUI/Atomic/Templates/MoleculeListTemplate.swift index a1c2d3b6..dc86aa4d 100644 --- a/MVMCoreUI/Atomic/Templates/MoleculeListTemplate.swift +++ b/MVMCoreUI/Atomic/Templates/MoleculeListTemplate.swift @@ -222,6 +222,33 @@ 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() { + return true + } else if let parent = moleculeInfo.molecule as? ParentMoleculeModelProtocol { + // Get all molecules of the same type for faster check. + let molecules: [MoleculeModelProtocol] = parent.reduceDepthFirstTraverse(options: .childFirst, depth: 0, initialResult: []) { (accumulator, currentMolecule, depth) in + if currentMolecule.moleculeName == molecule.moleculeName { + return accumulator + [currentMolecule] + } + return accumulator + } + for molecule in molecules { + if json == molecule.toJSON() { + return true + } + } + } + return false + }) else { return } + let indexPath = IndexPath(row: index, section: 0) + tableView.reloadRows(at: [indexPath], with: .none) + } + open override func removeMolecules(_ molecules: [ListItemModelProtocol & MoleculeModelProtocol], animation: UITableView.RowAnimation) { var indexPaths: [IndexPath] = [] //TODO: check for molecule protocol equality