Merge branch 'feature/ActionHandlerRegistration' into 'develop'
Action Handler Registry See merge request BPHV_MIPS/mvm_core!180
This commit is contained in:
commit
587f5a7bf7
@ -8,6 +8,22 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
|
public protocol MVMCoreActionHandlerProtocol: ModelHandlerProtocol {
|
||||||
|
init()
|
||||||
|
func handleAction(_ model: ActionModelProtocol, additionalData: [AnyHashable : Any]?, delegateObject: DelegateObject?)
|
||||||
|
}
|
||||||
|
|
||||||
|
extension ModelRegistry {
|
||||||
|
public static func getActionHandler(_ model: ActionModelProtocol) throws -> MVMCoreActionHandlerProtocol {
|
||||||
|
do {
|
||||||
|
let type = try ModelRegistry.getHandler(model) as! MVMCoreActionHandlerProtocol.Type
|
||||||
|
return type.init()
|
||||||
|
} catch {
|
||||||
|
throw ModelRegistry.Error.other(message: error.localizedDescription)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public extension MVMCoreActionHandler {
|
public extension MVMCoreActionHandler {
|
||||||
|
|
||||||
/// Converts the action to json for old action handler to handle.
|
/// Converts the action to json for old action handler to handle.
|
||||||
@ -26,6 +42,36 @@ public extension MVMCoreActionHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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,
|
||||||
|
let actionInformation = actionInformation,
|
||||||
|
let actionModelType = ModelRegistry.getType(for: actionType, with: ActionModelProtocol.self)
|
||||||
|
else { return false }
|
||||||
|
|
||||||
|
do {
|
||||||
|
//deserialize the actionModel for the actionType found
|
||||||
|
guard let actionModel = try actionModelType.decode(jsonDict: actionInformation) as? ActionModelProtocol else {
|
||||||
|
throw ModelRegistry.Error.decoderOther(message: "Could not decode to ActionModelProtocol")
|
||||||
|
}
|
||||||
|
|
||||||
|
//get the action Handler for the actionModel created
|
||||||
|
let actionHandler = try ModelRegistry.getActionHandler(actionModel)
|
||||||
|
|
||||||
|
//call the handleAction of the handler
|
||||||
|
actionHandler.handleAction(actionModel, additionalData: additionalData, delegateObject: delegateObject)
|
||||||
|
|
||||||
|
} catch {
|
||||||
|
//log the error
|
||||||
|
if let errorObject = MVMCoreErrorObject.createErrorObject(for: error, location: "") {
|
||||||
|
MVMCoreActionHandler.shared()?.defaultHandleActionError(errorObject, additionalData: additionalData)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//complete
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
/// Start action on current thread.
|
/// Start action on current thread.
|
||||||
func syncHandleAction(with model: ActionModelProtocol, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) {
|
func syncHandleAction(with model: ActionModelProtocol, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) {
|
||||||
guard let json = convertActionToJSON(model, delegateObject: delegateObject) else { return }
|
guard let json = convertActionToJSON(model, delegateObject: delegateObject) else { return }
|
||||||
|
|||||||
@ -387,7 +387,7 @@ NSString * const KeyActionTypeOpen = @"openPage";
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)handleOtherActions:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject {
|
- (BOOL)handleOtherActions:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject {
|
||||||
return NO;
|
return [self hasActionHandlerWithActionType:actionType actionInformation:actionInformation additionalData:additionalData delegateObject:delegateObject];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)unknownAction:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject {
|
- (void)unknownAction:(nullable NSString *)actionType actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user