Making the shouldFinishProcessingLoad method in behavior to throw

This commit is contained in:
Sumanth Nadigadda 2023-02-22 23:19:57 +05:30
parent 904cdf3798
commit 29c73f2ccc
3 changed files with 17 additions and 12 deletions

View File

@ -147,12 +147,17 @@ import MVMCore
} }
///Check with behavior if it can continue ///Check with behavior if it can continue
let conditionSatisfied = conditionSatisfyingBehaviours { (behavior: PageMoleculeTransformationBehavior) in do{
return behavior.shouldFinishProcessingLoad(loadObject) let conditionSatisfied = try executeThrowingBehaviors {(behavior: PageMoleculeTransformationBehavior) in
} return try behavior.shouldFinishProcessingLoad(loadObject)
}
if conditionSatisfied == false { if conditionSatisfied == false {
return conditionSatisfied return conditionSatisfied
}
} catch let behaviorError {
if let errorObject = MVMCoreErrorObject.createErrorObject(for: behaviorError, location: MVMCoreLoadHandler.sharedGlobal()?.errorLocation(forRequest: loadObject)) {
error.pointee = errorObject
}
} }
return true return true

View File

@ -45,7 +45,7 @@ public extension PageBehaviorHandlerProtocol {
behaviors?.compactMap { $0 as? T }.forEach { behaviorBlock($0) } behaviors?.compactMap { $0 as? T }.forEach { behaviorBlock($0) }
} }
func conditionSatisfyingBehaviours<T>(_ behaviourBlock: (_ behavior: T) -> Bool) -> Bool { func executeThrowingBehaviors<T>(_ behaviourBlock: (_ behavior: T) throws -> Bool) throws -> Bool {
return behaviors?.compactMap({$0 as? T}).allSatisfy({ return behaviourBlock($0) }) ?? false return try behaviors?.compactMap({$0 as? T}).allSatisfy({ return try behaviourBlock($0) }) ?? false
} }
} }

View File

@ -32,7 +32,7 @@ public protocol PageMoleculeTransformationBehavior: PageBehaviorProtocol {
func didSetupMolecule(view: MoleculeViewProtocol, withModel: MoleculeModelProtocol) func didSetupMolecule(view: MoleculeViewProtocol, withModel: MoleculeModelProtocol)
func willSetupNavigationBar(with model: NavigationItemModelProtocol, updating view: UINavigationBar) func willSetupNavigationBar(with model: NavigationItemModelProtocol, updating view: UINavigationBar)
func didSetupNavigationBar(view: UINavigationBar, with model: NavigationItemModelProtocol) func didSetupNavigationBar(view: UINavigationBar, with model: NavigationItemModelProtocol)
func shouldFinishProcessingLoad(_ loadObject: MVMCoreLoadObject) -> Bool func shouldFinishProcessingLoad(_ loadObject: MVMCoreLoadObject) throws -> Bool
} }
public extension PageMoleculeTransformationBehavior { public extension PageMoleculeTransformationBehavior {
@ -42,7 +42,7 @@ public extension PageMoleculeTransformationBehavior {
func didSetupMolecule(view: MoleculeViewProtocol, withModel: MoleculeModelProtocol) {} func didSetupMolecule(view: MoleculeViewProtocol, withModel: MoleculeModelProtocol) {}
func willSetupNavigationBar(with model: NavigationItemModelProtocol, updating view: UINavigationBar) {} func willSetupNavigationBar(with model: NavigationItemModelProtocol, updating view: UINavigationBar) {}
func didSetupNavigationBar(view: UINavigationBar, with model: NavigationItemModelProtocol) {} 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 { public protocol PageVisibilityBehavior: PageBehaviorProtocol {