From 904cdf3798d8b83c4f0750e43295efe22d1136da Mon Sep 17 00:00:00 2001 From: Sumanth Nadigadda Date: Wed, 22 Feb 2023 20:24:18 +0530 Subject: [PATCH 1/4] Introducing shouldFinishProcessingLoad call to behavior to check if we can continue to load the viewcontroller --- MVMCoreUI/BaseControllers/ViewController.swift | 9 +++++++++ .../Protocols/PageBehaviorHandlerProtocol.swift | 4 ++++ MVMCoreUI/Behaviors/Protocols/PageBehaviorProtocol.swift | 2 ++ 3 files changed, 15 insertions(+) diff --git a/MVMCoreUI/BaseControllers/ViewController.swift b/MVMCoreUI/BaseControllers/ViewController.swift index c6c64f3a..cab9d9ce 100644 --- a/MVMCoreUI/BaseControllers/ViewController.swift +++ b/MVMCoreUI/BaseControllers/ViewController.swift @@ -146,6 +146,15 @@ import MVMCore } } + ///Check with behavior if it can continue + let conditionSatisfied = conditionSatisfyingBehaviours { (behavior: PageMoleculeTransformationBehavior) in + return behavior.shouldFinishProcessingLoad(loadObject) + } + + if conditionSatisfied == false { + return conditionSatisfied + } + return true } diff --git a/MVMCoreUI/Behaviors/Protocols/PageBehaviorHandlerProtocol.swift b/MVMCoreUI/Behaviors/Protocols/PageBehaviorHandlerProtocol.swift index 971a052b..dcd8a2eb 100644 --- a/MVMCoreUI/Behaviors/Protocols/PageBehaviorHandlerProtocol.swift +++ b/MVMCoreUI/Behaviors/Protocols/PageBehaviorHandlerProtocol.swift @@ -44,4 +44,8 @@ public extension PageBehaviorHandlerProtocol { func executeBehaviors(_ behaviorBlock: (_ behavior: T) -> Void) { behaviors?.compactMap { $0 as? T }.forEach { behaviorBlock($0) } } + + func conditionSatisfyingBehaviours(_ behaviourBlock: (_ behavior: T) -> Bool) -> Bool { + return behaviors?.compactMap({$0 as? T}).allSatisfy({ return behaviourBlock($0) }) ?? false + } } diff --git a/MVMCoreUI/Behaviors/Protocols/PageBehaviorProtocol.swift b/MVMCoreUI/Behaviors/Protocols/PageBehaviorProtocol.swift index d5f65323..c8b05055 100644 --- a/MVMCoreUI/Behaviors/Protocols/PageBehaviorProtocol.swift +++ b/MVMCoreUI/Behaviors/Protocols/PageBehaviorProtocol.swift @@ -32,6 +32,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 shouldFinishProcessingLoad(_ loadObject: MVMCoreLoadObject) -> Bool } public extension PageMoleculeTransformationBehavior { @@ -41,6 +42,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 shouldFinishProcessingLoad(_ loadObject: MVMCoreLoadObject) -> Bool { return true } } public protocol PageVisibilityBehavior: PageBehaviorProtocol { From 29c73f2ccc883370b0295b433e8cdbc8339caaa0 Mon Sep 17 00:00:00 2001 From: Sumanth Nadigadda Date: Wed, 22 Feb 2023 23:19:57 +0530 Subject: [PATCH 2/4] Making the shouldFinishProcessingLoad method in behavior to throw --- .../BaseControllers/ViewController.swift | 21 ++++++++++++------- .../PageBehaviorHandlerProtocol.swift | 4 ++-- .../Protocols/PageBehaviorProtocol.swift | 4 ++-- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/MVMCoreUI/BaseControllers/ViewController.swift b/MVMCoreUI/BaseControllers/ViewController.swift index cab9d9ce..dddb918e 100644 --- a/MVMCoreUI/BaseControllers/ViewController.swift +++ b/MVMCoreUI/BaseControllers/ViewController.swift @@ -146,15 +146,20 @@ import MVMCore } } - ///Check with behavior if it can continue - let conditionSatisfied = conditionSatisfyingBehaviours { (behavior: PageMoleculeTransformationBehavior) in - return behavior.shouldFinishProcessingLoad(loadObject) + ///Check with behavior if it can continue + do{ + let conditionSatisfied = try executeThrowingBehaviors {(behavior: PageMoleculeTransformationBehavior) in + return try behavior.shouldFinishProcessingLoad(loadObject) + } + if conditionSatisfied == false { + return conditionSatisfied + } + } catch let behaviorError { + if let errorObject = MVMCoreErrorObject.createErrorObject(for: behaviorError, location: MVMCoreLoadHandler.sharedGlobal()?.errorLocation(forRequest: loadObject)) { + error.pointee = errorObject + } } - - if conditionSatisfied == false { - return conditionSatisfied - } - + return true } diff --git a/MVMCoreUI/Behaviors/Protocols/PageBehaviorHandlerProtocol.swift b/MVMCoreUI/Behaviors/Protocols/PageBehaviorHandlerProtocol.swift index dcd8a2eb..b0d49b69 100644 --- a/MVMCoreUI/Behaviors/Protocols/PageBehaviorHandlerProtocol.swift +++ b/MVMCoreUI/Behaviors/Protocols/PageBehaviorHandlerProtocol.swift @@ -45,7 +45,7 @@ public extension PageBehaviorHandlerProtocol { behaviors?.compactMap { $0 as? T }.forEach { behaviorBlock($0) } } - func conditionSatisfyingBehaviours(_ behaviourBlock: (_ behavior: T) -> Bool) -> Bool { - return behaviors?.compactMap({$0 as? T}).allSatisfy({ return behaviourBlock($0) }) ?? false + func executeThrowingBehaviors(_ behaviourBlock: (_ behavior: T) throws -> Bool) throws -> Bool { + return try behaviors?.compactMap({$0 as? T}).allSatisfy({ return try behaviourBlock($0) }) ?? false } } diff --git a/MVMCoreUI/Behaviors/Protocols/PageBehaviorProtocol.swift b/MVMCoreUI/Behaviors/Protocols/PageBehaviorProtocol.swift index c8b05055..543ee60c 100644 --- a/MVMCoreUI/Behaviors/Protocols/PageBehaviorProtocol.swift +++ b/MVMCoreUI/Behaviors/Protocols/PageBehaviorProtocol.swift @@ -32,7 +32,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 shouldFinishProcessingLoad(_ loadObject: MVMCoreLoadObject) -> Bool + func shouldFinishProcessingLoad(_ loadObject: MVMCoreLoadObject) throws -> Bool } public extension PageMoleculeTransformationBehavior { @@ -42,7 +42,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 shouldFinishProcessingLoad(_ loadObject: MVMCoreLoadObject) -> Bool { return true } + func shouldFinishProcessingLoad(_ loadObject: MVMCoreLoadObject) throws -> Bool { return true } } public protocol PageVisibilityBehavior: PageBehaviorProtocol { From d647dc9d18d08e27263946a63ee759ef8bd4ecd3 Mon Sep 17 00:00:00 2001 From: Sumanth Nadigadda Date: Thu, 23 Feb 2023 20:54:35 +0530 Subject: [PATCH 3/4] shouldFinishProcessingLoad Behavior flow - Minor changes --- MVMCoreUI/BaseControllers/ViewController.swift | 6 ++---- .../Behaviors/Protocols/PageBehaviorHandlerProtocol.swift | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/MVMCoreUI/BaseControllers/ViewController.swift b/MVMCoreUI/BaseControllers/ViewController.swift index dddb918e..fe7eee30 100644 --- a/MVMCoreUI/BaseControllers/ViewController.swift +++ b/MVMCoreUI/BaseControllers/ViewController.swift @@ -148,12 +148,10 @@ import MVMCore ///Check with behavior if it can continue do{ - let conditionSatisfied = try executeThrowingBehaviors {(behavior: PageMoleculeTransformationBehavior) in + let allFinishedProcessingLoad = try executeThrowingBehaviors {(behavior: PageMoleculeTransformationBehavior) in return try behavior.shouldFinishProcessingLoad(loadObject) } - if conditionSatisfied == false { - return conditionSatisfied - } + guard allFinishedProcessingLoad else { return false } } catch let behaviorError { if let errorObject = MVMCoreErrorObject.createErrorObject(for: behaviorError, location: MVMCoreLoadHandler.sharedGlobal()?.errorLocation(forRequest: loadObject)) { error.pointee = errorObject diff --git a/MVMCoreUI/Behaviors/Protocols/PageBehaviorHandlerProtocol.swift b/MVMCoreUI/Behaviors/Protocols/PageBehaviorHandlerProtocol.swift index b0d49b69..9e5c6a6d 100644 --- a/MVMCoreUI/Behaviors/Protocols/PageBehaviorHandlerProtocol.swift +++ b/MVMCoreUI/Behaviors/Protocols/PageBehaviorHandlerProtocol.swift @@ -46,6 +46,6 @@ public extension PageBehaviorHandlerProtocol { } func executeThrowingBehaviors(_ behaviourBlock: (_ behavior: T) throws -> Bool) throws -> Bool { - return try behaviors?.compactMap({$0 as? T}).allSatisfy({ return try behaviourBlock($0) }) ?? false + return try behaviors?.compactMap({$0 as? T}).allSatisfy({ return try behaviourBlock($0) }) ?? true } } From 2ecfa6e9249217999dfc15e1ff56485a435d1cad Mon Sep 17 00:00:00 2001 From: Sumanth Nadigadda Date: Tue, 21 Mar 2023 22:28:02 +0530 Subject: [PATCH 4/4] Return false in shouldFinishProcessing flow in case behavior has thrown any error --- MVMCoreUI/BaseControllers/ViewController.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/MVMCoreUI/BaseControllers/ViewController.swift b/MVMCoreUI/BaseControllers/ViewController.swift index fe7eee30..fc176da5 100644 --- a/MVMCoreUI/BaseControllers/ViewController.swift +++ b/MVMCoreUI/BaseControllers/ViewController.swift @@ -156,6 +156,7 @@ import MVMCore if let errorObject = MVMCoreErrorObject.createErrorObject(for: behaviorError, location: MVMCoreLoadHandler.sharedGlobal()?.errorLocation(forRequest: loadObject)) { error.pointee = errorObject } + return false } return true