code review
This commit is contained in:
parent
1d725bb6b8
commit
614a2b89c8
@ -8,11 +8,15 @@
|
||||
|
||||
public extension Dictionary {
|
||||
|
||||
func asActionModel() -> ActionModelProtocol? {
|
||||
guard let castedSelf = self as? [String: Any],
|
||||
let actionType = ModelRegistry.getType(for: castedSelf.stringForkey(KeyActionType), with: ActionModelProtocol.self),
|
||||
let actionModel = try? actionType.decode(jsonDict: castedSelf) as? ActionModelProtocol else {
|
||||
return nil
|
||||
func asActionModel() throws -> ActionModelProtocol {
|
||||
guard let castedSelf = self as? [String: Any] else {
|
||||
throw ModelRegistry.Error.decoderOther(message: "Dictionary is not of type [String: Any]")
|
||||
}
|
||||
guard let actionType = ModelRegistry.getType(for: castedSelf.stringForkey(KeyActionType), with: ActionModelProtocol.self) else {
|
||||
throw ModelRegistry.Error.decoderErrorModelNotMapped
|
||||
}
|
||||
guard let actionModel = try actionType.decode(jsonDict: castedSelf) as? ActionModelProtocol else {
|
||||
throw ModelRegistry.Error.decoderOther(message: "Could not decode to ActionModelProtocol")
|
||||
}
|
||||
return actionModel
|
||||
}
|
||||
|
||||
@ -12,11 +12,11 @@ public extension FooterModel {
|
||||
|
||||
var primaryButtonModel: ButtonModel?
|
||||
var secondaryButtonModel: ButtonModel?
|
||||
if let primaryActionModel = primaryMap?.asActionModel() {
|
||||
primaryButtonModel = ButtonModel(primaryButtonWith: primaryActionModel.title ?? "", action: primaryActionModel)
|
||||
if let primaryActionModel = try? primaryMap?.asActionModel(), let title = primaryActionModel.title {
|
||||
primaryButtonModel = ButtonModel(primaryButtonWith: title, action: primaryActionModel)
|
||||
}
|
||||
if let secondaryActionModel = secondaryMap?.asActionModel() {
|
||||
secondaryButtonModel = ButtonModel(secondaryButtonWith: secondaryActionModel.title ?? "", action: secondaryActionModel)
|
||||
if let secondaryActionModel = try? secondaryMap?.asActionModel(), let title = secondaryActionModel.title {
|
||||
secondaryButtonModel = ButtonModel(secondaryButtonWith: title, action: secondaryActionModel)
|
||||
}
|
||||
let twoButtonModel = TwoButtonViewModel(primaryButtonModel, secondaryButtonModel)
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@ public extension LabelModel {
|
||||
titlePrefix += " "
|
||||
}
|
||||
if !titlePostfix.isEmpty {
|
||||
titlePostfix += " "
|
||||
titlePostfix = " " + titlePostfix
|
||||
}
|
||||
let title = linkAction.optionalStringForKey(KeyTitle) ?? ""
|
||||
let text = "\(titlePrefix)\(title)\(titlePostfix)"
|
||||
@ -25,7 +25,7 @@ public extension LabelModel {
|
||||
self.init(text: text)
|
||||
|
||||
// Add action attribute.
|
||||
if let linkActionModel = linkAction.asActionModel() {
|
||||
if let linkActionModel = try? linkAction.asActionModel() {
|
||||
attributes = [LabelAttributeActionModel(titlePrefix.isEmpty ? 0 : titlePrefix.count, title.count, action: linkActionModel)]
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user