Digital PCT265 story PCT-135: Extract running the behavior transformations for method clarity.
This commit is contained in:
parent
042cc20859
commit
d79ec8dc6a
@ -251,26 +251,7 @@ import MVMCore
|
|||||||
// Run through behavior tranformations.
|
// Run through behavior tranformations.
|
||||||
var behaviorUpdatedModels = [MoleculeModelProtocol]()
|
var behaviorUpdatedModels = [MoleculeModelProtocol]()
|
||||||
if var newTemplateModel = newPageModel as? TemplateModelProtocol {
|
if var newTemplateModel = newPageModel as? TemplateModelProtocol {
|
||||||
executeBehaviors { (behavior: PageMoleculeTransformationBehavior) in
|
behaviorUpdatedModels = runBehaviorTransformations(on: &newTemplateModel)
|
||||||
var changes = [any MoleculeModelProtocol]()
|
|
||||||
if let updatedMolecules = behavior.onPageNew(rootMolecules: newTemplateModel.rootMolecules, delegateObjectIVar, changes: &changes) {
|
|
||||||
updatedMolecules.forEach { molecule in
|
|
||||||
// Replace again in case there is a template level child.
|
|
||||||
if let replaced = try? newTemplateModel.replaceChildMolecule(with: molecule) {
|
|
||||||
// Only recognize the molecules that actually changed.
|
|
||||||
if changes.count > 0 {
|
|
||||||
debugLog("\(behavior) updated \(changes) in template model.")
|
|
||||||
changes = changes.filter({ model in
|
|
||||||
!behaviorUpdatedModels.contains { $0.id == model.id }
|
|
||||||
})
|
|
||||||
behaviorUpdatedModels.append(contentsOf: changes)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
debugLog("Failed to replace \(molecule) in the template model.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply the form validator to the controller.
|
// Apply the form validator to the controller.
|
||||||
@ -331,6 +312,31 @@ import MVMCore
|
|||||||
view.setNeedsLayout()
|
view.setNeedsLayout()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func runBehaviorTransformations(on newTemplateModel: inout any TemplateModelProtocol) -> [any MoleculeModelProtocol] {
|
||||||
|
var behaviorUpdatedModels = [MoleculeModelProtocol]()
|
||||||
|
executeBehaviors { (behavior: PageMoleculeTransformationBehavior) in
|
||||||
|
var changes = [any MoleculeModelProtocol]()
|
||||||
|
if let updatedMolecules = behavior.onPageNew(rootMolecules: newTemplateModel.rootMolecules, delegateObjectIVar, changes: &changes) {
|
||||||
|
updatedMolecules.forEach { molecule in
|
||||||
|
// Replace again in case there is a template level child.
|
||||||
|
if let replaced = try? newTemplateModel.replaceChildMolecule(with: molecule) {
|
||||||
|
// Only recognize the molecules that actually changed.
|
||||||
|
if changes.count > 0 {
|
||||||
|
debugLog("\(behavior) updated \(changes) in template model.")
|
||||||
|
changes = changes.filter({ model in
|
||||||
|
!behaviorUpdatedModels.contains { $0.id == model.id }
|
||||||
|
})
|
||||||
|
behaviorUpdatedModels.append(contentsOf: changes)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
debugLog("Failed to replace \(molecule) in the template model.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return behaviorUpdatedModels
|
||||||
|
}
|
||||||
|
|
||||||
public func generateMoleculeView(from model: MoleculeModelProtocol) -> MoleculeViewProtocol? {
|
public func generateMoleculeView(from model: MoleculeModelProtocol) -> MoleculeViewProtocol? {
|
||||||
executeBehaviors { (behavior: PageMoleculeTransformationBehavior) in
|
executeBehaviors { (behavior: PageMoleculeTransformationBehavior) in
|
||||||
behavior.willSetupMolecule(with: model, updating: nil)
|
behavior.willSetupMolecule(with: model, updating: nil)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user