Digital PCT265 story ONEAPP-7249 - Fix notification retain cycle.
This commit is contained in:
parent
658850400f
commit
067f63e6de
@ -65,7 +65,9 @@ import MVMCore
|
|||||||
(pagesToListenFor()?.count ?? 0 > 0 || modulesToListenFor()?.count ?? 0 > 0)
|
(pagesToListenFor()?.count ?? 0 > 0 || modulesToListenFor()?.count ?? 0 > 0)
|
||||||
else { return }
|
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() {
|
open func stopObservingForResponseJSONUpdates() {
|
||||||
|
|||||||
@ -137,6 +137,7 @@ public class PollingBehavior: NSObject, PageVisibilityBehavior, PageMoleculeTran
|
|||||||
}
|
}
|
||||||
|
|
||||||
deinit {
|
deinit {
|
||||||
|
debugLog("deinit")
|
||||||
pollTimer?.cancel()
|
pollTimer?.cancel()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,7 +15,16 @@ public class ReplaceableMoleculeBehaviorModel: PageBehaviorModelProtocol {
|
|||||||
public var moleculeIds: [String]
|
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 moleculeIds: [String]
|
||||||
var modulesToListenFor: [String]
|
var modulesToListenFor: [String]
|
||||||
private var observingForResponses: NSObjectProtocol?
|
private var observingForResponses: NSObjectProtocol?
|
||||||
@ -34,9 +43,11 @@ public class ReplaceableMoleculeBehavior: PageMoleculeTransformationBehavior {
|
|||||||
self.delegateObject = delegateObject
|
self.delegateObject = delegateObject
|
||||||
guard let pageType = delegateObject?.moleculeDelegate?.getTemplateModel()?.pageType else { return }
|
guard let pageType = delegateObject?.moleculeDelegate?.getTemplateModel()?.pageType else { return }
|
||||||
MVMCoreViewControllerMappingObject.shared()?.addOptionalModules(toMapping: moleculeIds, forPageType: pageType)
|
MVMCoreViewControllerMappingObject.shared()?.addOptionalModules(toMapping: moleculeIds, forPageType: pageType)
|
||||||
|
Self.debugLog("Initializing for \((model as! ReplaceableMoleculeBehaviorModel).moleculeIds)")
|
||||||
}
|
}
|
||||||
|
|
||||||
public func onPageNew(rootMolecules: [MoleculeModelProtocol], _ delegateObject: MVMCoreUIDelegateObject?) {
|
public func onPageNew(rootMolecules: [MoleculeModelProtocol], _ delegateObject: MVMCoreUIDelegateObject?) {
|
||||||
|
debugLog("onPageNew")
|
||||||
self.delegateObject = delegateObject
|
self.delegateObject = delegateObject
|
||||||
let shouldListenForListUpdates = delegateObject?.moleculeListDelegate != nil
|
let shouldListenForListUpdates = delegateObject?.moleculeListDelegate != nil
|
||||||
if shouldListenForListUpdates {
|
if shouldListenForListUpdates {
|
||||||
@ -70,7 +81,9 @@ public class ReplaceableMoleculeBehavior: PageMoleculeTransformationBehavior {
|
|||||||
let pageUpdateQueue = OperationQueue()
|
let pageUpdateQueue = OperationQueue()
|
||||||
pageUpdateQueue.maxConcurrentOperationCount = 1
|
pageUpdateQueue.maxConcurrentOperationCount = 1
|
||||||
pageUpdateQueue.qualityOfService = .userInteractive
|
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() {
|
private func stopListeningForModuleUpdates() {
|
||||||
@ -97,7 +110,7 @@ public class ReplaceableMoleculeBehavior: PageMoleculeTransformationBehavior {
|
|||||||
guard modules.count > 0 else { return }
|
guard modules.count > 0 else { return }
|
||||||
#if LOGGING
|
#if LOGGING
|
||||||
let requestParams = (notification.userInfo?["MVMCoreLoadObject"] as? MVMCoreLoadObject)?.requestParameters
|
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
|
#endif
|
||||||
delegateObject?.moleculeDelegate?.replaceMoleculeData(modules) { replacedModels in
|
delegateObject?.moleculeDelegate?.replaceMoleculeData(modules) { replacedModels in
|
||||||
let modules = replacedModels.compactMap { modulesLoaded.dictionaryForKey($0.id) }
|
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
|
return try modelType.decode(jsonDict: moduleJSON as [String : Any]) as! MoleculeModelProtocol
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deinit {
|
||||||
|
debugLog("deinit")
|
||||||
|
stopListeningForModuleUpdates()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user