From 5c53466dac1321b14ed05f3221fa8b756ea6eb1d Mon Sep 17 00:00:00 2001 From: Scott Pfeil Date: Fri, 12 Aug 2022 16:17:00 -0400 Subject: [PATCH] Centralize SoureModel --- MVMCore/MVMCore.xcodeproj/project.pbxproj | 4 ---- .../ActionOpenPageHandler.swift | 12 ++++++---- .../ActionPreviousSubmitHandler.swift | 7 +++++- .../MVMCoreLoadHandler+Extension.swift | 22 ------------------- 4 files changed, 14 insertions(+), 31 deletions(-) delete mode 100644 MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler+Extension.swift diff --git a/MVMCore/MVMCore.xcodeproj/project.pbxproj b/MVMCore/MVMCore.xcodeproj/project.pbxproj index d14b68c..5bfb648 100644 --- a/MVMCore/MVMCore.xcodeproj/project.pbxproj +++ b/MVMCore/MVMCore.xcodeproj/project.pbxproj @@ -105,7 +105,6 @@ AF70699A287DD02400077CF6 /* ActionContactHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF706999287DD02400077CF6 /* ActionContactHandler.swift */; }; AF70699E2880D01400077CF6 /* ActionShareHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF70699D2880D01400077CF6 /* ActionShareHandler.swift */; }; AF7069A02880F0EB00077CF6 /* ActionOpenPageHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF70699F2880F0EB00077CF6 /* ActionOpenPageHandler.swift */; }; - AF7069A22882293900077CF6 /* MVMCoreLoadHandler+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF7069A12882293900077CF6 /* MVMCoreLoadHandler+Extension.swift */; }; AF787413286DEF8B00670588 /* ActionBackHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF787412286DEF8B00670588 /* ActionBackHandler.swift */; }; AF8D13392774EA1D008AF4A9 /* ActionOpenUrlHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF8D13382774EA1D008AF4A9 /* ActionOpenUrlHandler.swift */; }; AFBB96341FBA34310008D868 /* MVMCoreErrorConstants.h in Headers */ = {isa = PBXBuildFile; fileRef = AFBB96321FBA34310008D868 /* MVMCoreErrorConstants.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -268,7 +267,6 @@ AF706999287DD02400077CF6 /* ActionContactHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionContactHandler.swift; sourceTree = ""; }; AF70699D2880D01400077CF6 /* ActionShareHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionShareHandler.swift; sourceTree = ""; }; AF70699F2880F0EB00077CF6 /* ActionOpenPageHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionOpenPageHandler.swift; sourceTree = ""; }; - AF7069A12882293900077CF6 /* MVMCoreLoadHandler+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MVMCoreLoadHandler+Extension.swift"; sourceTree = ""; }; AF787412286DEF8B00670588 /* ActionBackHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionBackHandler.swift; sourceTree = ""; }; AF8D13382774EA1D008AF4A9 /* ActionOpenUrlHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionOpenUrlHandler.swift; sourceTree = ""; }; AFBB96321FBA34310008D868 /* MVMCoreErrorConstants.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreErrorConstants.h; sourceTree = ""; }; @@ -577,7 +575,6 @@ AFBB96371FBA39E70008D868 /* MVMCoreLoadDelegateProtocol.h */, AFBB96391FBA3A550008D868 /* MVMCoreLoadHandler.h */, AFBB964B1FBA3A560008D868 /* MVMCoreLoadHandler.m */, - AF7069A12882293900077CF6 /* MVMCoreLoadHandler+Extension.swift */, AFBB964A1FBA3A560008D868 /* MVMCoreLoadRequestOperation.h */, AFBB96521FBA3A570008D868 /* MVMCoreLoadRequestOperation.m */, AFBB96471FBA3A560008D868 /* MVMCoreLoadObject.h */, @@ -913,7 +910,6 @@ AF43A74D1FC6109F008E9347 /* MVMCoreSessionObject.m in Sources */, D282AAB62240085300C46919 /* MVMCoreGetterUtility+Extension.swift in Sources */, AFBB96901FBA3A9A0008D868 /* MVMCoreNavigationObject.m in Sources */, - AF7069A22882293900077CF6 /* MVMCoreLoadHandler+Extension.swift in Sources */, 1DAD0FFE26AAB40000216E83 /* ActionRunJavaScriptModel.swift in Sources */, 946EE1AB237B5C940036751F /* Decoder.swift in Sources */, AF70699A287DD02400077CF6 /* ActionContactHandler.swift in Sources */, diff --git a/MVMCore/MVMCore/ActionHandling/ActionOpenPageHandler.swift b/MVMCore/MVMCore/ActionHandling/ActionOpenPageHandler.swift index 7011008..7bdc502 100644 --- a/MVMCore/MVMCore/ActionHandling/ActionOpenPageHandler.swift +++ b/MVMCore/MVMCore/ActionHandling/ActionOpenPageHandler.swift @@ -17,8 +17,12 @@ open class ActionOpenPageHandler: MVMCoreJSONActionHandlerProtocol { if let closure = delegateObject?.actionDelegate?.handleOpenPage { // Legacy code will use the old handler function and break the task chain here. closure(model.requestParameters, JSON, additionalData) - } else { - try await performRequestAddingClientParameters(with: model.requestParameters, model: model, delegateObject: delegateObject, additionalData: additionalData) + } else if let operation = try await performRequestAddingClientParameters(with: model.requestParameters, model: model, delegateObject: delegateObject, additionalData: additionalData) { + await withCheckedContinuation { continuation in + operation.completionBlock = { + continuation.resume() + } + } } } catch { try handle(error: error, model: model, delegateObject: delegateObject) @@ -37,14 +41,14 @@ open class ActionOpenPageHandler: MVMCoreJSONActionHandlerProtocol { } /// Adds client parameters and makes calls performRequest() - open func performRequestAddingClientParameters(with requestParameters: MVMCoreRequestParameters, model: ActionOpenPageModel, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?) async throws { + open func performRequestAddingClientParameters(with requestParameters: MVMCoreRequestParameters, model: ActionOpenPageModel, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?) async throws -> MVMCoreLoadRequestOperation? { // Adds any client parameters to the request parameters. if let parametersToFetch = model.clientParameters, let fetchedParameters = try await ClientParameterHandler().getClientParameters(with: parametersToFetch, requestParameters: requestParameters.parameters as? [String : Any] ?? [:], showLoadingOverlay: !requestParameters.backgroundRequest) { requestParameters.add(fetchedParameters) } try Task.checkCancellation() - try await MVMCoreLoadHandler.sharedGlobal()?.performRequest(with: requestParameters, delegateObject: delegateObject, additionalData: additionalData) + return MVMCoreLoadHandler.sharedGlobal()?.loadRequest(requestParameters, dataForPage: additionalData, delegateObject: delegateObject) } /// Ensures background requests do not have showing errors. diff --git a/MVMCore/MVMCore/ActionHandling/ActionPreviousSubmitHandler.swift b/MVMCore/MVMCore/ActionHandling/ActionPreviousSubmitHandler.swift index 9fd12d4..a3bded2 100644 --- a/MVMCore/MVMCore/ActionHandling/ActionPreviousSubmitHandler.swift +++ b/MVMCore/MVMCore/ActionHandling/ActionPreviousSubmitHandler.swift @@ -36,7 +36,12 @@ open class ActionPreviousSubmitHandler: MVMCoreJSONActionHandlerProtocol { let json = try json ?? MVMCoreActionHandler.convertActionToJSON(model) delegateObject?.actionDelegate?.handleOpenPage?(for: previousRequest, actionInformation: json, additionalData: additionalData) } else { - try await MVMCoreLoadHandler.sharedGlobal()?.performRequest(with: previousRequest, delegateObject: delegateObject, additionalData: additionalData) + guard let operation = MVMCoreLoadHandler.sharedGlobal()?.loadRequest(previousRequest, dataForPage: additionalData, delegateObject: delegateObject) else { return } + await withCheckedContinuation { continuation in + operation.completionBlock = { + continuation.resume() + } + } } } } diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler+Extension.swift b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler+Extension.swift deleted file mode 100644 index 48c626f..0000000 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler+Extension.swift +++ /dev/null @@ -1,22 +0,0 @@ -// -// MVMCoreLoadHandler+Extension.swift -// MVMCore -// -// Created by Scott Pfeil on 7/15/22. -// Copyright © 2022 myverizon. All rights reserved. -// - -import Foundation - -public extension MVMCoreLoadHandler { - /// Performs the request. - func performRequest(with requestParameters: MVMCoreRequestParameters, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?) async throws { - // Makes the request and waits for it. TODO: Any way to take errors into account? - let operation = loadRequest(requestParameters, dataForPage: additionalData, delegateObject: delegateObject) - await withCheckedContinuation { continuation in - operation.completionBlock = { - continuation.resume() - } - } - } -}