diff --git a/MVMCoreUI/Atomic/Protocols/MoleculeDelegateProtocol.swift b/MVMCoreUI/Atomic/Protocols/MoleculeDelegateProtocol.swift index e7a4bdef..e8cae35b 100644 --- a/MVMCoreUI/Atomic/Protocols/MoleculeDelegateProtocol.swift +++ b/MVMCoreUI/Atomic/Protocols/MoleculeDelegateProtocol.swift @@ -22,7 +22,8 @@ public protocol MoleculeDelegateProtocol: AnyObject { /// Notifies the delegate that the molecule layout update. Should be called when the layout may change due to an async method. Mainly used for list or collections. func moleculeLayoutUpdated(_ molecule: MoleculeViewProtocol) //optional - func replaceMoleculeData(_ moleculeModels: [MoleculeModelProtocol]) + /// Attempts to replace the molecules provided. Returns the ones that replaced successfully. + func replaceMoleculeData(_ moleculeModels: [MoleculeModelProtocol], completionHandler: (([MoleculeModelProtocol])->Void)?) } extension MoleculeDelegateProtocol { diff --git a/MVMCoreUI/BaseControllers/ViewController.swift b/MVMCoreUI/BaseControllers/ViewController.swift index 5997847d..452d2962 100644 --- a/MVMCoreUI/BaseControllers/ViewController.swift +++ b/MVMCoreUI/BaseControllers/ViewController.swift @@ -511,7 +511,7 @@ import MVMCore // Needed otherwise when subclassed, the extension gets called. open func moleculeLayoutUpdated(_ molecule: MoleculeViewProtocol) { } - public func replaceMoleculeData(_ moleculeModels: [MoleculeModelProtocol]) { + public func replaceMoleculeData(_ moleculeModels: [MoleculeModelProtocol], completionHandler: (([MoleculeModelProtocol])->Void)? = nil) { pageUpdateQueue.addOperation { let replacedModels:[MoleculeModelProtocol] = moleculeModels.compactMap { model in guard self.attemptToReplace(with: model) else { @@ -524,6 +524,7 @@ import MVMCore self.updateUI(for: replacedModels) } } + completionHandler?(replacedModels) } } diff --git a/MVMCoreUI/Behaviors/ReplaceableMoleculeBehaviorModel.swift b/MVMCoreUI/Behaviors/ReplaceableMoleculeBehaviorModel.swift index 2e38017c..e52ee464 100644 --- a/MVMCoreUI/Behaviors/ReplaceableMoleculeBehaviorModel.swift +++ b/MVMCoreUI/Behaviors/ReplaceableMoleculeBehaviorModel.swift @@ -62,7 +62,7 @@ public class ReplaceableMoleculeBehavior: PageMoleculeTransformationBehavior { } } if moleculeModels.count > 0 { - delegateObject?.moleculeDelegate?.replaceMoleculeData(moleculeModels) + delegateObject?.moleculeDelegate?.replaceMoleculeData(moleculeModels, completionHandler: nil) } } @@ -95,8 +95,11 @@ public class ReplaceableMoleculeBehavior: PageMoleculeTransformationBehavior { return nil } } - if modules.count > 0 { - delegateObject?.moleculeDelegate?.replaceMoleculeData(modules) + guard modules.count > 0 else { return } + delegateObject?.moleculeDelegate?.replaceMoleculeData(modules) { replacedModels in + let modules = replacedModels.compactMap { modulesLoaded.dictionaryForKey($0.id) } + guard let viewController = self.delegateObject?.moleculeDelegate as? MVMCoreViewControllerProtocol else { return } + modules.forEach { MVMCoreUILoggingHandler.shared()?.defaultLogPageUpdate(forController: viewController, from: $0) } } } diff --git a/MVMCoreUI/OtherHandlers/MVMCoreUILoggingHandler.swift b/MVMCoreUI/OtherHandlers/MVMCoreUILoggingHandler.swift index e74bc580..74a27f7f 100644 --- a/MVMCoreUI/OtherHandlers/MVMCoreUILoggingHandler.swift +++ b/MVMCoreUI/OtherHandlers/MVMCoreUILoggingHandler.swift @@ -13,4 +13,7 @@ // Action Logging @objc open func defaultLogAction(forController controller: MVMCoreViewControllerProtocol?, actionInformation: [AnyHashable : Any]?, additionalData: [AnyHashable : Any]?) { } + + // Module Update Logging + @objc open func defaultLogPageUpdate(forController controller: MVMCoreViewControllerProtocol, from module: [AnyHashable: Any]) { } }