signature fix. template traversal conformance.

This commit is contained in:
Kyle Matthew Hedden 2021-03-29 16:52:48 -04:00
parent 4a491cbfaa
commit cb2c42793a
3 changed files with 14 additions and 6 deletions

View File

@ -43,9 +43,9 @@ public extension Array where Element == MoleculeModelProtocol {
}
}
func depthFirstTraverse(options: TreeTraversalOptions, depth: Int, callback: (Int, MoleculeModelProtocol)->Void) {
func depthFirstTraverse(options: TreeTraversalOptions, depth: Int, onVisit: (Int, MoleculeModelProtocol)->Void) {
forEach { (molecule) in
molecule.depthFirstTraverse(options: options, depth: depth, onVisit: callback)
molecule.depthFirstTraverse(options: options, depth: depth, onVisit: onVisit)
}
}
}

View File

@ -9,7 +9,7 @@
import Foundation
public protocol TemplateModelProtocol: PageModelProtocol, ModelProtocol {
public protocol TemplateModelProtocol: PageModelProtocol, ModelProtocol, MoleculeTreeTraversalProtocol {
var template: String { get }
var rootMolecules: [MoleculeModelProtocol] { get }
}
@ -27,4 +27,12 @@ public extension TemplateModelProtocol {
static var categoryName: String {
return "\(TemplateModelProtocol.self)"
}
func reduceDepthFirstTraverse<Result>(options: TreeTraversalOptions, depth: Int, initialResult: Result, nextPartialResult: (Result, MoleculeModelProtocol, Int) -> Result) -> Result {
return rootMolecules.reduceDepthFirstTraverse(options: options, depth: depth, initialResult: initialResult, nextPartialResult: nextPartialResult)
}
func depthFirstTraverse(options: TreeTraversalOptions, depth: Int, onVisit: (Int, MoleculeModelProtocol) -> Void) {
return rootMolecules.depthFirstTraverse(options: options, depth: depth, onVisit: onVisit)
}
}

View File

@ -335,12 +335,12 @@ import UIKit
initialLoadFinished = true
initialLoad()
}
print("total molecules in tree: \(model?.rootMolecules.countMolecules() ?? 0)")
print("total molecules in tree: \(model?.countMolecules() ?? 0)")
model?.rootMolecules.printMolecules()
let allVideoMolecules:[BGVideoImageMoleculeModel] = model?.rootMolecules.allMoleculesOfType() ?? []
let allVideoMolecules:[BGVideoImageMoleculeModel] = model?.allMoleculesOfType() ?? []
print("video molecules: \(allVideoMolecules.count)")
handleNewDataAndUpdateUI()