Add will render event to avoid circumvent addRemoveListItemBehavior conflict. Page concurrent update sequentialization.

This commit is contained in:
Hedden, Kyle Matthew 2023-09-18 19:20:26 -04:00
parent 33a05b79a6
commit 1cb490f822
3 changed files with 13 additions and 8 deletions

View File

@ -38,7 +38,7 @@ import MVMCore
public var behaviors: [PageBehaviorProtocol]?
public var needsUpdateUI = false
private var observingForResponses = false
private var observingForResponses: NSObjectProtocol?
private var initialLoadFinished = false
public var previousScreenSize = CGSize.zero
@ -54,18 +54,21 @@ import MVMCore
//--------------------------------------------------
open func observeForResponseJSONUpdates() {
guard !observingForResponses,
guard observingForResponses == nil,
(pagesToListenFor()?.count ?? 0 > 0 || modulesToListenFor()?.count ?? 0 > 0)
else { return }
observingForResponses = true
NotificationCenter.default.addObserver(self, selector: #selector(responseJSONUpdated(notification:)), name: NSNotification.Name(rawValue: NotificationResponseLoaded), object: nil)
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:))
}
open func stopObservingForResponseJSONUpdates() {
guard observingForResponses else { return }
NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NotificationResponseLoaded), object: nil)
observingForResponses = false
guard let observingForResponses = observingForResponses else { return }
NotificationCenter.default.removeObserver(observingForResponses)
self.observingForResponses = nil
}
open func pagesToListenFor() -> [String]? {

View File

@ -76,7 +76,7 @@ public class AddRemoveMoleculesBehavior: PageCustomActionHandlerBehavior, PageMo
self.delegate = delegateObject
}
public func onPageNew(rootMolecules: [MoleculeModelProtocol], _ delegateObject: MVMCoreUIDelegateObject?) {
public func willRender(rootMolecules: [MoleculeModelProtocol], _ delegateObject: MVMCoreUIDelegateObject?) {
guard let list = delegate?.moleculeListDelegate else { return }
for case let model as (MoleculeModelProtocol & ListItemModelProtocol & AddMolecules) in rootMolecules {
if let moleculesToAdd = model.getRecursiveMoleculesToAdd(),

View File

@ -35,6 +35,7 @@ public protocol PageMoleculeTransformationBehavior: PageBehaviorProtocol {
func didSetupMolecule(view: MoleculeViewProtocol, withModel: MoleculeModelProtocol)
func willSetupNavigationBar(with model: NavigationItemModelProtocol, updating view: UINavigationBar)
func didSetupNavigationBar(view: UINavigationBar, with model: NavigationItemModelProtocol)
func willRender(rootMolecules: [MoleculeModelProtocol], _ delegateObject: MVMCoreUIDelegateObject?)
func shouldFinishProcessingLoad(_ loadObject: MVMCoreLoadObject) throws -> Bool
}
@ -45,6 +46,7 @@ public extension PageMoleculeTransformationBehavior {
func didSetupMolecule(view: MoleculeViewProtocol, withModel: MoleculeModelProtocol) {}
func willSetupNavigationBar(with model: NavigationItemModelProtocol, updating view: UINavigationBar) {}
func didSetupNavigationBar(view: UINavigationBar, with model: NavigationItemModelProtocol) {}
func willRender(rootMolecules: [MoleculeModelProtocol], _ delegateObject: MVMCoreUIDelegateObject?) {}
func shouldFinishProcessingLoad(_ loadObject: MVMCoreLoadObject) throws -> Bool { return true }
}