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