diff --git a/MVMCoreUI/BaseControllers/ViewController.swift b/MVMCoreUI/BaseControllers/ViewController.swift index ba38ad29..c146afa0 100644 --- a/MVMCoreUI/BaseControllers/ViewController.swift +++ b/MVMCoreUI/BaseControllers/ViewController.swift @@ -65,7 +65,9 @@ import MVMCore (pagesToListenFor()?.count ?? 0 > 0 || modulesToListenFor()?.count ?? 0 > 0) else { return } - observingForResponses = NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: NotificationResponseLoaded), object: nil, queue: pageUpdateQueue, using: responseJSONUpdated(notification:)) + observingForResponses = NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: NotificationResponseLoaded), object: nil, queue: pageUpdateQueue) { [weak self] notification in + self?.responseJSONUpdated(notification: notification) + } } open func stopObservingForResponseJSONUpdates() { diff --git a/MVMCoreUI/Behaviors/PollingBehaviorModel.swift b/MVMCoreUI/Behaviors/PollingBehaviorModel.swift index b8e2eee0..0d40f4cd 100644 --- a/MVMCoreUI/Behaviors/PollingBehaviorModel.swift +++ b/MVMCoreUI/Behaviors/PollingBehaviorModel.swift @@ -137,6 +137,7 @@ public class PollingBehavior: NSObject, PageVisibilityBehavior, PageMoleculeTran } deinit { + debugLog("deinit") pollTimer?.cancel() } } diff --git a/MVMCoreUI/Behaviors/ReplaceableMoleculeBehaviorModel.swift b/MVMCoreUI/Behaviors/ReplaceableMoleculeBehaviorModel.swift index 233efdcc..08f9c2f9 100644 --- a/MVMCoreUI/Behaviors/ReplaceableMoleculeBehaviorModel.swift +++ b/MVMCoreUI/Behaviors/ReplaceableMoleculeBehaviorModel.swift @@ -15,7 +15,16 @@ public class ReplaceableMoleculeBehaviorModel: PageBehaviorModelProtocol { public var moleculeIds: [String] } -public class ReplaceableMoleculeBehavior: PageMoleculeTransformationBehavior { +public class ReplaceableMoleculeBehavior: PageMoleculeTransformationBehavior, CoreLogging { + + public var loggingPrefix: String { + "\(self) \(ObjectIdentifier(self))\n\(moleculeIds)\n" + } + + public static var loggingCategory: String? { + String(describing: Self.self) + } + var moleculeIds: [String] var modulesToListenFor: [String] private var observingForResponses: NSObjectProtocol? @@ -34,9 +43,11 @@ public class ReplaceableMoleculeBehavior: PageMoleculeTransformationBehavior { self.delegateObject = delegateObject guard let pageType = delegateObject?.moleculeDelegate?.getTemplateModel()?.pageType else { return } MVMCoreViewControllerMappingObject.shared()?.addOptionalModules(toMapping: moleculeIds, forPageType: pageType) + Self.debugLog("Initializing for \((model as! ReplaceableMoleculeBehaviorModel).moleculeIds)") } public func onPageNew(rootMolecules: [MoleculeModelProtocol], _ delegateObject: MVMCoreUIDelegateObject?) { + debugLog("onPageNew") self.delegateObject = delegateObject let shouldListenForListUpdates = delegateObject?.moleculeListDelegate != nil if shouldListenForListUpdates { @@ -70,7 +81,9 @@ public class ReplaceableMoleculeBehavior: PageMoleculeTransformationBehavior { let pageUpdateQueue = OperationQueue() pageUpdateQueue.maxConcurrentOperationCount = 1 pageUpdateQueue.qualityOfService = .userInteractive - observingForResponses = NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: NotificationResponseLoaded), object: nil, queue: pageUpdateQueue, using: responseJSONUpdated(notification:)) + observingForResponses = NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: NotificationResponseLoaded), object: nil, queue: pageUpdateQueue) { [weak self] notification in + self?.responseJSONUpdated(notification: notification) + } } private func stopListeningForModuleUpdates() { @@ -97,7 +110,7 @@ public class ReplaceableMoleculeBehavior: PageMoleculeTransformationBehavior { guard modules.count > 0 else { return } #if LOGGING let requestParams = (notification.userInfo?["MVMCoreLoadObject"] as? MVMCoreLoadObject)?.requestParameters - MVMCoreLoggingHandler.shared()?.handleDebugMessage("Replacing \(modules.map { $0.id }) from \(requestParams?.url?.absoluteString ?? "unknown"), e2eId: \(requestParams?.identifier ?? "unknown")") + debugLog("Replacing \(modules.map { $0.id }) from \(requestParams?.url?.absoluteString ?? "unknown"), e2eId: \(requestParams?.identifier ?? "unknown")") #endif delegateObject?.moleculeDelegate?.replaceMoleculeData(modules) { replacedModels in let modules = replacedModels.compactMap { modulesLoaded.dictionaryForKey($0.id) } @@ -113,4 +126,9 @@ public class ReplaceableMoleculeBehavior: PageMoleculeTransformationBehavior { } return try modelType.decode(jsonDict: moduleJSON as [String : Any]) as! MoleculeModelProtocol } + + deinit { + debugLog("deinit") + stopListeningForModuleUpdates() + } }