refactored the hasActionHanlder guard
bug - added public to JSONValue decode Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
7f5419d81b
commit
9293894d36
@ -32,30 +32,29 @@ public extension MVMCoreActionHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@objc func hasActionHandler(actionType: String?, actionInformation: [String: Any]?, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) -> Bool {
|
@objc func hasActionHandler(actionType: String?, actionInformation: [String: Any]?, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) -> Bool {
|
||||||
//ensure there is a Serialized version of the Action
|
|
||||||
guard let actionType = actionType,
|
guard //ensure there is a actinType
|
||||||
|
let actionType = actionType,
|
||||||
|
//ensure there is a serialized version of the Action
|
||||||
let actionInformation = actionInformation,
|
let actionInformation = actionInformation,
|
||||||
|
//esnure the actionModelType
|
||||||
let actionModelType = ModelRegistry.getType(for: actionType, with: ActionModelProtocol.self),
|
let actionModelType = ModelRegistry.getType(for: actionType, with: ActionModelProtocol.self),
|
||||||
let actionHandlerType = try? ModelRegistry.getHandlerType(for: actionModelType)
|
//ensure there is handlerType for the action of MVMCoreActionHandlerProtocol
|
||||||
|
let actionHandlerType = try? ModelRegistry.getHandlerType(for: actionModelType) as? MVMCoreActionHandlerProtocol.Type
|
||||||
else { return false }
|
else { return false }
|
||||||
|
|
||||||
do {
|
do {
|
||||||
//Cast the actionHandlerType to the new Protocol
|
//ensure the decoded actionModel is of ActionModelProtocol
|
||||||
guard let actionHandlerProtocolType = actionHandlerType as? MVMCoreActionHandlerProtocol.Type else {
|
|
||||||
throw ModelRegistry.Error.decoderOther(message: "ModelHandlerProtocol found not of MVMCoreActionHandlerProtocol Type")
|
|
||||||
}
|
|
||||||
|
|
||||||
//deserialize the actionModel for the actionType found
|
|
||||||
guard let actionModel = try actionModelType.decode(jsonDict: actionInformation) as? ActionModelProtocol else {
|
guard let actionModel = try actionModelType.decode(jsonDict: actionInformation) as? ActionModelProtocol else {
|
||||||
throw ModelRegistry.Error.decoderOther(message: "Could not decode to ActionModelProtocol")
|
throw ModelRegistry.Error.decoderOther(message: "Could not decode to ActionModelProtocol")
|
||||||
}
|
}
|
||||||
|
|
||||||
//create the handler since we know it can initialize
|
//create the handler since we know it can initialize
|
||||||
let actionHandler = actionHandlerProtocolType.init()
|
let actionHandler = actionHandlerType.init()
|
||||||
|
|
||||||
//call the handleAction of the handler
|
//call the handleAction of the handler
|
||||||
actionHandler.handleAction(actionModel, additionalData: additionalData, delegateObject: delegateObject)
|
actionHandler.handleAction(actionModel, additionalData: additionalData, delegateObject: delegateObject)
|
||||||
|
|
||||||
} catch {
|
} catch {
|
||||||
//log the error
|
//log the error
|
||||||
if let errorObject = MVMCoreErrorObject.createErrorObject(for: error, location: "") {
|
if let errorObject = MVMCoreErrorObject.createErrorObject(for: error, location: "") {
|
||||||
|
|||||||
@ -51,7 +51,7 @@ public enum JSONValue: Codable, Equatable {
|
|||||||
self = value ?? JSONValue.null
|
self = value ?? JSONValue.null
|
||||||
}
|
}
|
||||||
|
|
||||||
func decode<T: Decodable>() throws -> T {
|
public func decode<T: Decodable>() throws -> T {
|
||||||
let encoded = try JSONEncoder().encode(self)
|
let encoded = try JSONEncoder().encode(self)
|
||||||
return try JSONDecoder().decode(T.self, from: encoded)
|
return try JSONDecoder().decode(T.self, from: encoded)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user