Merge branch 'feature/Decoders+Context' into 'develop'
updated models for use of Decoder Context See merge request BPHV_MIPS/mvm_core_ui!851
This commit is contained in:
commit
a8bced9dbd
@ -198,6 +198,11 @@ open class ButtonModel: ButtonModelProtocol, MoleculeModelProtocol, FormGroupWat
|
|||||||
title = try typeContainer.decode(String.self, forKey: .title)
|
title = try typeContainer.decode(String.self, forKey: .title)
|
||||||
action = try typeContainer.decodeModel(codingKey: .action)
|
action = try typeContainer.decodeModel(codingKey: .action)
|
||||||
|
|
||||||
|
if let style = decoder.context?.value(forKey: CodingKeys.style.stringValue) as? Styler.Button.Style{
|
||||||
|
self.style = style
|
||||||
|
setFacade(by: style)
|
||||||
|
}
|
||||||
|
|
||||||
if let style = try typeContainer.decodeIfPresent(Styler.Button.Style.self, forKey: .style) {
|
if let style = try typeContainer.decodeIfPresent(Styler.Button.Style.self, forKey: .style) {
|
||||||
self.style = style
|
self.style = style
|
||||||
setFacade(by: style)
|
setFacade(by: style)
|
||||||
|
|||||||
@ -50,13 +50,17 @@ public class TwoButtonViewModel: ParentMoleculeModelProtocol {
|
|||||||
required public init(from decoder: Decoder) throws {
|
required public init(from decoder: Decoder) throws {
|
||||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
||||||
primaryButton = try typeContainer.decodeMoleculeIfPresent(codingKey: .primaryButton)
|
|
||||||
if primaryButton?.style == nil {
|
//set context value for 'primary' style to be set for the primaryButton in case the
|
||||||
primaryButton?.style = .primary
|
//property is not returned in the JSON and once decoded, this value is removed from the context
|
||||||
|
try decoder.setContext(value: Styler.Button.Style.primary, for: "style") {
|
||||||
|
self.primaryButton = try typeContainer.decodeMoleculeIfPresent(codingKey: .primaryButton)
|
||||||
}
|
}
|
||||||
secondaryButton = try typeContainer.decodeMoleculeIfPresent(codingKey: .secondaryButton)
|
|
||||||
if secondaryButton?.style == nil {
|
//set context value for 'secondary' style to be set for the primaryButton in case the
|
||||||
secondaryButton?.style = .secondary
|
//property is not returned in the JSON and once decoded, this value is removed from the context
|
||||||
|
try decoder.setContext(value: Styler.Button.Style.secondary, for: "style") {
|
||||||
|
self.secondaryButton = try typeContainer.decodeMoleculeIfPresent(codingKey: .secondaryButton)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -33,11 +33,7 @@ public extension TemplateProtocol {
|
|||||||
guard let pageJSON = json else { return }
|
guard let pageJSON = json else { return }
|
||||||
let delegateObject = (self as? MVMCoreViewControllerProtocol)?.delegateObject?() as? MVMCoreUIDelegateObject
|
let delegateObject = (self as? MVMCoreViewControllerProtocol)?.delegateObject?() as? MVMCoreUIDelegateObject
|
||||||
let data = try JSONSerialization.data(withJSONObject: pageJSON)
|
let data = try JSONSerialization.data(withJSONObject: pageJSON)
|
||||||
let decoder = JSONDecoder()
|
let decoder = JSONDecoder.create(with: delegateObject)
|
||||||
if let delegateObject = delegateObject {
|
|
||||||
// Add the delegate to access mid parsing if applicable.
|
|
||||||
try decoder.add(delegateObject: delegateObject)
|
|
||||||
}
|
|
||||||
templateModel = try decodeTemplate(using: decoder, from: data)
|
templateModel = try decodeTemplate(using: decoder, from: data)
|
||||||
|
|
||||||
// Add additional required behaviors if applicable.
|
// Add additional required behaviors if applicable.
|
||||||
|
|||||||
@ -69,10 +69,7 @@ open class TopNotificationModel: Codable {
|
|||||||
/// Decodes the top alert json to a model.
|
/// Decodes the top alert json to a model.
|
||||||
public static func decode(json: [AnyHashable: Any], delegateObject: MVMCoreUIDelegateObject?) throws -> Self {
|
public static func decode(json: [AnyHashable: Any], delegateObject: MVMCoreUIDelegateObject?) throws -> Self {
|
||||||
let data = try JSONSerialization.data(withJSONObject: json)
|
let data = try JSONSerialization.data(withJSONObject: json)
|
||||||
let decoder = JSONDecoder()
|
let decoder = JSONDecoder.create(with: delegateObject)
|
||||||
if let delegateObject = delegateObject {
|
|
||||||
try decoder.add(delegateObject: delegateObject)
|
|
||||||
}
|
|
||||||
return try decoder.decode(self, from: data)
|
return try decoder.decode(self, from: data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user